Skip to content

FTP file fetch using perl

File: fetch.pl

#!/usr/bin/perl                                      
# this script is written by ketan patel

use Net::FTP;

$file = "name of file";

@paths = ('comma_separated path file');

$remotehost = "<remote_hostname>";
$user = "<ftp_username>";
$pass = "<ftp_password>";

chdir "/srv/www/htdocs/passwd";

$k2=1;
print "Connecting...\n";
$ftp = Net::FTP->new("$remotehost", Debug => 0) or
      die "cannot connect:";

print "Logging in...\n";
$ftp->login("$user","$pass")
      or die "cannot login: ",$ftp->message;

print "Beginning Transfer...\n";

foreach $paths (@paths)
{
 print "$paths/$file..\n";
 $ftp -> cwd($paths);
 print "xfering $file..\n";
 $ftp->get($file,"$file$k2");
 $ftp->message;
 $k2++;
}

print "Done.\n";