tags:

views:

162

answers:

5

I have a system which is writing files to a folder using FTP. I need to copy those files, but only when they FTP system has finished. How do I tell when the first process has finished writing.

+1  A: 

The easiest way would be to create a file indicating a finished transfer?

zoul
+3  A: 

To extend zoul's idea: have a file that indicated the last time the target has been updated. After every upload, you touch that file.

A cron process on the other side can then periodically check for updates and do its job.

Leon Timmermans
+11  A: 

Another possibility is to have the process which uploads the files upload them under a temporary name and then rename them.

Renames happen atomically so there would be no case where the file was incomplete under its final name.

The copying process could ignore the temporary named files.

MarkR
This would be the ideal solution if I had any control over the writing source.
Xetius
A: 

You should use Linux::Inotify2, it's made for that kind of thing ! :)

Just watch the 'IN_CLOSE' event on your FTP directory...

sebthebert
That would work in the common case, but it would also tell you the file was complete if the upload aborted, timed out or failed in some other way.
MarkR