简体   繁体   中英

Why does automating SFTP with Expect hang after sending the password?

I am attempting to automate uploading some files from my Linux server to an FTP-enabled Windows server. I am successfully doing so manually using SFTP and then issuing the put command. However, when called from cron, my script keeps stopping for a password.

Below is the code I am attempting to use:

#!/usr/bin/expect
#!/bin/sh
clear
spawn sftp remoteuser@43.123.0.10
expect "password"
send "world"
expect eof

As it stands, it stops each time to request a password. Why doesn't send "world" complete the password dialog?

UPDATE:

#!/usr/bin/expect
#!/bin/sh
clear
spawn sftp remoteuser@43.123.0.10
expect "remoteuser@43.123.0.10's password:"
send "world"
expect eof

Now I get the following error:

xml_reports.sh: line 5: spawn: command not found
couldn't read file "remoteuser@43.123.0.10's password:": no such file or directory
xml_reports.sh: line 7: send: command not found
couldn't read file "eof": no such file or directory

Try like this:

#!/bin/bash
expect -c "
spawn sftp remoteuser@XX.XX.XX.XX
expect \"password\"
send \"PASSWORD\r\"
interact "

Example : http://www.techtrunch.com/scripting/lazy-admins-part-2

You need to use arguments when you run it. Read this article. It explains how to do this properly.

发生的事情是Expect仍在等待模式到达(直到超时),可能是“密码”不在sftp的提示中,并且它可能是“密码”或其他东西。

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