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?

  • 2
    The usual trick for this is to embed the file's checksum in the filename. Sep 10, 2014 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. Sep 10, 2014 at 11:30

2 Answers 2


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.


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 .