Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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.
RafaelDBA

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

follows the log attachment
martin

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.
RafaelDBA

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
}