问题
I have tried the script below to SFTP using bash script. But it does not work. Always error at password.
/usr/local/bin/expect <<EOF
spawn sftp PG1@dev1.dummy.com
expect "Password:"
send "abc123\r"
expect "sftp>"
send "cd /tmp\r"
send "get Data.dat\r"
send "get List.dat\r"
send "bye\r"
EOF
Here's the log file when I run the script above, after taking in all the suggestions from responders.
######### StartJob #########
Sun Apr 19 09:59:08 MYT 2015
spawn sftp PG1@dev1.dummy.com^M
Connecting to dev1.dummy.com...^M
Password: ^M
sftp> ERROR: Data file Data.dat not successfully extracted!
Sun Apr 19 09:59:12 MYT 2015
########## EndJob #########
回答1:
Note that you are expecting password worth lower case p,but the log shows a capital P
回答2:
Thank you for your attempts to solve the problem above. I found the solution. Here's what I did:
/usr/local/bin/expect <<EOF
spawn sftp PG1@dev1.dummy.com
expect "Password:"
send "abc123\r"
expect "sftp>"
send "cd /tmp\r"
expect "sftp>"
send "get Data.dat\r"
expect "sftp>"
send "get List.dat\r"
expect "sftp>"
send "bye\r"
EOF
来源:https://stackoverflow.com/questions/29724845/sftp-using-expect