# Why is my FTP output file blank?

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? –  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,

help
pwd
quit


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.

-

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

-
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
bin
prompt off
cd wbc/webr >>>
ls
END_SCRIPT


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

./dp.sh > ftp.log

-