PowerShell: Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed"
Entire Error:
This works fine within WinSCP. Below is the PowerShell script that is experiencing this issue;Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0."
# 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() }