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.

Options
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)

Options

Topic review

martin

Re: SFTP PutFileToDirectory failing on 3rd file being transferred.

The error comes from the server. Please ask the server administrator, why the server cannot accept three successive uploads.
drobbins

SFTP PutFileToDirectory failing on 3rd file being transferred.

We have a PowerShell script that SFTP files. It transfers 2 files but consistently fails on the third file (regardless of size). I added a Start-Sleep -Seconds 25 in between each PutFileToDirectory call and it resolves it, but I don't think this is the best solution.

I attached the session log with error

Portion of the code is
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = $HostName
    UserName = $UserName
    SshHostKeyFingerprint = $SshHostKeyFingerprint
    SshPrivateKeyPath = $SshPrivateKeyPath
    Timeout = New-TimeSpan -Seconds 60
}
$session = New-Object WinSCP.Session   
$session.SessionLogPath = "e:\FTP\DV\Config\session.log"
 
$session.Open($sessionOptions)           
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.ResumeSupport.State = WinSCP.TransferResumeSupportState]::Off
$transferOptions.FilePermissions = $Null
$transferOptions.PreserveTimestamp = $False
         
#Get all files with file extension *.EFT80ST from process folder
$processFileList = Get-ChildItem -Path $FTPTransferFiles
 
#iterate thru each file in the list
foreach ($item in $processFileList) {                               
    $transferResult =
        $session.PutFileToDirectory(
            $item.FullName, $RemoteDirectory,$False, $transferOptions)
}

Apologize if I haven't posted a proper posting as I am new to PowerShell scripting and WINSCP