Linux expect問題集:227 Entering Passive Mode (10,41,49,10,218,187). ftp: connect: Connection timed out

問題出現背景:
在內網的Linux機器A中使用expect腳本自動登錄到雲主機B中並下載文件到A中。
問題片斷:

get /chinawiserv/Ftp/crawlerWorker.jar /home/expectDownload/crawlerWorker.jar
local: /home/expectDownload/crawlerWorker.jar remote: /chinawiserv/Ftp/crawlerWorker.jar
227 Entering Passive Mode (10,41,49,10,218,187).
ftp: connect: Connection timed out
ftp> quit
221 Goodbye.

解決方法:
由於兩臺機子處於不同的網絡中,網速較慢,我們需要使用PORT方式傳輸數據(FTP默認爲PASV模式,即被動方式),開啓方式爲:

ftp passive
Passive mode off.
ftp passive (注:再次運行該命令就會打開PASV模式)
Passive mode on.

修改後的腳本片斷爲:

expect "ftp>*"
send "passive\r"
expect "Passive mode off."
send "lcd $dir\r"
expect {
 "*file"  { send_user "local $dir No such file or directory";send "quit\r" }
 "*now*"  { send "get $remotedir/$file $dir/$file\r"}
 }
 expect {
 "*Failed" { send_user "remote $remotefile No such file\r";send "quit\r" }
 "*Transfer complete*"     { send_user "$file has been download\r";send "quit\r"}
 }
send "passive"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章