Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LFTP active mode with servers that do not recognize the PORT command

I am using LFTP to transfer files from a server, which unfortunately does not recognize the PORT command. I do not have control over the server (do not know in detail what server is) and I have to use the active mode.

This is the command line as:

lftp -e 'debug 10;set ftp:passive-mode off; set ftp:auto-passive-mode no; ls; bye;' -u user,password ftp://ftp.site.com

This is the debug output:

<--- 200 Using default language en_US
---> OPTS UTF8 ON
<--- 200 UTF8 set to on           
---> OPTS MLST modify;perm;size;type;UNIX.group;UNIX.mode;UNIX.owner;
<--- 200 OPTS MLST modify;perm;size;type;UNIX.group;UNIX.mode;UNIX.owner;
---> USER xxxxx
<--- 331 Password required for xxxxx
---> PASS xxxxxx
<--- 230 User xxxxx logged in     
---> PBSZ 0
<--- 200 PBSZ 0 successful               
---> PROT P
<--- 200 Protection set to Private       
---> PORT 172,16,133,11,146,168
<--- 500 Illegal PORT command                    
---> LIST
---> ABOR
---- Closing aborted data socket
---- Chiusura del socket di controllo

It seems that LFTP renounces to connect to data socket because the remote server does not support the PORT command. Is there a way to convince LFTP can still connect to port 20? By FTP manual obviously no problem.

like image 233
Marco Avatar asked Feb 22 '13 11:02

Marco


People also ask

How use lftp command line?

You can launch lftp by typing just lftp and then using an open command to take you to your target site or you can provide the target's name on the same line as lftp like I did. If you want to download an entire directory, you can use the mirror command.

What is lftp command?

lftp is a file transfer program that allows sophisticated ftp, http and other connections to other hosts. If site is specified then lftp will connect to that site otherwise a connection has to be established with the open command.

How do I connect to lftp server?

Connecting to a remote server When using lftp there are basically two ways we can connect to a remote host. The first is by invoking the application from our shell and provide the URL of the remote host, the second is to use the open command, when already in the lftp prompt.


1 Answers

The issue, I think, is not that the FTP server doesn't support the PORT command (it does), but rather, it doesn't like the IP address/port that your FTP client is sending in the PORT command.

PORT 172,16,133,11,146,168

...tells the server to connect to address 172.16.133.11, port 37544*. The interesting part here is the IP address: it's an RFC 1918 address (i.e. it's a private network address). That, in turn, suggests that your FTP client is in a LAN somewhere, and is connecting to an FTP server using a public IP address.

That remote FTP server cannot connect to a private network address; by definition, RFC 1918 address are not publicly routable.

Thus it very well could be that the FTP server is trying to make a connection to the address/port given in your PORT command, fails, thus that is why the FTP server fails the command, saying:

500 Illegal PORT command

To make a PORT command work with that FTP server, you would need to discover the public IP address that that server can connect to, to reach your client machine. Let's say that this address is 1.2.3.4. Then you would need to tell lftp to use that address in its PORT command, using the ftp:port-ipv4 option.

Chances are, though, that public IP address is the address of a NAT/router/firewall, and that that NAT/router/firewall will not allow connections, from the outside world to a high numbered port (e.g. 37544), to be routed to a machine within the LAN. This is one of the issues with active FTP data transfers, i.e. FTP data transfers which use the PORT (or EPRT) commands: they are not considered "firewall-friendly".

Hope this helps!


* - why 146,168 translates to port 37544?

According to FTP's RFC959 those parameters are:

(...) 16-bit TCP port address. This address information is broken into 8-bit fields and the value of each field is transmitted as a decimal number (in character string representation).

146 dec = 10010010 bin = A
168 dec = 10101000 bin = B

    A        B
10010010 10101000 bin = 37544 dec
like image 195
Castaglia Avatar answered Sep 22 '22 12:09

Castaglia