微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby – 尝试从FTP下载文件导致“500非法PORT命令”错误

如果我在本地执行,一切正常:
require 'net/ftp'

ftp=Net::FTP.new("myftpserver.com","username","password")

ftp.getbinaryfile("/myfile.zip","localfile.zip")
ftp.close

如果我尝试在我正在使用的Linux服务器上执行它,结果是:

/usr/local/lib/ruby/1.9.1/net/ftp.rb:273:in `getresp': 500 Illegal
PORT command. (Net::FTPPermError)   from
/usr/local/lib/ruby/1.9.1/net/ftp.rb:281:in `voidresp'  from
/usr/local/lib/ruby/1.9.1/net/ftp.rb:304:in `block in voidcmd'  from
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'   from
/usr/local/lib/ruby/1.9.1/net/ftp.rb:302:in `voidcmd'   from
/usr/local/lib/ruby/1.9.1/net/ftp.rb:317:in `sendport'  from
/usr/local/lib/ruby/1.9.1/net/ftp.rb:325:in `makeport'  from
/usr/local/lib/ruby/1.9.1/net/ftp.rb:358:in `transfercmd'   from
/usr/local/lib/ruby/1.9.1/net/ftp.rb:420:in `block (2 levels) in
retrbinary'   from /usr/local/lib/ruby/1.9.1/net/ftp.rb:166:in
`with_binary'   from /usr/local/lib/ruby/1.9.1/net/ftp.rb:419:in `block
in retrbinary'  from /usr/local/lib/ruby/1.9.1/monitor.rb:201:in
`mon_synchronize'   from /usr/local/lib/ruby/1.9.1/net/ftp.rb:418:in
`retrbinary'  from /usr/local/lib/ruby/1.9.1/net/ftp.rb:539:in
`getbinaryfile'

可能是什么问题呢?

解决方法

我在 http://www.ruby-forum.com/topic/161274发现了答案:

Beyond firewalls,active ftp won’t work behind a NAT device. Ftp
servers sometimes say illegal port command if you tell them that your
address is a private ip address like 192.168.x (your address on the
network behind the nat device)

添加

ftp.passive = true

修复.

原文地址:https://www.jb51.cc/ruby/273930.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐