Topic "using Private key in Powershell"

Author Message
ruban chandar
[View user's profile]

Joined: 2014-06-19
Posts: 2
Location: India
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
}
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
You always have to specify host key fingerprint. This has nothing to do with private key (i.e. is not an alternative to).
See https://winscp.net/eng/docs/ssh_verifying_the_host_key
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License