So please collect the logs for us.
- martin
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
.filepart
extension while transferring.
$sessionOptions.AddRawSettings("SendBuf","0")
Host is not communicating for more than 15 seconds. Host is not communicating
Note: If the problem repeats, try turning off 'Optimize connection buffer size'.
Warning: Aborting this operation will close connection!
Remote side sent disconnect message type 11 (by application): "Idle connection"
Authentication log (see session log for details): Using username .
Authentication failed.
for
loop to execute the transfer multiple times after a failure. However, it seems the transfer always starts the from the beginning of the file on each iteration. This is very time consuming especially if the the transfer aborts 45 minutes into the download and starts from the beginning again. I do know the server supports resuming a download.
Function Get-SupplierFtpFile
{
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory=$True)]
[String]$RemotePath,
[Parameter(Position=1, Mandatory=$True)]
[String]$LocalPath,
[Parameter(Position=4, Mandatory=$false)]
[int]$Iterations = 36,
[Parameter(Position=5, Mandatory=$false)]
[int]$WaitSeconds = 300
)
Try
{
[Void][System.Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\WinSCP\WinSCP.dll")
$FileName = [System.IO.Path]::GetFileName($RemotePath)
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Ftp
$sessionOptions.FtpMode = [WinSCP.FtpMode]::Passive
$sessionOptions.HostName = "ftp4.xxxxxxxx.com"
$sessionOptions.UserName = "Username"
$sessionOptions.Password = "pa$$word"
$sessionOptions.PortNumber = 990
$sessionOptions.FtpSecure = [WinSCP.FtpSecure]::Implicit
$sessionOptions.SslHostCertificateFingerprint = "99:98:97:96:19:2f:dd:cc:aa:ff:89:78:77:66:76:75:74:73:72:71"
# Connect
$session = New-Object WinSCP.Session
$session.SessionLogPath = "D:\Logs\GetFTP\$(Get-Date -Format "yyyyMMddHHmm").FTPlog.txt"
$session.Open($sessionOptions)
Try
{
For([int]$x = 1;$x -le $Iterations;$x += 1)
{
Write-EventLog -LogName ScriptEvents -Source PowerShellITG `
-Message "Supplier refresh: Download started." `
-EventId 1001 -EntryType Information
Try
{
$session.GetFiles($remotePath,$localPath).Check()
Break
}
Catch
{
Write-Warning $_.Exception.Message
Write-EventLog -LogName ScriptEvents -Source PowerShellITG `
-Message "Supplier refresh: Download aborted $x times. Retry in 5 minutes." `
-EventId 1002 -EntryType Warning
}
Start-Sleep -Seconds $WaitSeconds
}
If($x -ge $Iterations)
{
Throw "Excessive time waiting for remote file access."
}
Get-Item $localPath -ErrorVariable ERR -ErrorAction SilentlyContinue | Out-Null
If($ERR)
{
Throw $ERR.Message
}
Return $localPath
}
Catch
{
Throw $_.Exception
}
}
Finally
{
# Disconnect, clean up
$session.Dispose()
}
Return
}