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' | [reply] [d/l] |
One problem you could be having with your date-extraction
regexp is case sensitivity and using =~ (matching)
instead of = (assignment). Try
($month,$day) = /(\d\d)(\d\d)x86\.exe/i;
-Mark | [reply] [d/l] |