0 votes
by (270 points)
reopened by

Hi, I have setup a sftp server using FileServer class. I would like to "do something"(on my server) after all files has been successfully transfer from client to my sftp server. Is there any way that my server can know or check if all files transfer successfully into my server? I saw FileServer class has event FileServer.FileUploaded Event but i'm not sure how to use it. Appreciated if there are some sample code to handle the event.

Thanks in advance!

Applies to: Rebex SFTP, File Server

1 Answer

+1 vote
by (145k points)
selected by
Best answer

In the SFTP protocol, there is no concept of multi-file transfers. It's in actually a simple remote file system protocol, despite its name.

This means that there is no standard way for an SFTP client to signal an "end of a multi-file transfer" to the server. In practice, if the whole file transfer process is under your control, there are numerous workaround for this - for example, the SFTP client might upload a ".done" file when all the files have been uploaded. Then, you could use FileUploaded event to detect this.

The drawback of this is that it won't work for client's that don't behave as expected. However, because this is due to the limitation of the SFTP protocol itself, there doesn't seem to be any substantially better alternatives.

by (270 points)
edited by
I see, thats what i've concluded after doing some research. Thanks for the answer! I have some further question I hope that you are able to help... I will "do something" within FileUploaded event but what if this "do something" results a fail and I want to inform client that file transfer actually failed...(even though file has uploaded successfully to my server) Is there some event that I can raise or alter the command send back to client within this FileUploaded event?
by (145k points)
The recommended solution would is to create a ".result" file inside (or following) the "FileUpload" event that contains information about the result of that "do something" operation. The client would then simply download the file to determine the result.
by (270 points)
I see, that would be one solution. But I want to make it user friendly for client, is there anyway I can force file transfer failed on client side?(by sending file transfer failed command back to client or something) The client i'm using is Filezilla.
by (145k points)
Well, we could make it possible to trigger an error in response to SFTP's "close" command (which is called at the end of each file transfer), but the problem with this is that some SFTP clients just ignore this silently. I'll give it a try with FileZilla and see what we can do!
by (270 points)
Thanks!!! Appreciated for the help!
by (145k points)
I gave this a try - unfortunately, FileZilla appears to be among the SFTP clients that ignore error responses to "close" requests. It still displays "File transfer successful" message in that case. Bitvise SSH Client and PuTTY 'psftp' command-line client behave like this as well. I'm afraid that having the client download a ".result" file in order to determine the result is the most user-friendly option.
by (270 points)
I see... Thanks a lot for the help. Really appreciate the effort!