FTP Transfer using Perl
Below is a script I occasionally use to transfer log files from my server to my desktop. This scripts works with Net::FTP and Perl 5.10.0.
#!/usr/bin/perl
use Net::FTP;
# Basic Settings
my $host="ftp.example.com"; # Remote FTP Server
my $directory="/Server/wamp/logs/"; # Navigate to this directory on remote FTP.
my $username="user"; # FTP Username
my $password="pass"; # FTP Password
#Advanced settings.
my $timeout=1000; # FTP Timeout
$ftp=Net::FTP->new($host,Timeout=>$timeout) or $newerr=1;
push @ERRORS, "Can't ftp to $host: $!\n" if $newerr;
myerr() if $newerr;
print "Connected\n";
$ftp->login($username,$password) or $newerr=1;
print "Getting file list";
push @ERRORS, "Can't login to $host: $!\n" if $newerr;
$ftp->quit if $newerr;
myerr() if $newerr;
print "Logged in\n";
$ftp->cwd($directory) or $newerr=1;
push @ERRORS, "Can't cd $!\n" if $newerr;
myerr() if $newerr;
$ftp->quit if $newerr;
$ftp->get("access2.log"); #Rename/duplicate as you need it.
$ftp->quit;
sub myerr {
print "Error: \n";
print @ERRORS;
exit 0;
}
Note: I may have built this script based on some internet examples, so I don’t take *complete* credit for this script.