using Private key in Powershell

Advertisement

ruban chandar
Joined:
Posts:
2
Location:
India

using Private key in Powershell

Hi,
I am using .Net assembly with powershell commands, i am moving the files from server to local folder, everything is working fine, however i have some issue with the authentication, i want to use my Private key instead of using public key fingerprint, this worked fine in command scripting, but in powershell i get the error message. "SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.HostKey is not set." The code works when i mention the public key finger print, Below is the sample code, can anyone post any example to just use Private key location.



$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "host.net"
$sessionOptions.UserName = "userName"
$sessionOptions.SshPrivateKeyPath="D:\PrivateKey.ppk"


$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"


$session = New-Object WinSCP.Session
$session.ExecutablePath = "C:\Program Files (x86)\WinSCP\winscp.exe"
try
{
$session.Open($sessionOptions)
#all the file transfer operations
}

Reply with quote

Advertisement

You can post new topics in this forum