use strict;
use warnings;
use Net::FTP;
my $ftp = Net::FTP->new("ftp.suse.com", Debug => 0, Timeout => 3) or die "Cannot connect to ftp.suse.com: $@";
if ( $ftp->login('anonymous','')){
my @dirs = $ftp->dir();
foreach my $dir (@dirs){
my ($permission,$number1,$user,$group,$number2,$months,$day,$year,$name_path) = split(/\s+/,$dir);
print "Name path:\t$name_path\n";
my @sub_dir = $ftp->ls("$name_path/*.txt");
print "Name file *.txt:\t$sub_dir[0]\n";
my $file_txt = $ftp->get($sub_dir[0]);
print "Name file GET $file_txt:\t$sub_dir[0]\n";
print "Copy $file_txt to LocalHost\n";
`cp $file_txt ftp.txt`;
$ftp->quit();
}
}
-----------------------------------------------------------------------------------------------
Result
perl ftp.pl Name path: pub
Name file *.txt: pub/README.txt
Name file GET README.txt: pub/README.txt
Copy README.txt to LocalHost
less ftp.txt
0 comentários:
Post a Comment