- 论坛徽章:
- 0
|
#!/usr/bin/perl
use Net::FTP;
sub ftpdown {
my $user="root";
my $passwd="ftpdown";
my $dates=`date '+%Y%m%d'`;
my $date=$dates-1;
#exec("mkdir -p /file/$date" ;
my $dirs="/file/$date";
my $haom="192.168";
my $wav=" ->";
my $xxx="xxx";
my $ftp=Net::FTP->new("@_",Port=>21) or die "can't connet @\n";
$ftp->login("$user","$passwd")or die"no login\n";
$ftp->binary;
$ftp->cwd("$dirs")or die "$@\n";
my @filelist=$ftp->dir();
foreach (@filelist){
if ($_ =~ l){
my $start=index($_,$haom);
my $starts=substr($_,$start);
my $ends=index($starts,$wav);
my $localfile=substr($starts,0,$ends);
my $downs=rindex($_,$haom);
my $remotefile=substr($_,$downs);
$ftp->get("$remotefile","$localpath/$localfile");
my $a="list";
print "$a\n";
}
if (!($_ =~ $xxx)){
my $downs=rindex($_,$haom);
my $remotefile=substr($_,$downs);
my $localfile=$remotefile;
$ftp->get("$remotefile","$localpath/$localfile");
}
#print "$_\n",foreach @filelist;
$ftp->quit;
}
}
my @host=("192.168.0.221","192.168.0.224","192.168.0.225","192.168.0.227");
my %pid_to_host;
my $dates=`date '+%Y%m%d'`;
my $date=$dates-1;
if (!(-e "/file/$date")){exec("mkdir -p /file/$date");}
foreach (@host){
if (my $pid=fork){
$pid_to_host{$pid}=$_;
}else{
exit !ftpdown($_);
}
}
while(keys %pid_to_host){
my $pid=wait;
last if $pid <0;
my $host=delete $pid_to_host{$pid},next;
#print "ftp download file is securell\n";
}
|
各位帮忙看下,为什么这段代码不能下载.如果改成列出@filelist的条目都可以显示! |
|