PowerShell: Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed"

Advertisement

Zeppelins2
Joined:
Posts:
2
Location:
USA

PowerShell: Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed"

Entire Error:
Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0."
This works fine within WinSCP. Below is the PowerShell script that is experiencing this issue;
# Load WinSCP .NET assembly
Add-Type -Path "C:\<concealed local path>\WinSCPnet.dll"
 
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "<concealed hostname>"
    UserName = "<concealed username>"
    Password = "<concealed password>"
    SshHostKeyFingerprint = "ssh-rsa 3072 <concealed fingerprint>"
}
 
$session = New-Object WinSCP.Session
 
try
{
    # Connect
    $session.Open($sessionOptions)
 
    # Transfer files
    $session.GetFiles("/*", "\\<concealed UNC path>\*").Check()
}
finally
{
    $session.Dispose()
}

Reply with quote

Advertisement

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

Re: Powershell: Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed"

Please attach session log files both from the PowerShell code and WinSCP GUI.

Reply with quote

Zeppelins2

Re: Powershell: Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed"

Hello Martin, how would I go about getting the PowerShell info, and would posting this information reveal sensitive information? Can I instead email it directly?

Reply with quote

martin
Site Admin
martin avatar

Re: Powershell: Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed"

Use Session.SessionLogPath. You can mark the logs as private attachments when posting them.

Reply with quote

Advertisement

You can post new topics in this forum