简体   繁体   中英

SFTP Upload using Bash

I have a Script program which uses Bash with Expect. This shell script is doing a SFTP Upload.

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.

It keeps printing 'Y' on the terminal and never ends.

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 << EOD

and then take @whjm's advice

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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