1

I'm writing a shell script which would use inotify to monitor certain directories for incoming SFTP uploads. When a client is done uploading a file, the file would be handed over to another script which processes the file.

Now what happens if the network connection goes down in the mid of a transfer? As far as I understand openssh's sftp server, the file on the server would be closed, inotify would report a close event and my script would start to process the incomplete file.

This is obviously not what I want, so I need to tell complete and incomplete files apart.

Now my favorite way of doing this would be that either the sftp server or the client add an extension to the file name (e. g. .part or .filepart) to indicate that the file is incomplete. Once the transfer is confirmed to be complete, the extension would be removed.

Unfortunately, client behavior is not under my control, so the only way to implement the extension solution would be by implementing it on the server side.

Now is there some way how I can make the openssh sftp server add .part/.filepart extensions to incomplete files? Or is there some other way how I can tell whether a file is complete or not?

2
  • 2
    I afraid that there's no way. See also SFTP file lock mechanism. Mar 4, 2020 at 6:19
  • I just found a solution, but I don't like it because it only works for my specific use case: The files being transmitted always use a file format which includes an end-of-file marker at the end of the file. By looking for that end-of-file marker, I can tell whether the file is complete or not.
    – erebus
    Mar 4, 2020 at 17:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.