• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 471
  • Last Modified:

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 testftp.pl <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';

2 Solutions
do not have DOS so can not test this mut I would expect:

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

to do what you want
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';

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now