in reply to Capturing Net::FTP output

Without any code, it's difficult to know what you're trying to do. However, following is a script I wrote to automate the download of all files in a give directory, or simply a given file. It's quick and dirty, and I'm sure could be cleaned considerably, but when I wrote it, I needed it "yesterday".....

#!/usr/bin/perl # # gets $FILE in $DIR from $HOST # # the following command line parameters are accepted: # # -h host IP and port (ex: 192.168.1.1 22) # -u userid (ex: -u anonymous) # -p password (ex: -p your@email.com) # -d directory (ex: -d /pub/data/) # -f file (ex: -f filename.txt) # NOTE: if -f is not passed, then the entire directory is downlo +aded $BadInput = ""; use Getopt::Long; GetOptions("h=s" => \$HOST, "port=s" => \$PORT, "u=s" => \$USERNAME, "p=s" => \$PASSWORD, "d=s" => \$DIR, "f=s" => \$FILE); use File::stat; $fileinfo = stat("$ENV{HOME}.batchftprc"); if (!($HOST)) { print "No host specified\n"; $BadInput = "Y"; } if (!($USERNAME)) { print "No userid specified\n"; $BadInput = "Y"; } if (!($PASSWORD)) { print "No password specified\n"; } if ((!($DIR)) and (!(-s("$ENV{HOME}/.batchftprc")))) { print "No directory specified\n"; $BadInput = "Y"; } if ($BadInput) { print "correct usage is: perl batchftp.pl --h=<HOST> [--port=< +PORT>] --u=<USERID> --p=<PASSWORD> --d=<DIRECTORY> [--f=<FILENAME>]\n +"; print "items enclosed in [] are optional\n"; print "-d is required unless $ENV{HOME}/.batchftprc exists\n"; print "probably want to use & as well\n"; exit; } if ($DIR) { push(@dir, $DIR); } else { open(CONFIG, "$ENV{HOME}/.batchftprc") or die "-d not specifie +d and could not open $ENV{HOME}/.batchftprc: $!"; while (chomp($DIR = <CONFIG>)) { push(@dir, $DIR); } } use Net::FTP; $ftp = Net::FTP->new("$HOST $PORT") or die "can't connect to $HO +ST: $!\n"; $ftp->login($USERNAME, $PASSWORD) or die "can't login: $!\n"; foreach $DIR (@dir) { $ftp->cwd($DIR) or die "can't change to $DIR +: $!\n"; if ($FILE) { $ftp->get($FILE) or die "can't get $FILE: $!\ +n"; } else { @list = $ftp->ls or die "can't get ls: $!\n"; foreach $FILE (@list) { $ftp->get($FILE) or die "in foreach can't get + $FILE: $!\n"; } } } $ftp->quit;

The format of .batchftprc is:

/directory01/whatever /directory02 /directory03/whatever/you/want

Hope this helps.

If things get any worse, I'll have to ask you to stop helping me.