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

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 ( [id://493844]=note: print w/replies, xml ) Need Help??


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

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: note [id://493844]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-25 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found