#!/usr/bin/perl -w
use strict;
use Net::FTP;
my $host = 'www.ftp.com';
my $user = 'anonymous';
my $pass = 'updatepuller@ftp.com';
my $remote_dir = '/pub/antivirus/NAV/signatures';
my $destination_dir = 'current-sig';
####
my @lupd = ();
if(-e "./lastupdate.txt") {
open(LASTUPDATE,"./lastupdate.txt")
or die "Error while opening lastupdate.txt ($!)";
chomp( @lupd = );
close(LASTUPDATE);
}
##
##
my %haveit;
@haveit{ @lupd } = (1) x @lupd;
my $ftp = Net::FTP->new($host, Debug => 1);
$ftp->login($user,$pass);
$ftp->type("I");
my @listing = grep /x86\.exe$/i, $ftp->ls($remote_dir);
my @newupdate;
foreach my $file (@listing) {
##
##
next if $haveit{ $file };
$ftp->get($file) or next;
push @newupdate, $file;
}
$ftp->quit;
open(NEWUPDATE,">>./lastupdate.txt")
or die "Couldn't open lastupdate.txt for appending ($!)";
print NEWUPDATE map "$_\n", @newupdate;
close(NEWUPDATE)
or die "Closing lastupdate.txt failed ($!)";