How can you react to an abort transfer command on the FileServer?

0 votes
asked Apr 18 by suggo (190 points)

I am using the Rebex FileServer and a Rebex SFTP client. The server application is linked to a database to store users and custom file details.
The FileUploaded/FileDownloaded event is used to update the database and rename the file uploaded.
The problem I have is that if the client hits the Abort Transfer button, the server aborts the upload but still fires the FileUploaded/FileDownloaded event so the database becomes inaccurate.
Is there an event or some way to recognize on the server that the transfer has been aborted so I can alter my custom FileUploaded/FileDownloaded event handling?

I am using the PutFileAsync command for uploading and the Download command for downloading.

1 Answer

0 votes
answered Apr 18 by Lukas Pokorny (92,230 points)

This happens due to the nature of the SFTP protocol, which actually has no concept of 'upload a file' or 'download a file'. It is a POSIX-like remote file system protocol with operations such as open, read, write and close. FileUploaded/FileDownloaded events are raised on close when any data has been written/read.

So when the 'abort transfer' functionality actually closes the remote file, the server cannot distinguish this from a completed transfer (due to the nature of SFTP protocol) and raises the events. Interestingly, if you closed the SFTP session without aborting the transfer, the server would not receive the close request and would not raise the events.

In most scenarios, all we can do is to recommend to Rebex File Server users to modify their transfer logic and trigger the 'done' state differently (for example, upload the file into a .tmp file first, and only consider the transfer complete when it's renamed to the desired file name).

However, your scenario is different because you use Rebex libraries at both ends. We can introduce a custom extension that could be used by the client to indicate whether the data transfer is to be considered aborted. This would work transparently in Rebex SFTP and Rebex File Server scenario. Third-party SFTP clients would still work as before, but they would not be able to indicate this (unless they implement the extension as well, of course). Would you be interested in this solution?

commented Apr 18 by suggo (190 points)
I would definitely interested in this, in fact I would like it yesterday(joke), but this would be a terrific extension not only for my system but also others who have asked in the past.

I realized that it would take changes for both client and server for it to work, but since my system is a pure Rebex system, I was hopeful for a possible solution.
commented Apr 19 by Lukas Pokorny (92,230 points)
We'll review this and keep you updated!
commented Apr 22 by suggo (190 points)
Thank you for not saying "out of scope"
...