ruby 尝试从 FTP 下载文件导致“500 Illegal PORT command”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13752580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trying to download file from FTP results in an "500 Illegal PORT command" error
提问by Pavel K.
If I execute this locally, everything works fine:
如果我在本地执行此操作,则一切正常:
require 'net/ftp'
ftp=Net::FTP.new("myftpserver.com", "username", "password")
ftp.getbinaryfile("/myfile.zip","localfile.zip")
ftp.close
If I attempt to execute it on the Linux server I am using, the result is:
如果我尝试在我使用的 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'
What could be the problem?
可能是什么问题呢?
回答by Pavel K.
I found the answer at http://www.ruby-forum.com/topic/161274:
我在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 将无法在 NAT 设备后面工作。如果您告诉 Ftp 服务器您的地址是私有 IP 地址,例如 192.168.x(您在 nat 设备后面的网络上的地址),则有时会说非法端口命令
Adding:
添加:
ftp.passive = true
fixed it.
修复。

