繁体   English   中英

发送密码后为什么使用Expect自动保存SFTP?

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

我试图自动将一些文件从我的Linux服务器上传到支持FTP的Windows服务器。 我使用SFTP手动成功,然后发出put命令。 但是,从cron调用时,我的脚本会一直停止输入密码。

以下是我尝试使用的代码:

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

就目前而言,它每次都会停止请求密码。 为什么不send "world"完成密码对话框?

更新:

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

现在我收到以下错误:

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

试试这样:

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

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

运行时需要使用参数。 阅读这篇文章。 它解释了如何正确地做到这一点。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM