SFTP PutFileToDirectory failing on 3rd file being transferred.

Advertisement

drobbins
Joined:
Posts:
1
Location:
Ontario

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

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,453
Location:
Prague, Czechia

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.

Reply with quote

Advertisement

You can post new topics in this forum