in reply to ftp files (TMTOWTDI)
* 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:
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:$state_hash{$filename} = [$state,$size];
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-
|
|---|