Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to retrieve a list of files from a remote FTP server using the ls command. When just executing ls by itself in the command line, it lists the files. When adding a filename to the command, it returns an empty file.

My code works perfectly on several other ftp servers (likely different server config). Not sure what is going wrong.

ftp> Packet tracing On .
ftp> trace on
Connected to ************.
OPEN ************
220 ************ FTP server ready.
User (*****************): 
331 Password required for ********.
230 User ********* logged in.  Access restrictions apply.
ftp> CD incoming
250 CWD command successful.
ftp> Local directory now C:\csrkb\etl\files\incoming\TASK0460\txt\FTP_OBJ_LIST.
ftp> LCD C:\csrkb\etl\files\incoming\TASK0460\txt\FTP_OBJ_LIST
ftp> ls - FTP_OBJECT_LIST.TXT
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
226 Transfer complete.
ftp> BYE
221-You have transferred 0 bytes in 0 files.
221-Total traffic for this session was 12603 bytes in 2 transfers.
221-Thank you for using the FTP service on ftp-out.
221 Goodbye.
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Why are you using the dash after ls? The remote server is returning an empty list. I would search in the FTP server logs. Make also a network capture with Wireshark. If you have a L7 firewall you should do a capture on the server and compare the two captures.

share|improve this answer
    
Thanks for posting a response. No specific reason for using the dash... it is just how we did it for the other FTP servers we pull data from. For those, it works fine. I have put in a request to the remote servers administrators to check the logs for me. (it is a shipping carrier's FTP server from which we pull event scan data files) –  Gary Jun 1 '11 at 13:42
    
Can you please try without the dash? Like ls FTP_OBJECT_LIST.TXT. Also make sure you are using the same case as displayed by ls of the folder. I mean FTP_OBJECT_LIST.TXT is not the same as Ftp_oBject_lisT.txt –  Mircea Vutcovici Jun 1 '11 at 13:53
    
Run the debug command in ftp before to ls command. –  Mircea Vutcovici Jun 1 '11 at 13:55
    
I did try it before responding, and it failed altogether... with the remote server saying it could not find the file: ls FTP_OBJECT_LIST.TXT 200 PORT command successful. 550 FTP_OBJECT_LIST.TXT: No such file or directory. ftp> BYE 221-You have transferred 0 bytes in 0 files. 221-Total traffic for this session was 366 bytes in 0 transfers. 221-Thank you for using the FTP service on ftp-out. 221 Goodbye. –  Gary Jun 1 '11 at 14:02
    
No such file or directory. - Make sure that you are using the right letter case (lower vs upper/capital). If you are using Linux, try with lftp and use TAB key to do completion. –  Mircea Vutcovici Jun 1 '11 at 14:33
show 1 more comment

The ls and dir commands in ftp are intended to take a remote directory as a first parameter, not a filename - doing so with a filename may or may not work, depending on the ftp server. The syntax is:

ls [remote-dir] [local-file]
  • If no parameters are passed, the current directory is listed.
  • If one parameter is passed, it is assumed to be a directory and is listed
  • If the 2nd parameter is passed, it is a local file and the output is sent to this.
  • If the 2nd parameter is omitted or is a hyphen, then the output is sent to the terminal

Having a hyphen immediately after the 'ls' portion with something else following is not a valid command, so who knows what it will do. As is specifying a filename as the first parameter. It should only be a remote directory name.

share|improve this answer
    
what should be listed for the [remote-dir] if the current remote directory is the same? do I still have to specify the remote directory from the root? –  Gary Jun 1 '11 at 14:51
    
@Gary - if you don't specify anything, the current directory is listed. If you specify a directory, that directory (relative to current directory) should be listed. My point is that specifying a filename will give undefined results, as it's not part of the command syntax. –  barryj Jun 1 '11 at 15:00
    
right, got it. I will do some tests and post back here with the results' –  Gary Jun 1 '11 at 15:03
    
I removed the dash and swapped with a '.' period. this pushed the filename (the target file to write the list to) to the appropriate parameter. –  Gary Jun 1 '11 at 15:40
add comment

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.