0 votes
by (150 points)

When monitoring file uploads to a FileServer instance using the FileUploaded event, FileTransferredEventArgs filename fields contain a suffix of "filepart" for files of any significant size.

As far as I can tell, the event is only called when the file transfer is completed, so I am confused why the event doesn't have the final file name. Is this by design and i am doing something incorrectly?

Kind Regards
Craig

Applies to: File Server

1 Answer

0 votes
by (72.7k points)
selected by
 
Best answer

As far as I know, FileServer should not modify any names which comes from client. So it seems that the "filepart" suffix was added by client.

Can you please send us communication log to support@rebex.net (or post it here). It can be created like this:

var server = new FileServer();
server.LogWriter = new Rebex.FileLogWriter("C:/server/log.txt", Rebex.LogLevel.Debug);

This is server log when I upload 185 MB file:


2017-09-06 18:45:10.649 DEBUG SftpModule(1)[8] SFTP: Opening file '/OUT/Foto1.zip' (Create, Write): success.
2017-09-06 18:45:15.033 DEBUG SftpModule(1)[10] SFTP: Closing file '/OUT/Foto1.zip': success.

My output from FileUploaded event:


File upload finished.
User: 'tester'
File: 'c:\temp\OUT\Foto1.zip'
'/OUT/Foto1.zip'
total bytes: 185523333

As you can see, there is no "filepart" suffix.

by (150 points)
I have executed testing  using Mac OSX sftp command and also WinSCP.   It looks like the behaviour of WinSCP is different to Mac.

code is here:
class Program
    {
        static void Main(string[] args)
        {
            var server = new FileServer();
            server.Bind(22, FileServerProtocol.Sftp);
            server.Keys.Add(new SshPrivateKey("private.key", "test"));
            server.Users.Add("WinSCP", "test", "C:/ftproot");
            server.Users.Add("MacOSX", "test", "C:/ftproot");
            server.FileUploaded += Server_FileUploaded;
            server.LogWriter = new Rebex.FileLogWriter("C:/ftproot/log.txt", Rebex.LogLevel.Debug);
            server.Start();
            Console.ReadLine();
        }

        private static void Server_FileUploaded(object sender, FileTransferredEventArgs e)
        {
            File.AppendAllText("C:/ftproot/UploadLog.txt", $"{DateTime.Now.ToString("u")} COMPLETE BytesTransferred={e.BytesTransferred.ToString("#,##0")} Path='{e.Path}' User='{e.User.Name}'\r\n");
        }
    }

I have sent logs from above via email.
Thanks
by (72.7k points)
Thank you for the log file. It showed that the "filepart" behavior is done by WinSCP client on purpose. For some files (probably greater than X bytes), WinSCP uploads the file with .filepart extension and after successful transfer it renames it to original name. See following part of the log:

2017-09-07 07:12:31.145 DEBUG SftpModule(2)[20] SFTP: Getting item info on '/IMG_0041.JPG': not found.
2017-09-07 07:12:31.145 DEBUG SftpModule(2)[21] SFTP: Getting item info on '/IMG_0041.JPG.filepart': not found.
2017-09-07 07:12:31.146 DEBUG SftpModule(2)[21] SFTP: Opening file '/IMG_0041.JPG.filepart' (Create, Write): success.
2017-09-07 07:12:31.156 DEBUG SftpModule(2)[21] SFTP: Closing file '/IMG_0041.JPG.filepart': success.
2017-09-07 07:12:31.165 DEBUG SftpModule(2)[21] SFTP: Renaming '/IMG_0041.JPG.filepart' to '/IMG_0041.JPG': success.
2017-09-07 07:12:31.166 DEBUG SftpModule(2)[21] SFTP: Setting item info on '/IMG_0041.JPG': success.


WinSCP performs these steps:

 1. Check whether '/IMG_0041.JPG' exists
 2. Check whether '/IMG_0041.JPG.filepart' exists
 3. Upload file to '/IMG_0041.JPG.filepart'
 4. Rename '/IMG_0041.JPG.filepart' to '/IMG_0041.JPG'

This behavior cannot be modified by the server.
by (150 points)
Thankyou so much for this. Wasn't something I considered!

It seems there is a way to turn off this behaviour in WinSCP so that should be sufficient.

Cheers.
...