[SOLVED] - Ignore password promt when useing Private/Publik Keys?
Hi,
I'm trying to get my Powershell script to login and upload som files on a FTP server. It works great with Putty/psftp.exe.
The connection is SFTP with a username, a Key-file that has a passphrase on it and no password.
But I can't get it to work with WinSCP .Net or the Powershell module.
This gets me a login promt at $session:
and with this:
I get this error message:
Any idea?
I'm trying to get my Powershell script to login and upload som files on a FTP server. It works great with Putty/psftp.exe.
The connection is SFTP with a username, a Key-file that has a passphrase on it and no password.
But I can't get it to work with WinSCP .Net or the Powershell module.
This gets me a login promt at $session:
$sshKeyFinger = "ssh-rsa 2048 xx:cc:vv:bb" $sshKeyPath = "\\UNC\Path\to\Key.ppk" $sshpw = ConvertTo-SecureString "Password" -AsPlainText -Force $session = New-WinSCPSession -HostName Username@host.com -SshPrivateKeyPath $sshKeyPath -SshPrivateKeySecurePassphrase $sshpw -SshHostKeyFingerprint $sshKeyFinger Send-WinSCPItem -Path \\local\unc\path\* -WinSCPSession $session -Destination /transfer Remove-WinSCPSession -WinSCPSession $session
and with this:
# Load WinSCP .NET assembly Add-Type -Path "WinSCPnet.dll" # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "Host" UserName = "UserName" Password = "SSHKey_Passphrase" SshHostKeyFingerprint = "ssh-rsa 2048 xx:cc:vv:bb" SshPrivateKeyPath = "\\UNC\Path\to\Key.ppk" } $sessionOptions.AddRawSettings("AuthKI", "0") $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # Your code $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary $transferResult = $session.PutFiles("\\Local\UNC\Path\*", "/transfer", $False, $transferOptions) # Throw on any error $transferResult.Check() # Print results foreach ($transfer in $transferResult.Transfers) { Write-Host ("Upload of {0} succeeded" -f $transfer.FileName) } } finally { # Disconnect, clean up $session.Dispose() }
I get this error message:
Exception calling "Open" with "1" argument(s): "Connection has been unexpectedly closed. Server sent command exit status 0. Authentication log (see session log for details): Using username "Username". Authenticating with public key "rsa-key-". Authentication failed." At line:20 char:5 + $session.Open($sessionOptions) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SessionRemoteException
Any idea?
Last edited by Muffinz on 2016-12-27 10:47; edited 1 time in total