Using the
dir method of
Net::FTP to get a directory listing, you
can feed this into
File::Listing to extract the desired
information, as in the following example:
use strict;
use warnings;
use Net::FTP;
use File::Listing qw(parse_dir);
use POSIX qw(strftime);
my ($host, $user, $passwd) = ('a.b.org', 'me', 'pgrx%sf');
my $dir = '/some/dir';
my $ftp = Net::FTP->new($host)
or die qq{Cannot connect to $host: $@};
$ftp->login($user, $passwd)
or die qq{Cannot login: }, $ftp->message;
$ftp->cwd($dir)
or die qq{Cannot cwd to $dir: }, $ftp->message;
my $ls = $ftp->dir();
foreach my $entry (parse_dir($ls)) {
my ($name, $type, $size, $mtime, $mode) = @$entry;
next unless $type eq 'f';
my $time_string = strftime "%Y-%m-%d %H:%M:%S", gmtime($mtime);
print "File $name has an mtime of $time_string\n";
}
$ftp->quit;