Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinSCP: How to make sure SFTP upload gets renamed from .zip.filepart to .zip?

Using the .NET assembly of WinSCP to upload a file. OperationResultBase.Check() is throwing the following error:

WinSCP.SessionRemoteException: Transfer was successfully finished, but temporary transfer file 'testfile.zip.filepart' could not be renamed to target file name 'testfile.zip'. If the problem persists, you may want to turn off transfer resume support.

It seems that this happens with any zip file that I try to send. If it makes a difference, these are zip files that were created using the DotNetZip library.

Code that I'm using, taken pretty much directly from the example in the WinSCP documentation:

public void uploadFile(string filePath, string remotePath)
{
    TransferOptions transferOptions = new TransferOptions();
    transferOptions.TransferMode = TransferMode.Binary;
    TransferOperationResult transferResult;
    transferResult = currentSession.PutFiles(filePath, remotePath, false, transferOptions);
    transferResult.Check();
    foreach (TransferEventArgs transfer in transferResult.Transfers)
    {
        Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
    }
}

Discussion over at the WinSCP forum indicates that the assembly doesn't yet allow programmatic control of transfer resume support. Is there a workaround for this?

like image 687
sigil Avatar asked Jun 01 '12 22:06

sigil


2 Answers

It sounds as if the filesystem on the destination server where the file is getting uploaded to does not allow file change permissions. This could be causing the renaming of the file at the finish of the upload to fail despite the fact that the complete file was uploaded and written to the filesystem with the temporary file name used while the transfer was in progress. If you don't have administrative access to the destination server, you can test that by trying to rename a file that is already on the destination server. If that fails also, then you will either need to have the proper permissions on the destination server changed in order for that to work. Otherwise you might have to use the advice provided in your error message to turn off the resume support so it is initially opened for writing with the desired filename instead of the temporary filename (with the .filepart extension).

like image 100
dmarietta Avatar answered Oct 01 '22 21:10

dmarietta


Turn off the resumesupport:

put *.txt -nopreservetime -nopermissions -resumesupport=off
like image 38
low Avatar answered Oct 01 '22 20:10

low