6

This question already has an answer here:

I have machine on which the files are uploaded by ftp. From this machine I would like to run cronjob and scp/rsync (simply copy them) to different machine in the same network.

The problem is I don't want to copy files which are not coplete (still during transfer) Is there a possibility to check whether a file is complete and only then copy to another server?

marked as duplicate by Gilles bash Sep 10 '14 at 22:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    The usual trick for this is to embed the file's checksum in the filename. – Mark Plotnick Sep 10 '14 at 11:10
  • 2
    Another trick would be to have uploading processes set read permission for the copied file only after the copy is complete. I'm not sure if it is feasible to persuade all upload processes to adhere to this. – Marc van Leeuwen Sep 10 '14 at 11:30
4

You can use lsyncd:

Lsyncd watches a local directory trees event monitor interface (inotify or fsevents). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes. By default this is rsync.

You can specify the time out after which a file has changed is to be synced. Set it to e.g. five times the typical upload time and you're probably fine.

0

If the lsyncd idea isn't to your liking - because "typical upload time" is something bound to break on a medium like the internet, not even considering a wider range of upload sizes (from 32K to 1234T), just think of a resumed ftp transfer. Well, even my idea doesn't help you there, I'm afraid. But how about using lsof?!?

lsof /home/ftp

Well, after a little perusing in the lsyncd documentation I guess my concerns - born out of the phrasing "typical upload time" - seem unwarranted; the default inotify it watches for is "CloseWrite", which seems fine. YMMV.

Not the answer you're looking for? Browse other questions tagged or ask your own question.