SFTP supports blocking from version 5. See specification .
You did not specify which SFTP server you are using. Therefore, I assume the most common, OpenSSH. OpenSSH only supports SFTP version 3, so it does not support blocking.
In any case, even if your server supports file locking, most SFTP clients / libraries do not support SFTP version 5. Or even if they do, they will not support the lock function. Note that the lock is explicit, the client must request it.
There are some general solutions to the problem:
- As suggested by @ user1717259, you can download the client "made" file after the download is complete. Make the automatic system wait for the "done" file to appear.
- You may have a dedicated โdownloadโ folder and the client (atomically) moves the downloaded file to the โdoneโ folder. Make an automatic system only in the "done" folder.
- Have a file naming convention for the uploaded files (".filepart") and ask the client (atomically) to rename the file after downloading to its final name. Make the automatic system ignore the ".filepart" files.
See (My) article Lock files when uploading / downloading to a temporary file name , for example, when implementing this approach. - Gross hacking is to periodically check file attributes (size and time) and consider a completed download if the attributes have not changed over a period of time.
Martin Prikryl
source share