1

我无法使用 Net::Ftp 获取文件的大小。我收到的错误是“file1.csv:没有这样的文件或目录”。我确定该文件存在。$ftp->supported('size')返回真。使用完整路径 ('/otherdir/file1.csv') 会导致相同的错误。我正在使用的目录中没有子目录,所有文件的大小都>0。我究竟做错了什么?我已将我的代码精简为以下代码段 -

#! /usr/bin/perl
use strict;
use warnings;
use Net::FTP;

my $ftp = Net::FTP->new("host", Debug =>0) or die "couldnt connect: $@";
$ftp->login("username","password") or die "couldnt login: ", $ftp->message;
$ftp->binary;
$ftp->cwd("otherdir") or die "couldn't cwd ", $ftp->message;
my @ftp_files = $ftp->ls();
print scalar(@ftp_files);

foreach  (@ftp_files){
  print $_,"\n";
  my $size= $ftp->size($_) or die $ftp->message;
  print $size,"\n";
}
4

1 回答 1

1

size() 仅适用于文件。不是文件夹。您的代码可能会死掉,因为它为文件夹获取了 $size 的 undef。它永远不会到达那里的文件。

于 2013-06-28T19:53:30.410 回答