Log included - Keep disconnecting from FTP

Advertisement

abd1111
Joined:
Posts:
17

Log included - 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:
17

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

Advertisement

You can post new topics in this forum