我已经编写了以下代码来连接到ftp位置并将单个文件下载到本地文件系统。
#!/usr/local/bin/perl -w
use strict;
use Net::FTP;
my $hostname = 'mirror.anl.gov';
my $username = 'anonymous';
my $password = 'username@domain.com';
# Hardcode the directory and filename to get
my $home = '/pub';
my $filename = 'motd';
# Hardcode the local directory
my $localdir = '/home/boy/';
# Open the connection to the host
my $ftp = Net::FTP->new($hostname)
or die "Cannot connect to $hostname: $@"; # Construct object
$ftp->login($username, $password)
or die "Cannot login ", $ftp->message;; # Log in
$ftp->cwd($home)
or die "Cannot change working directory ", $ftp->message;# Change
+directory
my @filelist=$ftp->ls($home);
print map { "$_\n"} @filelist;
# Now get the file and leave
$ftp->get($filename,$localdir.$filename)
or die "Cannot get $filename: $@";
$ftp->quit;
foreach
循环开启
@filelist
如下所示
foreach(@filelist){
print map { "$_\n"} @filelist;
# Now get the file and leave
$ftp->get($filename,$localdir.$filename)
or die "Cannot get $filename: $@";
}
但现在我在最后一个
die
. 因为我必须得到多个文件,所以现在我删除了
$filename
从我的代码,现在
foreach公司
foreach(@filelist){
print map { "$_\n"} @filelist;
# Now get the file and leave
$ftp->get($localdir)
or die "Cannot get $filename: $@";
}
但我又犯了同样的错误。现在我知道了
get
函数用于只下载单个文件和
mget
can not locate object method 'mget' via package NET::FTP
那我们怎么才能完成我的任务呢?