tomohulk / WinSCP

WinSCP PowerShell Wrapper Module
GNU General Public License v3.0
153 stars 30 forks source link

New-WinSCPSessionOption: SshPrivateKeyPath Parameter Doesn't Escape Network Share Paths Properly #108

Closed jeffreymcclain closed 4 years ago

jeffreymcclain commented 5 years ago

Issue Description

Network Share paths in SshPrivateKeyPath Parameter aren't escaped properly.

Example

$sessionOption = New-WinSCPSessionOption -HostName $sftpHostname -SshPrivateKeyPath 'C:\Temp\test.ppk' echo $sessionOption

$sessionOption = New-WinSCPSessionOption -HostName $sftpHostname -SshPrivateKeyPath '\\cifs01.company.com\EncryptionKeys\test.ppk' echo $sessionOption

Expected Output

SshPrivateKeyPath : C:\Temp\test.ppk SshPrivateKeyPath : \\cifs01.company.com\EncryptionKeys\test.ppk

Actual Output

SshPrivateKeyPath : C:\Temp\test.ppk SshPrivateKeyPath : Microsoft.PowerShell.Core\FileSystem::\\cifs01.company.com\EncryptionKeys\test.ppk

When calling New-WinSCPSession with a network path, it fails with:

New-WinSCPSession : Exception calling "Open" with "1" argument(s): "Disconnected: No supported authentication methods available (server sent: publickey) Authentication log (see session log for details): Unable to use key file "Microsoft.PowerShell.Core\FileSystem::\\cifs01.company.com\EncryptionKeys\test.ppk" (unable to open file) Using username "test". Authentication failed." At C:\Scripts\test.ps1:26 char:12

If I leave everything else identical (including username and password), but copy the .ppk file from the network share to the local machine and specify the local path, then New-WinSCPSession connects as expected (so the issue seems to be with how the network share path is handled).

WinSCP-PowerShell Version

5.15.2.0

Environment

Windows Server 2016 64-bit, connecting to SFTP server with username, private-key file, and private-key passphrase.

dotps1 commented 5 years ago

Please give this version a try if can and let me know if it works. thanks! WinSCP.zip

jeffreymcclain commented 5 years ago

@dotps1 Once I unzip the folder, how do I manually install / import the module for testing?

dotps1 commented 5 years ago

Import-Module -Path

Sent from my iPhone

On Aug 8, 2019, at 12:00 PM, Jeffrey McClain notifications@github.com wrote:



Once I unzip the folder, how do I manually install / import the module for testing?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/dotps1/WinSCP/issues/108?email_source=notifications&email_token=AAHYJJEZ74A3T4SSKDBTVRTQDQ7IVA5CNFSM4IIJDT4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD34CYYI#issuecomment-519580769, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAHYJJHW5DUCFZ6KQ2TUSJTQDQ7IVANCNFSM4IIJDT4A.

jeffreymcclain commented 5 years ago

@dotps1 Just tested and it works!

P.S.:

Import-Module -Path \

For reference, the actual command was "Import-Module -Name \". I also had to Set-ExecutionPolicy to "Unrestricted" and unblock some files after extracting, since they were "downloaded from the internet".