[英]SFTP Upload using Bash
我有一个脚本程序,它使用 Bash 和 Expect。 这个 shell 脚本正在执行 SFTP 上传。
这是脚本。
#!/usr/bin/expect -f
/usr/bin/expect << EOD
spawn sftp $loginid@server
#expect "*Are you sure you want to continue connecting*" {send "yes\r" }
expect "Password:*"
send $pwd\r
expect "sftp> "
send "lcd $locdirectory\r"
expect "sftp> "
send "cd $remDirect\r"
expect "sftp> "
send "put $file\r"
expect "sftp> "
send "bye\r"
expect EOD
运行此脚本时,它将在 bye 语句后无限循环。
它不断在终端上打印“Y”并且永不结束。
请提出为什么会这样。
如果您使用#!/usr/bin/expect
那么您没有 bash 脚本:删除该行
/usr/bin/expect << EOD
然后接受@whjm 的建议
另外,有条件地期望“继续”的方式? 是
expect {
"*Are you sure you want to continue connecting*" {
send "yes\r"
exp_continue
}
"Password:*" {send $pwd\r}
}
我能够解决这个问题。 我不得不从脚本中取消注释以下行。
#expect "*Are you sure you want to continue connecting*" {send "yes\r" }
我的服务器没有目标服务器的密钥,所以不是提示输入密码而是提示“您确定要继续连接吗”? 并且没有任何适当的通过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.