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"
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值