使用 Bash 的 SFTP 上传
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
while 运行 这个脚本在 bye 语句之后会无限循环。
它一直在终端上打印 'Y' 并且永不结束。
请说明为什么会这样。
如果您使用的是 #!/usr/bin/expect
,那么您没有 bash 脚本:删除行
/usr/bin/expect << EOD
然后听取@whjm 的建议
此外,有条件地期望"continue?"的方法是
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" }
我的服务器没有目标服务器的密钥,所以不是提示输入密码而是提示输入 'Are you sure you want to continue connecting'?在这方面没有任何适当的通过。
我有一个脚本程序,它使用 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
while 运行 这个脚本在 bye 语句之后会无限循环。
它一直在终端上打印 'Y' 并且永不结束。
请说明为什么会这样。
如果您使用的是 #!/usr/bin/expect
,那么您没有 bash 脚本:删除行
/usr/bin/expect << EOD
然后听取@whjm 的建议
此外,有条件地期望"continue?"的方法是
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" }
我的服务器没有目标服务器的密钥,所以不是提示输入密码而是提示输入 'Are you sure you want to continue connecting'?在这方面没有任何适当的通过。