Archived Forum Post

Index of archived forum posts


SFTP download issue

Jan 30 '17 at 15:52


We have an application that uses Chilkat SFTP to collect files from various folders on our SFTP server, and occasionally an incomplete file is downloaded which I think is because it is in use at the time by the customer and not yet finished with. I have tried various access and dispositions in the openfile method but it always succeeds in getting a handle on the file, which surprises me.

Is there any way I can check if a file is in the middle of being uploaded by another party before I try and download the file ?

Any help appreciated

Thank you


You could call GetFileSize32 both before and after the download to see if the sized changed during the download. You could also call GetFileSize a short time later to see if the file size changed.

I don't know if there's a way to know if a local process on the remote server also has the file open. The SSH server is the one opening the remote file, and to it the file is local. It's just opening the file, and if the open succeeds, it succeeds.

One thing you might try is to download the file by calling OpenFile w/ an access of "readWrite" to get a handle, then read the file using the handle via the ReadFile* methods, and then close the handle (CloseHandle method). The hope is that the server opens for exclusive access when the access mode is readWrite (as opposed to readOnly). There's nothing in the SFTP protocol that explicitly requests "open for exclusive access" as far as I know (or can remember..).



Thanks for the input - I will try your suggestions



Is it possible for the creating program to add an extension like .xfr, .filepart, or a temp name, and then rename the file at success create.

you then ignore these files.


Horrible implementation of file locking on a Windows system. Unix has a command to check file locking. And it even gets worse if file system on a net appliance.