简体   繁体   中英

SFTP using Expect

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

请注意,您期望密码的大小写为p,但日志显示为大写P

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

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