Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

( #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


Description:

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.

--Dave

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

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2014-12-27 00:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (176 votes), past polls