Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Anti-Virus Signature Updates

by Anonymous Monk
on Jul 09, 2002 at 00:14 UTC ( [id://180357]=note: print w/replies, xml ) Need Help??


in reply to Anti-Virus Signature Updates

I think this is what you are looking for. I didnt get the chance to test it (sorry, Im way too tired and my eyes are crawling shut). Please share your code with the rest of us when you get it working! btw, You really should add error checking for the ftp transactions!
#!/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 $UPDATE_TRACKER = './lastupdate.txt'; # You should add error checking to make sure you actually make # a connection to the server my $ftp = Net::FTP->new($host, Debug => 1); $ftp->login($user,$pass); my @listing = $ftp->ls($remote_dir); foreach (@listing) { $_=~s/\r|\n//g; if ( /x86\.exe/gi ) { my ($response,$errmsg) = do_we_already_have_it($_); if ( $response != 1 ) { # Either we have it or we have an error if ($response == -1) { # We have an error print "Error - $errmsg\n"; quit_now(); }; } else { # We dont have it - grab it ($response,$errmsg) = grab_it($_); if ( $response == -1 ) { # We have an error print "Error - $errmsg\n"; quit_now(); }; }; }; }; quit_now(); sub quit_now { $ftp->quit; exit; }; sub grab_it { # returns 1 if we get the file # returns -1 if we dont get the file # in its current state it will only return -1 if we cant update # the tracker db my ($remote_file) = @_; $ftp->type("I"); $ftp->get($remote_file); # You should add error checking here to make sure you actually # get the file !! ( I would but im too tired ) if ( open(NEWUPDATE,">>$UPDATE_TRACKER") ) { print NEWUPDATE "$remote_file\n"; close(NEWUPDATE); return(1); } else { # Something went wrong return -1 and the error msg return(-1,$!); }; }; sub do_we_already_have_it { # returns 1 if we already have it # returns 0 if we dont have it # returns -1,error msg if something goes wrong (like permissions) my ($check_file) = @_; $check_file=~s/\r|\n//g; if ( open(LASTUPDATE,$UPDATE_TRACKER) ) { while(<LASTUPDATE>) { $_=~s/\r|\n//g; if ($_ eq $check_file) { close(LASTUPDATE); return(1); }; }; close(LASTUPDATE); return(0); } else { # something went wrong - check if the file exists # If the file exists then we have some sort of other error # that we should probably report back to the client # otherwise we simply dont have it yet ! if(-e $UPDATE_TRACKER) { return(-1,$!) }; return(0); }; };

Replies are listed 'Best First'.
Re: Re: Anti-Virus Signature Updates
by Anonymous Monk on Jul 09, 2002 at 00:28 UTC
    First occurance of
    if ( $response != 1 ) {
    should have been
    if ( $response != 0 ) {
    I blame it on the heat and lack of sleep!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://180357]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found