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).
Igal Serban's answer is correct. Try this,
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:
In your case, the command would be
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!
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 toget 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?
http://support.microsoft.com/kb/96269
probably the ftp server process does not have the right to write to c:. Try c:\somedir\somefile.txt instead
Save this file. for example I have saved it with the name of
dp.sh
. After that run the command: