Hello! I have had this issue before, and it happens randomly (especially when I need to do some file uploads). I will often get a timeout or something like:
Exception calling "Open" with
"1" argument(s): "Connection failed.
Timeout detected. (control connection)
Connection failed."
Here's a snippet of the setup:
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = "usxxxxxxxxxx.sharefileftp.com"
UserName = "xxxxxxxxxxx"
Password = $plainPass # Read in as a secure string
FtpSecure = [WinSCP.FtpSecure]::Implicit
Timeout = New-TimeSpan -Seconds 150
}
$session = New-Object WinSCP.Session
Remove-Item $sessionLog_File
$session.SessionLogPath = $sessionLog_File
$session.Open($sessionOptions)
All the rest of the code is just looping through directories and doing a bunch of
PutFiles
. It's a 50/50 shot, usually that it won't time out halfway through my file upload list or just after logging in.
I have already tried adding something like:
$session.Timeout = New-TimeSpan -Seconds 500
below the
$sessions.Open
, but I don't think anything has exactly worked better.
Thanks!