I am using Python to develop an application that does the following:
- Monitors a particular directory and watches for file to be transferred to it. Once the file has finished its transfer, run some external program on the file.
The main issue I have developing this application is knowing when the file has finished transferring. From what I know the file will be transferred via SFTP to a particular directory. How will Python know when the file has finished transferring? I know that I can use the st_size
attribute from the object returned by os.stat(fileName)
method. Are there more tools that I need to use to accomplish these goals?
I ended up using a combination of watchdog and waited until I can open the file for writing
The best way to solve this would be to have the sending process SFTP to a holding area, and then (presumably using SSH) execute a
mv
command to move the file from the holding area to the final destination area. Then, once the file appears in the destination area, your script knows that it is completely transferred.