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.
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
Start-Sleep -Seconds 25
in between each PutFileToDirectory
call and it resolves it, but I don't think this is the best solution.
# 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)
}