Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by javze (Novice)
on Feb 15, 2001 at 23:27 UTC ( #58696=categorized question: print w/replies, xml ) Need Help??
Contributed by javze on Feb 15, 2001 at 23:27 UTC
Q&A  > HTTP and FTP clients


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

Answer: How can I get the timestamp of a file on a FTP server?
contributed by spaz

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.


Answer: How can I get the timestamp of a file on a FTP server?
contributed by randyk

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) = ('', '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;

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (4)
    As of 2020-06-06 12:08 GMT
    Find Nodes?
      Voting Booth?
      Do you really want to know if there is extraterrestrial life?

      Results (41 votes). Check out past polls.