Bash script: Monitor hotfolder and partial files

bashftpscripting

I have a customer that upload files through FTP, I made a script that basically monitor the ftp folder and move the file on a production machine.
How can I check if the file has been completely transferred from the customer through ftp before start my scp command in order to avoid to transfer partial files?

Best Answer

If your OS supports it you can take a look at incrond. The events that can be monitored are defined in the incrontab Perhaps the event your looking for is

IN_CLOSE_WRITE File opened for writing was closed (*)

or in combination with

IN_CREATE File/directory created in watched directory (*)

Note that

When monitoring a directory, ... the events above can occur for files in the directory, in which case the name field in the returned event data identifies the name of the file within the directory.