You're automating the download of new virus definitions from Symantec, right? I have code to do this at work, but due to a misplaced fit of paranoia the other day, I changed my password on my ssh gateway and so I'm locked out right now. I can post you my code tomorrow, but in the meantime here a few hints to get you started.

The main problem is dealing with the end-of-year wrap around, when file 0112x86.exe is more recent than 1221x26.exe. Another problem is that sometimes the filename lies. The date encoded in the filename does not agree with the filesystem time. I choose to trust the filesystem time. The following code (which I am writing from memory), will determine the most recent file on the remote server that follows the filename convention.

#! /usr/local/bin/perl -w use strict; use Net::FTP; my $host = 'ftp.example.com'; my $user = 'anonymous'; my $pass = 'grinder@localhost'; my $remote = '/pub'; my $ftp = Net::FTP->new($host); # error $ftp->login($user,$pass); # checking my @listing = $ftp->dir($remote); # omitted my $latest_timestamp = 0; my $latest = undef; my $cur_year = (localtime)[5] + 1900; for my $line( @listing ) { my( $prot, $links, $user, $group, $size, $month, $day, $yeartime, $e +ntry ) = ($line =~ /^(\S+)\s+(\d+)\s+(\w+)\s+(\w+)\s+(\d+)\s+(\w+)\s+(\S+)\s+ +(.*)$/); if( $entry =~ /^(\d\d)(\d\d)i86\.exe$/ ) { my( $year, $hour, $min ) = do { $yeartime =~ /^(\d\d):(\d\d)$/ ? ( $cur_year, $1, $2 ) : ( $yeartime, 0, 0 ) }; my $timestamp = sprintf '%04d%02d%02d%02d%02d', $year, $month, $day, $hour, $min; if( $latest_timestamp lt $timestamp ) { $latest_timestamp = $timestamp; $latest = $entry; } } } exit unless $latest_timestamp; my $prev = undef; if( open IN, 'latest' ) { $prev = <IN>; close IN; chomp $prev; } if( !defined($prev) or $prev lt $latest_timestamp ) { $ftp->get("$remote/$entry"); open OUT '>latest' or die "latest for output: $!\n"; print "$latest_timestamp\n"; close OUT; }

Basically, you scan the remote directory, find the most recently updated file, and see if it is more recent than the most recent timestamp you have cached locally. If it is, get that file, and update your local timestamp.


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: Comparing file dates then downloading newer files through ftp by grinder
in thread Comparing file dates then downloading newer files through ftp by linebacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.