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); }; };

In reply to Re: Anti-Virus Signature Updates by Anonymous Monk
in thread Anti-Virus Signature Updates 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.