[英]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. 我试图自动将一些文件从我的Linux服务器上传到支持FTP的Windows服务器。 I am successfully doing so manually using SFTP and then issuing the put command.
我使用SFTP手动成功,然后发出put命令。 However, when called from cron, my script keeps stopping for a password.
但是,从cron调用时,我的脚本会一直停止输入密码。
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? 为什么不
send "world"
完成密码对话框?
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 示例: http : //www.techtrunch.com/scripting/lazy-admins-part-2
发生的事情是Expect仍在等待模式到达(直到超时),可能是“密码”不在sftp的提示中,并且它可能是“密码”或其他东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.