in reply to How can I get the timestamp of a file on a FTP server?
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;
|
|---|