SFTP using Expect

房东的猫 提交于 2019-12-24 07:21:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!