簡體   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