Keep disconnecting from FTP

Advertisement

abd1111
Joined:
Posts:
18

Keep disconnecting from FTP

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!

Reply with quote

Advertisement

abd1111

Wondering, also, if session.ReconnectTime
needs to be called in order to work, or is it just on by default? I'd love something that could force re-connect. Thanks. Not terribly PowerShell savvy.

Reply with quote

abd1111
Joined:
Posts:
18

Here's a snippet with the same settings where it tries listing the first directory and then just stops in another log:
> 2025-08-20 15:18:12.849 Script: ls -- "/1 xxxxx CLIENTS/xxxxxxxx/Sydney TPA/A-CAP/Client Folders/xxxxxxxx/"
. 2025-08-20 15:18:12.849 Retrieving directory listing...
> 2025-08-20 15:18:12.849 CWD /1 xxxx CLIENTS/xxxxxx/Sydney TPA/A-CAP/Client Folders/xxxxxxxxxxxx
. 2025-08-20 15:20:42.155 Timeout detected. (control connection)
. 2025-08-20 15:20:42.155 Could not retrieve directory listing.
. 2025-08-20 15:20:42.164 Retry interval expired, will not retry transfer
< 2025-08-20 15:20:42.171 Script: Lost connection.
< 2025-08-20 15:20:42.171 Timeout detected. (control connection)
< 2025-08-20 15:20:42.171 Could not retrieve directory listing.
< 2025-08-20 15:20:42.171 Error listing directory '/1 xxxxx CLIENTS/xxxxx/Sydney TPA/A-CAP/Client Folders/xxxxxxx'.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
42,328
Location:
Prague, Czechia

Re: Keep disconnecting from FTP

The server just seems to stop responding. I do not know what to suggest.
Did you try another FTP client? Does it work reliably with the server?

Reply with quote

abd1111

Re: Keep disconnecting from FTP

That's kind of what I am feeling. It just abruptly stops without warning. Yes, other ones are hit or miss, too, depending on time of day. Might just be them. I also notice it behave the same on the GUI doing manual transfers.

Reply with quote

Advertisement

You can post new topics in this forum