Main Page: Difference between revisions
mNo edit summary |
mNo edit summary |
||
| Line 33: | Line 33: | ||
use Net::FTP; | use Net::FTP; | ||
use Socket; | use Socket; | ||
sub ftp_folder { | |||
my $dir = shift; | |||
my $ftpdir = shift; | |||
my $c = "ls -1 '$dir'"; | |||
my @ls = `$c`; | |||
chomp @ls; | |||
my $i; | |||
if ($debug) { | |||
foreach $i (@ls) { | |||
print "$i\n"; | |||
} | |||
} | |||
my $err = 0; | |||
$i = 0; | |||
my $ftp; | |||
$ftp = Net::FTP->new($ftpHost, Debug => 0) | |||
or die "Cannot connect to $ftpHost: $@"; | |||
$ftp->login($ftpUser, $ftpPass) | |||
or die "Cannot login ", $ftp->message; | |||
$ftp->cwd($ftpdir) | |||
or die "Cannot change working directory ", $ftp->message; | |||
$ftp->binary(); | |||
foreach my $f (@ls) { | |||
print "Copying $f to $ftpHost$ftpdir\n"; | |||
$ftp->put("$dir/$f") or $err = 1; | |||
if (!$err) { | |||
unlink "$dir/$f"; | |||
$i++; | |||
} | |||
} | |||
$ftp->quit; | |||
sleep 2; | |||
return $i; | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||