http://qs321.pair.com?node_id=58696

javze has asked for the wisdom of the Perl Monks concerning the following question:

I need to get all files newer than a given time. Any ideas?

Originally posted as a Categorized Question.

  • Comment on How can I get the timestamp of a file on a FTP server?

Replies are listed 'Best First'.
Re: How can I get the timestamp of a file on a FTP server?
by spaz (Pilgrim) on Feb 16, 2001 at 01:05 UTC
    I assume you're using Net::FTP, and if you're not you should be.
    You can use the dir method to get a listing of files and directories, you can then iterate over that list and execute the mdtm( $file ) method on each file, which will give you the modification date.
    The rest is left as an exercise for the reader.

    --Dave
Re: How can I get the timestamp of a file on a FTP server?
by randyk (Parson) on Sep 21, 2005 at 15:27 UTC
    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;