Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by javze (Novice)
on Feb 15, 2001 at 23:27 UTC ( [id://58696]=perlquestion: print w/replies, xml ) Need Help??

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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://58696]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 21:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found