Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to download file from FTP results in an "500 Illegal PORT command" error

Tags:

ruby

download

ftp

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:

/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?

like image 459
Pavel K. Avatar asked Dec 06 '12 21:12

Pavel K.


People also ask

Why am I getting 500 illegal port in FTP_get?

The connection is set to be in passive mode. Show activity on this post. If you get "500 Illegal PORT command.", you are using the active mode, not the passive mode. Double check that and make sure to really use the passive mode. ftp_get: Illegal PORT command.

What is ftplib error_Perm 500?

ftplib.error_perm: 500 Illegal PORT command. ftplib.error_perm: 550 Illegal PORT command. Probably the file is no longer avaible on the FTP server? Since that from my local machine works well I was thinking that it could be a problem with docker. This is the code which triggers the copy: And this is the move_file function:

How do I fix FTP port 21 not working?

Click "Control Panel". Click on "Network and Internet". Click on "Windows Firewall". Click on "Change Setting". Under that tab, put a check mark next to the FTP port 21. This should allow connections to FTP sites. Click "OK" on the Firewall settings and close the other windows. Restart your computer and try to connect to the FTP site again.

Why can’t I download from FTP?

Re-try the FTP link. If this does not work, you maybe completely firewalled/prevented from accessing FTP sites. In this case an alternative download method will be needed i.e. HTTP/web link.


1 Answers

I found the answer at 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)

Adding:

ftp.passive = true

fixed it.

like image 169
Pavel K. Avatar answered Sep 27 '22 21:09

Pavel K.