agent/project/ssh/scp_upload.exp
2025-11-14 16:44:12 +08:00

43 lines
800 B
Plaintext
Executable File

#!/usr/bin/expect -f
set timeout 30
set hostname "59.110.19.30"
set username "root"
set password "@CuiYuJian040618"
set local_file ""
set remote_path "/root/"
if {$argc > 0} {
set local_file [lindex $argv 0]
if {$argc > 1} {
set remote_path [lindex $argv 1]
}
} else {
set local_file "scp_test_file.txt"
}
puts "上传文件: $local_file 到远程路径: $remote_path"
spawn scp -r $local_file $username@$hostname:$remote_path
expect {
"*password:" {
send "$password\r"
}
"*Are you sure you want to continue connecting*\" {
send "yes\r"
expect "*password:"
send "$password\r"
}
}
expect {
"*100%*" {
puts "文件上传成功!"
}
timeout {
puts "上传超时!"
exit 1
}
eof
}