How do you output batch DOS FTP to a textfile?


I have the following perl script for some testing. Right now what happens is that the program transfers a number of files in a live DOS screen then closes. What i want to be able to do is output the live dos screen to a text file. Everything in the DOS window is fine it doesn't need to be just the filtered results.

Many thanks in advance.


# ftp script for TCP-PEP test bench

$num_args = $#ARGV + 1;

if ($num_args != 5)
   print "Script Usage ...\n";
   print "perl <server ip addr> <userid> <password> <mode> <ftp file name>\n";
   print "<server ip addr> : IP address which ftp will connect to\n";
   print "<userid>         : win-xp, win-2k, win-2003 or MAC \n";
   print "<password        : password \n";
   print "<mode>           : get for ftp-get and put for ftp-put\n";
   print "<ftp file name>  : file name used for ftp\n";
   die "Try again ...\n";

$server = $ARGV[0];
$userid = $ARGV[1];
$password = $ARGV[2];
$mode = $ARGV[3];
$filename = $ARGV[4];

open (cmdfile, ">test.cmd") || die ("Could not open file. $!");

print cmdfile "open $server\n";
print cmdfile "$userid\n";
print cmdfile "$password\n";
print cmdfile "hash\n";
print cmdfile "bin\n";

if ($ARGV[3] eq "put")
    print cmdfile "cd put\n";
    print cmdfile "put $filename $filename.put\n";
    print cmdfile "cd get\n";
    print cmdfile "get $filename $filename.get\n";

print cmdfile "bye\n";

close (cmdfile) || die ("Could not write file. $!");

system 'ftp -s:test.cmd';

Who is Participating?
creates output.log (or deletes existing) and put the output in there
system 'ftp -s:test.cmd > output.log';

or if you want to append to the log:
system 'ftp -s:test.cmd >> output.log';
do not have DOS so can not test this mut I would expect:

system 'ftp -s:test.cmd >capturedOutput';

to do what you want
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.