Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

by ergowolf (Monk)
on May 05, 2000 at 16:24 UTC ( [id://10350] : sourcecode . print w/replies, xml ) Need Help??
Category: FTP
Author/Contact Info ergowolf
Description: This script gets multiple files from multiple file servers. It requires some minor tweaks to change the script. For example, you could change get to put or the user name from Randal to vroom. It will take aas many servers and files as you would like.
use Net::FTP; 

my $ftp;
my $filename;
my @files = ('file1','file2');
my %servers = (
        'box1' => 'password',
        'box2' => 'password',

chdir "path/where/you/want/the/files";

foreach (keys %servers) {
# line 16
    $ftp = Net::FTP -> new($_);
    print $ftp -> message(), "\n";
    $ftp -> login('Randal', $servers{$_});
    print $ftp -> message(), "\n";
    $ftp -> binary();
    print $ftp -> message(), "\n";
    $ftp -> cwd('/your/path');
    print $ftp -> message(), "\n";
    foreach $filename (@files) {
        $ftp -> get( "$filename", "$_$filename");
        print $ftp -> message(), "\n";
print "Completed $_\n\n";
$ftp -> quit();

Replies are listed 'Best First'.
by Anonymous Monk on Jun 09, 2000 at 00:36 UTC
    One of the shortcomings of the Net:FTP module is the lack of the 'multi' commands (mget, mput) A quick addition to code can populate the @files array even given a mask. @files = $ftp -> ls("*.tar.gz"); Gets all of the archives from the server.
by cybear (Monk) on May 24, 2002 at 18:54 UTC
    ergowolf, What is it that you are doing with the message() statements?
    Are you assigning somthing to it, or calling something from it?

    On another note...
    I have a script that FTP's a file to a VAN (Value-added Network).
    Once the file transfer is complete an ILOG number is returned
    from the VAN. This number 99.99999999% certifies that the file
    was received correctly.

    Currently, in order to capture that number, I need to turn
    the debug on Net::FTP to 1 and redirect STDERR to a file.
     my $ftpSession = Net::FTP-> new("$host", Debug => 1); open (STDERR, ">>/detaillogfile.log");

    Can you think of a better way?

      $ftp->message() is mentioned in the documentation - it returns the last line that was received from the server, so it would fit your purpose very nicely, read up the Net::FTP POD :)
        $ftp->message() grabs the last line STDOUT, but not the previous lines, nor STDERR... I'm trying to do the same thing...debug a troublesome FTP connection, and I'd like everything Debug -> 1 can give me. any way to redirect STDOUT and STDERR to a hash? (or a pair of them?)