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

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).

  • That's my initial thought, too. Interesting that ftp.exe still creates the file, though, isn't it? 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? 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).


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.


The simplest way is open Computer folder where you see all your drives. Here you need to create a shortcut for ftp server. To do this, on empty space in computer folder right click and click on 'Add a network location' click on it and follow the prompt to create shortcut for your network ftp server. If you have password for it or is anonymous do that. You can give it a name too. It will appear in Network location on Computer folder. Now double click it. To open>see, read or play and edit a folder or its file you need to drag>copy or move it to desktop. You can move it back when you are done. It is little bit cumbersome but is working for me. Hope it helps you guys!

  • Using paragraphs or bullets will improve the readability of your answer. Feb 4 '16 at 11:38

Addendum to Martin Bøgelund's answer:

The why-question (which I assume is "why did the original attempt do what it did") is interesting, and simple when you think about it the right way: it's the same dir [remote-directory] [local-file] syntax, where the remote directory happens to be >. The ftp client is not a shell. Commands typed into it are not shell commands. It doesn't have redirection operators, and > is not a special character.

Yes, you can have a directory named > on your FTP server, as long as you aren't running it on Windows.

The ftp.exe found in Windows is a copy of an early BSD ftp. It doesn't know about Windows filename restrictions. If you tell it to get remotefile > it will try to save a copy of the remote file as a local file called >, and fail because of the local filesystem limitations.

A major contributor to the confusion here is that the FTP server, receiving a LIST command with > as the argument, responded with a success code and an empty reply body instead of saying "No such file".


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



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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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