I currently have a perl script that have to retreive a single file from 20+ sites every 10 min. Right now it will ftp to site1 and download and continue up until site20. I am trying to get this to run all the ftp d/l at the same time. This is where I have my problem, I can't get it to work.
Sample of sam_sites.pl file :
AA|123.456.789.100|PASSWORD|Windows
BB|321.654.987.100|PASSWORD|Unix
CC|135.790.864.123|PASSWORD|Unix
Code from ret_sam.pl file :
#!/usr/bin/perl
use Net::FTP;
use Switch;
use threads;
use threads::shared;
$version = "0.00.0001";
$RETSAMC = `ps -ef | grep ret_sam | grep -v grep | wc -l`;
$RETSAMS = "/home/fox/SAM/RET_SAM_RUN";
$HOMEDIR = "/home/fox/SAM/sites/test";
open(SITES_F, "sam_sites.pl") || die ("Missing sam_sites.pl file!");
@site=<SITES_F>;
close(SITES_F);
$NLETNUM = scalar(@site);
foreach $location_n (@site)
{
chomp($location_n);
($s_name,$s_ip,$s_pwd,$s_sys)=split(/\|/,$location_n);
$thr = threads->create(\&ftp_go_and_get, $s_name, $s_ip, $s_pwd, $s_sys);
$thr->join();
}
sub ftp_go_and_get {
if (lc($[3]) eq "windows"){
$f_user = "fox\@openfox";
$directory = "SAM";
} elsif (lc($[3]) eq "unix"){
$f_user = "fox";
$directory = "/home/fox/SAM";
}
$ftp=Net::FTP->new($[1],Timeout=>60) or $newerr=1;
push @ERRORS, "Can't ftp to $_[1]($[0]): $!\n" if $newerr;
myerr() if $newerr;
print "Connected to $_[1]($[0])\n";
$ftp->login("$f_user","$[2]") or $newerr=1;
print "Trying to get in and grab file.\n";
push @ERRORS, "Can't login to $_[1]($[0]): $!\n" if $newerr;
# $ftp->quit if $newerr;
myerr() if $newerr;
print "Logged in\n";
$ftp->cwd("$directory") or $newerr=1;
push @ERRORS, "Can't find a spot to take dump.\n" if $newerr;
myerr() if $newerr;
# $ftp->quit if $newerr;
#$f_size=$ftp->size("@[0]") or $newerr=1;
#print "The size of this file is $f_size\n";
# push @ERRORS, "Can't get size of file.\n" if $newerr;
# myerr() if $newerr;
# $ftp->quit if $newerr;
@files=$ftp->get($[0], "$HOMEDIR/$[0]") or $newerr=1;
push @ERRORS, "Can't get file $[0]\n" if $newerr;
myerr() if $newerr;
print "Got file for $[0]\n";
foreach(@files) {
print "I took a dump in $_\n";
}
$ftp->quit;
}
sub myerr {
print "Error: \n";
print @ERRORS;
exit 0;
}
I am looking for any suggestions or constructive critism that can help me out here. Thanks in advance.