Error: Exception calling "Open" with "1" argument(s): "Connection failed.

Advertisement

RafaelDBA
Joined:
Posts:
2
Location:
Brazil

Error: Exception calling "Open" with "1" argument(s): "Connection failed.

hello, I need a solution to this problem:
Error: Exception calling "Open" with "1" argument(s): "Connection failed.
Timeout detected. (control connection)
Connection failed."
my code:
param (
    $localPath = "C:\TestesWinSCP",
    $remotePath = "/path/files/"
)
 
try
{
    Add-Type -Path "C:\TestesWinSCP\WinSCPnet.dll"
 
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::"FTP"
        HostName = "example.com.br"
        PortNumber = "990"
        UserName = "YYYYYY"
        Password = "********"
    }
 
    $session = New-Object WinSCP.Session
 
    try
    {
        $session.Open($sessionOptions)
        
        $directoryInfo = $session.ListDirectory($remotePath)
       
        $latest =
            $directoryInfo.Files |
            Where-Object { -Not $_.IsDirectory } |
            Sort-Object LastWriteTime -Descending |
            Select-Object -First 1
 
        if ($latest -eq $Null)
        {
            Write-Host "No file found"
            exit 1
        }
        
        $session.GetFiles(
            [WinSCP.RemotePath]::EscapeFileMask($latest.FullName), $localPath).Check()
    }
    finally
    {
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,025
Location:
Prague, Czechia

Re: Error: Exception calling "Open" with "1" argument(s): "Connection failed.

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

RafaelDBA
Joined:
Posts:
2
Location:
Brazil

Error: Exception calling "Open" with "1" argument(s): "Connection failed.

follows the log attachment
  • TEL&COM@sftp.sercom.com.br.log (7.07 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar

Re: Error: Exception calling "Open" with "1" argument(s): "Connection failed.

I've asked for a full log file from your code, not just a log snippet. What does that log is supposed to show us? The log seems to be from an idle GUI session.

Reply with quote

Advertisement

You can post new topics in this forum