Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was practicing ftp but faced an issue: ls command isn't working on ftp> . Why? I checked on 2 remote servers but ls didn't work on either and gave different output when ls was executed. Please see below for the 2 remote boxes.

The below shows my remote server where I installed vsftpd today.

ravbholua@ravbholua-Aspire-5315:~$ ftp rs
Connected to ravi.com.
220 (vsFTPd 3.0.2)
Name (rs:ravbholua): 
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/ravbholua"
ftp> ls
500 Illegal PORT command.
ftp: bind: Address already in use
ftp> 

The below is for a different remote machine where I have to send some files. But as ls on ftp> isn't working, how will I transfer files from my local box to that box because I can't be confirmed without ls whether the files have been transferred or not.

ravbholua@ravbholua-Aspire-5315:~$ ftp 125.21.153.140
Connected to 125.21.153.140.
220---------- Welcome to Pure-FTPd [TLS] ----------
220-You are user number 1 of 10 allowed.
220-Local time is now 04:34. Server port: 21.
220-This server supports FXP transfers
220 You will be disconnected after 2 minutes of inactivity.
Name (125.21.153.140:ravbholua): peacenews
331 User peacenews OK. Password required
Password:
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200-FXP transfer: from 123.63.112.168 to 10.215.10.80
200 PORT command successful

Please note that for the above machine, once I ran ls on ftp>, the prompt didn't come back.

On both the remote machines, I got different output when executed ls on ftp>

share|improve this question
3  
use passive mode. Check the man page of your ftp client for how to enable it. –  Stéphane Chazelas Oct 4 '13 at 12:58
    
How to know what ftp client is running at my end? –  Ravi Oct 5 '13 at 6:37
    
@stephane thanks! I ran man ftp and found the -p option to be used for passive mode. As man ftp mentions that ftp is a user interfacei to the Internet standard file transfer protocol: so it's interface and not the ftp client!!! What I understand is the ftp client uses this interface (ftp) for transferring files. –  Ravi Oct 5 '13 at 7:01

1 Answer 1

up vote 6 down vote accepted

FTP is an ancient protocol. It relies on two TCP connections: a control connection over which commands are exchanged, and data connections for the content of files and also for the output of commands such as ls. What's happening here is that the control connection is established, but the data connections aren't going through.

By default (active mode), data connections are established from the sender to the receiver. For the output of ls, the data is sent by the server, so the server attempts to open a connection to the client. This worked well when FTP was invented, but nowadays, clients are often behind a firewall or NAT which may or may not support active FTP. Switch to passive mode, where the client always initiates the data connection.

Check the manual of your ftp command to see how to switch to passive mode by default. For a one-time thing, typing the command passive usually does the trick.

You may wish to switch to a nicer FTP client such as ncftp or lftp.

share|improve this answer
    
Thanks!! But why all of a sudden this issue occured. Eariler I was able to run ls on ftp>. But yesterday, I installed vsftpd on my remote server (my VPS) and also edited file .netrc on my local box (simply had put hash at the beginning of the line in .netrc). That's all and then after the issue of ls I have been facing. What may be the reason that ls was working fine earlier and since yesterday not working? –  Ravi Oct 5 '13 at 6:35
    
You are right to suggest lftp. I am having experience working with that. lftp is really amazing. Also I would like to add that I have just now checked with lftp and it is perfectly running fine having no issue of ls. ls here (in lftp)is displaying the output properly. –  Ravi Oct 5 '13 at 6:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.