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
I attached the session log with error
Portion of the code is
Apologize if I haven't posted a proper posting as I am new to PowerShell scripting and WINSCP
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) }