Take the 2-minute tour ×

From the Windows command prompt, I have FTPd to a Windows web server. I can get a file, and I can see a directory listing with dir, but I want to save that list locally.

I tried dir > c:\somefile.txt, and the file is created, but it's blank. Same thing if I do ls > c:\somefile.txt.

The result is the same when I FTP from a Linux box.

FTP sends back the following:

200 PORT command successful
150 Opening ASCII mode data connection for /bin/ls
226 Transfer complete
share|improve this question

6 Answers 6

This is probably because FTP.exe take control over the shell. So redirections, that are handled by the cmd.exe have no effect.

What you can do, is use the -s:filename option and redirect the whole ftp output to a file. It will contain more then you want, but you can take care of that later.

Or, maybe, look for other ftp clients that have this functionality ( I am not aware of any).

share|improve this answer
That's my initial thought, too. Interesting that ftp.exe still creates the file, though, isn't it? –  Matt Simmons Jun 17 '09 at 21:17
I tried dir -s:somefile.txt but nothing was created in my local working directory and the output still went to the screen. Did I miss something? –  Nathan Long Jun 18 '09 at 14:56
I guess that not ftp.exe created the file, but that the shell got an empty return form ftp.exe, then created the file and filled it with... nothing. –  dertoni Jul 16 '09 at 7:34

Igal Serban's answer is correct. Try this,

ftp -s:ftp.txt > ftp.log 2>&1

where ftp.txt is a script, just a list of commands, for example,


ftp.log will capture the output. Adding the 2>&1 means you capture both standard out (normal output) and standard error (any error messages from ftp.exe).

share|improve this answer

You can put the dir listing into a local file by doing:

dir [remote-directory] [local-file]

In your case, the command would be

dir . c:\somefile.txt

It doesn't answer the why-question, but accomplishes what you're trying to do.

share|improve this answer

This doesn't really answer the question, but have you considered writing a script to do it, then redirecting the output of a script?


share|improve this answer

probably the ftp server process does not have the right to write to c:. Try c:\somedir\somefile.txt instead

share|improve this answer
How do you explain that the file was created without write permissions? –  nray Jul 16 '09 at 6:22
#!/bin/bash -vx
ftp -in bahugunazxc.com>>END_SCRIPT
quote USER bipin
quote PASS acs123
prompt off
cd wbc/webr >>>

Save this file. for example I have saved it with the name of dp.sh. After that run the command:

./dp.sh > ftp.log
share|improve this answer

Your Answer


