Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Re: PutFiles uploads the file twice to SFTP site

@kimxavier.nati: As you yourself noticed, WinSCP uploads the file only once. If you end up with two files, it must be the server's doing. Did you try to upload the file in WinSCP GUI or even better using any other SFTP client? You will most likely see the same behavior.
Might be a variant of:
Why is uploaded file not showing in a remote directory or showing with a different name?

PutFiles uploads the file twice to SFTP site


I am encountering a similar issue on the SFTP side after uploading a file using a PowerShell script Session.PutFiles. The file looks to be uploaded twice, second file with an _1 after the extension e.g. kim.xml, kim.xml_1.

Logs show there's only 1 file getting copied or processed though.

Here's the script
$session = New-Object WinSCP.Session
$session.SessionLogPath = $logPath
# Connect
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult =
    $session.PutFiles($localPath, $remotePath)
# Throw on any error
Write-Host "Transfer count: " $transferResult.Transfers.Count

Attached is the modified log to remove sensitive data.

Re: PutFiles / Check ends up uploading files multiple times

The connection was indeed lost during the first upload attempt.
Can you have them check theirs logs to see if the server had any reason to terminate the connection?

See also Network error: Software caused connection abort

Re: PutFiles / Check ends up uploading files multiple times


I am attaching here the session log.
It is the entire log generated while I was trying to upload a 74 KB file.
There seems to be a "Network error: Software caused connection abort".

The log I generate inside my code does not capture an error.

These are some lines from the log I generate:
2019-03-28 12:20:12.668 | Connect to WinSCP.

2019-03-28 12:20:16.944 | Try upload all files in Outbox folder...
2019-03-28 12:20:37.732 | ...Done
2019-03-28 12:20:37.741 | Uploaded Files: 1, Files Failed: 0

And this is the relevant code that produces the above 4 lines of log.
// Connect
Add2Log("Connect to WinSCP.");
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Automatic;
transferOptions.PreserveTimestamp = false;
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;
TransferOperationResult transferResult;
Add2Log("Try upload all files in Outbox folder...");
transferResult = session.PutFiles(
      outboxFolder + "*"
    , remoteFolder
    , false
    , transferOptions
// Throw on any error
     "Uploaded Files: {0}, Files Failed: {1}"
    , transferResult.Transfers.Count
    , transferResult.Failures.Count


Re: PutFiles / Check ends up uploading files multiple times

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

PutFiles / Check ends up uploading files multiple times

Hi there,

This might be a server-side-caused-problem, but ...

I have a process where I upload files on SFTP protocol and then check for errors.
The files are in a Outbox folder when picked up by PutFiles.... then I call the Check().
From the transferResult.Transfers collection I take file by file and create my log and move the files to an Archive folder.
Everything works fine on my side, but on the server side, a file looks like it is uploaded multiple times ("they" have a log showing multiple uploads), and that might be because the destination file gets picked up "too quick" before my process ends.

Can someone explain why/how PutFiles works and why is re-uploading files?
As a note, the ResumeSupport is set to off.