tomohulk / WinSCP

WinSCP PowerShell Wrapper Module
GNU General Public License v3.0
151 stars 29 forks source link

Sftp without a password #162

Open ChrisV-Newsday opened 2 days ago

ChrisV-Newsday commented 2 days ago

Issue Description

I have a SFTP connection that does not have a password. It uses a Private Key / User name combo. It works in the WinSCP Client but when I try to open a New-WinSCPSession and setting the New-WinSCPSessionOption's I either get prompted for a password if use "-Credential $userName" or if I leave -Credential out I get the error below

Example

$session = New-WinSCPSession -SessionOption (New-WinSCPSessionOption -HostName $MBNY_SERVER -PortNumber 22 -Protocol Sftp -SshHostKeyFingerprint $Fingerprint -SshPrivateKeyPath $privateKey)

Expected Output

Hoping for a successful connection

Actual Output

Exception calling "Open" with "1" argument(s): "Authentication failed. Authentication log (see session log for details): Using username
| "anonymous". Server refused our key. Access denied. Authentication failed."

WinSCP-PowerShell Version

WinSCP v. 6.3.4

Environment

Windows 10 PowerShell v. 7.4.1 WinSCP v. 6.3.4

tomohulk commented 2 days ago

It still needs to be a [PSCredential] object, even if the password is blank:

$mycreds = New-Object System.Management.Automation.PSCredential("username", (new-object System.Security.SecureString))

$sessionOptions = New-WinSCPSessionOption -Credential $mycreds
ChrisV-Newsday commented 1 day ago

Thanks. That worked like a charm!