无法调用方法“文件名"没有包或对象引用 [英] Can't call method "filename" without a package or object reference

查看:173
本文介绍了无法调用方法“文件名"没有包或对象引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从ftp服务器(host1)下载一堆包含内容的目录.为此,我使用库 Net :: FTP :: Recursive .当我运行代码时,文件夹和文件已下载.不过,我收到了以下消息:

I want to download from a ftp server (host1) a bunch of directories with content. To do that I use library Net::FTP::Recursive. When I run the code the folders and files were downloaded. Nevertheless, I got this message:

>Can't call method "filename" without a package or object reference 
 at C:\10_LIB~1\PerlLib\lib\perl5/Net/FTP/Recursive.pm line 86.

我想知道为什么会发生这种情况,产生什么影响以及如何避免这种情况.

I wonder why this happens, what impact it has and how I can avoid this.

这是要下载的代码:

# -- 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:

I used perl on Windows 7 with version:

perl -v
This is perl 5, version 28, subversion 0 (v5.28.0) built for MSWin32-x64-multi-thread

这是/Net/FTP/Recursive.pm中的代码,直到消息的第86行:

And here is the code from /Net/FTP/Recursive.pm until line 86 from the message:

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服务器返回的行(作为子程序的参数提供),并为每个远程文件(...除外)返回Net :: FTP :: Recursive :: File对象的列表. ).

yoursub1 is completely wrong. It's suppose to parse the lines returned from the FTP server (provided as arguments to the sub), and return a list of Net::FTP::Recursive::File objects for each remote file (other than . and ..).

如果默认实现(Net::FTP::Recursive::parse_files)足够,只需删除ParseSub => \&yoursub1.否则,您可能应该首先复制Net::FTP::Recursive::parse_files并针对FTP服务器的输出进行调整.

If the default implementation (Net::FTP::Recursive::parse_files) is sufficient, simply remove ParseSub => \&yoursub1. Otherwise, you should probably start by copying Net::FTP::Recursive::parse_files and adjusting it for your FTP server's output.

这篇关于无法调用方法“文件名"没有包或对象引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆