没有包或对象引用无法调用方法 "filename"
Can't call method "filename" without a package or object reference
我想从 ftp 服务器 (host1) 下载一堆包含内容的目录。为此,我使用库 Net::FTP::Recursive。当我 运行 代码下载文件夹和文件时。尽管如此,我还是收到了这条消息:
>Can't call method "filename" without a package or object reference
at C:_LIB~1\PerlLib\lib\perl5/Net/FTP/Recursive.pm line 86.
我想知道为什么会发生这种情况,它有什么影响以及如何避免这种情况。
下载代码如下:
# -- Libraries
# coding and diagnostic
use strict;
use warnings;
# FTP connection
use Net::FTP;
use Net::FTP::Recursive;
# -- Settings
my $host1 = "ftp.host1.com";
my $user1 = "myname\@myweb.com";
my $password1 = "password";
# -- Connection to ftp server
my $f1 = Net::FTP::Recursive->new($host1) or die "Can't open $f1 $host1\n";
$f1->login($user1, $password1) or die "Can't log $f1 $user1 in\n";
$f1->cwd() or die "Can't cwd to host folder\n";
# $f1->ascii();
$f1->binary;
# -- Directory to download the contents
my $download = "C:/mydirectory/download";
chdir($download);
# -- Host1
$f1->cwd();
$f1->rget( ParseSub => \&yoursub1 );
$f1->quit;
sub yoursub1 {
$f1->rget;
}
我在 Windows 7 上使用 perl,版本为:
perl -v
This is perl 5, version 28, subversion 0 (v5.28.0) built for MSWin32-x64-multi-thread
这是消息中从 /Net/FTP/Recursive.pm 到第 86 行的代码:
sub _rget {
my($ftp) = shift;
my @dirs;
my @ls = $ftp->dir();
my @files = $options{ParseSub}->( @ls );
@files = grep { $_->filename =~ $options{MatchAll} } @files
if $options{MatchAll};
@files = grep { $_->filename !~ $options{OmitAll} } @files
if $options{OmitAll};
print STDERR join("\n", @ls), "\n"
if $ftp->debug;
my $remote_pwd = $ftp->pwd;
my $local_pwd = Cwd::cwd();
FILE:
foreach my $file (@files){
#used to make sure that if we're deleting the files, we
#successfully retrieved the file
my $get_success = 1;
my $filename = $file->filename(); # <- 86
yoursub1
是完全错误的。它假设解析来自 FTP 服务器的 return 行(作为参数提供给 sub),以及 return 每个远程文件的 Net::FTP::Recursive::File 对象列表(其他比 .
和 ..
).
如果默认实现 (Net::FTP::Recursive::parse_files
) 足够,只需删除 ParseSub => \&yoursub1
。否则,您可能应该从复制 Net::FTP::Recursive::parse_files
开始并针对您的 FTP 服务器的输出进行调整。
我想从 ftp 服务器 (host1) 下载一堆包含内容的目录。为此,我使用库 Net::FTP::Recursive。当我 运行 代码下载文件夹和文件时。尽管如此,我还是收到了这条消息:
>Can't call method "filename" without a package or object reference
at C:_LIB~1\PerlLib\lib\perl5/Net/FTP/Recursive.pm line 86.
我想知道为什么会发生这种情况,它有什么影响以及如何避免这种情况。
下载代码如下:
# -- Libraries
# coding and diagnostic
use strict;
use warnings;
# FTP connection
use Net::FTP;
use Net::FTP::Recursive;
# -- Settings
my $host1 = "ftp.host1.com";
my $user1 = "myname\@myweb.com";
my $password1 = "password";
# -- Connection to ftp server
my $f1 = Net::FTP::Recursive->new($host1) or die "Can't open $f1 $host1\n";
$f1->login($user1, $password1) or die "Can't log $f1 $user1 in\n";
$f1->cwd() or die "Can't cwd to host folder\n";
# $f1->ascii();
$f1->binary;
# -- Directory to download the contents
my $download = "C:/mydirectory/download";
chdir($download);
# -- Host1
$f1->cwd();
$f1->rget( ParseSub => \&yoursub1 );
$f1->quit;
sub yoursub1 {
$f1->rget;
}
我在 Windows 7 上使用 perl,版本为:
perl -v
This is perl 5, version 28, subversion 0 (v5.28.0) built for MSWin32-x64-multi-thread
这是消息中从 /Net/FTP/Recursive.pm 到第 86 行的代码:
sub _rget {
my($ftp) = shift;
my @dirs;
my @ls = $ftp->dir();
my @files = $options{ParseSub}->( @ls );
@files = grep { $_->filename =~ $options{MatchAll} } @files
if $options{MatchAll};
@files = grep { $_->filename !~ $options{OmitAll} } @files
if $options{OmitAll};
print STDERR join("\n", @ls), "\n"
if $ftp->debug;
my $remote_pwd = $ftp->pwd;
my $local_pwd = Cwd::cwd();
FILE:
foreach my $file (@files){
#used to make sure that if we're deleting the files, we
#successfully retrieved the file
my $get_success = 1;
my $filename = $file->filename(); # <- 86
yoursub1
是完全错误的。它假设解析来自 FTP 服务器的 return 行(作为参数提供给 sub),以及 return 每个远程文件的 Net::FTP::Recursive::File 对象列表(其他比 .
和 ..
).
如果默认实现 (Net::FTP::Recursive::parse_files
) 足够,只需删除 ParseSub => \&yoursub1
。否则,您可能应该从复制 Net::FTP::Recursive::parse_files
开始并针对您的 FTP 服务器的输出进行调整。