In my project I have a file uploading feature. Files are uploaded via FTP. I need to configure a listener that will check for new files and invoke a script only when file up
An old one but still worth adding good ideas to.
Basically, because of the nature of the internet it's pretty difficult to detect that a file is the entire file you want. Here's what I'd do:
Have clients perform the upload to a staging directory, let's call it "upload", once the put (upload) has finished the client should then rename the file to place it in another directory let's call it "ready". If the client has some issue mid transfer, the file will never end up in the "ready" directory. So no partial uploads.
Clients should handle the upload error and retry. Most clients will carry on uploading the file without needing to send the whole thing again.
On the server side you only need to act on the files in the "ready" directory and monitor for long lived files in the "upload" directory.
For extra assurance, the csender could generate a checksum file containing the sha256 hash of the contents of the file and send that with the file. That would allow you to validate the contents against the hash before doing anything with the file.