如果它们是文件或目录,我想测试我用 ftp 下载的文件和目录。使用下面的代码,我总是得到 else 语句 ( 2,4,6 ) 曾经$x
是什么 (文件或目录)。这段代码有什么问题?
use Net::FTP;
my $host = "whatever";
my $user = "whatever";
my $password = "whatever";
my $f = Net::FTP->new($host) or die "Can't open $host\n";
$f->login($user, $password) or die "Can't log $user in\n";
# grep all folder of top level
my @content = $f->ls;
# remove . and ..
@content = grep ! /^\.+$/, @content;
foreach my $x (@content) {
print "\n$x: ";
if ( -f $x ) {print " ----> (1)";} else {print " ----> (2)";}
if ( -d $x ) {print " ----> (3)";} else {print " ----> (4)";}
if ( -e $x ) {print " ----> (5)";} else {print " ----> (6)";}
}