You basically want to keep state. Two things make it easy for your application to keep state:

* You are constantly running, meaning there is no need to keep a persistent state

* For those times when your program has stopped and needs to rebuild state, you are lucky that you have your state automatically persistent: it's the files on your local system.

To implement your state keeping, you could use a hash of filenames and array references as the data structure:

$state_hash{$filename} = [$state,$size];
The state hash would have filenames as a key, and a reference to an anonymous array as value. The anon array would contain a state and a size as elements. $state would have different values depending on whether the file in question is:

i) growing on the server

ii) no longer growing on the server but not yet downloaded

iii) downloaded to the local system

When the state is i) above, $size stores the current size of the file on the server.

Every five minutes, your script would then get a directory listing, loop over the files and check whether they are in the hash. If they are not in the hash, it would put them in the hash in the appropriate state, and if they are in the hash will update their state and download them if necessary.

Upon startup, the script would initialise the hash based on the files already on the local system.

That's how I would implement it. You will undoubtedly have noticed that I have cunningly refrained from posting any useful code. Sarcastically inclined people would point out that this is because none of my code is ever useful, but my excuse is that this is really a design rather than implementation issue. Nah.

CU
Robartes-


In reply to Re: ftp files (TMTOWTDI) by robartes
in thread ftp files (TMTOWTDI) by mkirank

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.