2012-12-06 49 views
14

如果我執行這個地方,一切工作正常:試圖從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' 

可能是什麼問題?

+1

可能應該移動到serverfault .. –

回答

34

我找到了答案,在http://www.ruby-forum.com/topic/161274

超越防火牆,主動FTP不會NAT設備後面的工作。 FTP服務器 有時說非法端口命令,如果你告訴他們,你的 地址就像192.168.x的私有IP地址(你的NAT設備後面的 網絡上的地址)

添加:

ftp.passive = true 

固定它。

+1

+1 ...我在Netbeans遠程編輯器中得到相同的錯誤,通過更改爲被動模式修復。 –

+0

我已經使用這個寶石「paperclip-storage-ftp」,並且在上傳照片時出現類似Net :: FTPPermError 500的錯誤。所以你可以告訴我在哪裏我應該把這一行ftp.passive = true在模型中?你也可以看到這個http://stackoverflow.com/questions/33540851/getting-random-error-while-upload-photo-with-paperclip-on-my-ftp-server –