今天用perl写了一个ftp下载上传的工具,执行一切正常,但在下载(get)时,对于下载当前没有的文档,会在下载处停留很久,然后报错

Can't use an undefined value as a symbol reference at /usr/lib/perl5/5.8.8/Net/FTP/dataconn.pm

。不晓得为什么or die没有起作用,然后谷歌下发现以下这篇帖子。http://community.activestate.com/forum-topic/undefined-value-symbol-reference-net-ftp-dataconn-pm-line-55


这个哥们儿是在xp环境下的activeperl出现的错误和我的很类似,版本也是v5.8.8,根据下面的回帖,试了一下把ftp环境设为非被动模式,居然成功了,仅此马克一下,若有大神请回复。下面粘贴脚本的下载子函数,初学,写的含糟糕,同求指点。

sub download{
        my $ftp = Net::FTP->new("$_[0]",Timeout => 5,Passive => 0) or die "Can't connect to the Ftp :$@\n";
        $ftp->login("$config{ftp_user}","$config{ftp_pass}") or die "Can't login . ",$ftp->message;
        $ftp->binary or die "Cannot change binary mode ", $ftp->message;
        printcolor bold,"\nInput the subdir:\n";
        printcolor blue,"$config{ftp_host}:$config{ftp_root_dir}/";
        chomp($ftp_sub_dir=<STDIN>);
        $ftp->cwd("$config{ftp_root_dir}/$ftp_sub_dir") or die "Change File:",$ftp->message;
        printcolor green,"Change Dir  Success!\n";
        printcolor bold,"Input the filename:";
        chomp($down_file=<STDIN>);
        printcolor blue,"\nDownloading...Please Wait.\n";
        $ftp->get("$down_file","$config{local_dir}/$down_file") or die "Can't get the $down_file . ",$ftp->message;
        printcolor green,"+++ Download Success! +++\n\nMD5: ";
        $ftp->quit;
        open L_FILE,"$config{local_dir}/$down_file";
        printcolor yellow,Digest::MD5->new->addfile(L_FILE)->hexdigest,"\t$config{local_dir}/$down_file\n\n" ;
        close L_FILE;
}