WinSCP: How to make sure that SFTP download is renamed from .zip.filepart to .zip?

Using the .NET WinSCP assembly to download a file. OperationResultBase.Check() throws the following error:

WinSCP.SessionRemoteException: the transfer was completed successfully, but the temporary transfer file "testfile.zip.filepart" could not be renamed to the name of the target file "testfile.zip". If the problem persists, you can disable support for resuming transfers.

This seems to be happening with any zip file I'm trying to send. If that matters, these are zip files that were created using the DotNetZip library.

The code I use is pretty much taken 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); } } 

A discussion on the WinSCP forum indicates that the assembly does not yet allow programmatic control of resumption of transmission support. Is there a workaround for this?

+6
source share
3 answers

It sounds as if the file system on the destination server where the file is being downloaded does not allow permission to modify the file. This may result in the renaming of the file failing at the end of the download, even though the complete file was downloaded and written to the file system with the temporary file name used during transfer. If you do not have administrative access to the target server, you can verify this by trying to rename a file that is already on the destination server. If this also fails, then you must either change the permissions on the destination server for this to work. Otherwise, you may have to use the recommendations provided in your error message to disable support for renewal, so it initially opens for writing with the desired file name instead of the temporary file name (with the .filepart extension).

+4
source

Disable recovery:

 put *.txt -nopreservetime -nopermissions -resumesupport=off 
+1
source

This will help if you included the full error message, including the root cause returned by the server.

I assume that on the server side there is an antivirus application (or the like). The anti-virus application scans any file after the download is complete. This conflicts with WinSCP trying to rename the file after the download is complete. The problem may tend to occur more often for .ZIP archives because they tend to be larger or simply because they need to be removed before checking (which takes time).

In either case, you can disable the transfer to a temporary file name using TransferOptions.ResumeSupport .

See also the documentation for the message "The transfer was completed successfully, but the temporary transfer file ... could not be renamed to the name of the target file ..."

0
source

Source: https://habr.com/ru/post/917226/


All Articles