0 votes
by (120 points)

I'm evaluating FileServer and need to process file after upload. I start with FileServerWinForm_CS example. I added FileUpload event handler, but the problem is at that moment uploaded file is still with temporary name. Looking at log renaming the file happens after FileUpload event is handled.
Is it possible to step in after uploaded file is renamed?

Applies to: Rebex SFTP

1 Answer

0 votes
by (73.6k points)

I am sorry, I don't know what do you mean by "uploaded file is still with temporary name".

The Rebex FileServer does not use any temporary names.

I added this code to the FileServerWinForm_CS example:

_server.FileUploaded += (s, e) =>
{
    MessageBox.Show(string.Format(
        "Uploaded: {0}\nTo: {1}", e.Path, e.FullPath));

    var content = File.ReadAllText(e.FullPath);
    MessageBox.Show(content);
};

The result is a message box showing something like this:

Uploaded: /test.txt
To: c:\Sample\test.txt

And then second message box showing content of the uploaded "c:\Sample\test.txt" file.

What do you mean by "temporary name"?

by (120 points)
edited by
Sorry, mistake from my side. I am not familiar with protocol behavior. It is not temporary file name, it is name of the transferred chunk with extension "filepart".

From log:
13:05:24.620 Debug SFTP: Opening file '/test.xlsx.filepart' (Create, Write): success.
13:05:24.711 Debug SFTP: Closing file '/test.xlsx.filepart': success.
13:05:24.713 Debug SFTP: Renaming '/test.xlsx.filepart' to '/test.xlsx': success.
13:05:24.713 Debug SFTP: Setting item info on '/test.xlsx': success.

So is there any way to know when file transfer is finished.

Edit
I am using WinSCP as client which may be reason for this?

Thank you for fast answer.
by (73.6k points)
Oh, I see. Yes, this is behavior of your SFTP client (WinSCP in your case).

You can disable it in Options->Preferences->Transfer->Endurance->Disable temporary filename.

Please note that the server is not aware of what client is going to do. So, when the file '/test.xlsx.filepart' is closed from the client side, the transfer is finished from the server point of view. At this point the FileUploaded event is raised and client is "blocked", until the event is finished.
This means the rename operation will not be issued until the event ends = you can process the *.filepart file without worries. When the event is finished, the client completes the operation by renaming the *.filepart file without realizing that the file was modified during the process.
...