User Tools

Site Tools


ftp_file_fetch_using_perl

FTP file fetch using perl

| 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";
ftp_file_fetch_using_perl.txt · Last modified: 2009/08/08 22:15 by k2patel