简体   繁体   English

使用 Bash 上传 SFTP

[英]SFTP Upload using Bash

I have a Script program which uses Bash with Expect.我有一个脚本程序,它使用 Bash 和 Expect。 This shell script is doing a SFTP Upload.这个 shell 脚本正在执行 SFTP 上传。

Here is the script.这是脚本。

#!/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 running this script it is going to infinite loop after bye statement.运行此脚本时,它将在 bye 语句后无限循环。

It keeps printing 'Y' on the terminal and never ends.它不断在终端上打印“Y”并且永不结束。

Please suggest why is it happening.请提出为什么会这样。

If you're using #!/usr/bin/expect then you don't have a bash script: remove the line如果您使用#!/usr/bin/expect那么您没有 bash 脚本:删除该行

/usr/bin/expect << EOD

and then take @whjm's advice然后接受@whjm 的建议

Also, the way to conditionally expect "continue?"另外,有条件地期望“继续”的方式? is

expect {
    "*Are you sure you want to continue connecting*"  {
        send "yes\r"
        exp_continue
    }
    "Password:*" {send $pwd\r}
}

I was able to work with this issue.我能够解决这个问题。 I had to uncomment below line from the script.我不得不从脚本中取消注释以下行。

#expect "*Are you sure you want to continue connecting*"  {send "yes\r" }

My server was not having the key of destination server , So instead of prompting for password it was prompting for 'Are you sure you want to continue connecting' ?我的服务器没有目标服务器的密钥,所以不是提示输入密码而是提示“您确定要继续连接吗”? and there was nothing proper being passed in this.并且没有任何适当的通过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM