I would like to test files and directories which I downloaded with ftp if they are files or directories. With the code below I always get the else statement (2,4,6) what ever $x
is (file or directory). What is wrong with this code?
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)";}
}