简体   繁体   English

为什么无法通过Net:FTP获得文件的大小?

[英]Why can't I get a file's size with Net:FTP?

I cannot get a file's size with Net::Ftp. 我无法通过Net :: Ftp获得文件的大小。 The error I receive is "file1.csv: No such file or directory." 我收到的错误是“ file1.csv:没有这样的文件或目录。” I'm sure the file exists. 我确定文件存在。 $ftp->supported('size') returned true. $ftp->supported('size')返回true。 Using the full path ('/otherdir/file1.csv') results in the same error. 使用完整路径('/otherdir/file1.csv')会导致相同的错误。 There are no sub directories in the directory I am using & all of the files have a size >0. 我正在使用的目录中没有子目录,所有文件的大小均> 0。 What am I doing wrong? 我究竟做错了什么? I've stripped my code down to the following snippet - 我已将代码剥离为以下代码段-

#! /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";
}

size() only works for files. size()仅适用于文件。 Not folders. 不是文件夹。 Your code is probably die-ing because it gets a $size of undef for a folder. 您的代码可能正在消亡,因为它为文件夹获取了$ def大小的undef。 It never reaches the files that are there. 它永远不会到达那里的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM