Topic "Problems with .NET SFTP connection and Host Key"

Author Message
Guest KarstenWagnerBang



Problem: When I try to log on autocratically using the dll I get the following error message: "Host key wasn't verified!". Manual log on works perfect.

What I've done:

Manually connected to the server and copied the key from Server/Protocol Information.

Written the following powershell script:
$sftp_site = @{"HOST" = "X.X.X.X"; "LOCATION" = "/Elev/"; "USER" = "YYYY"; "PASSWORD" = "ZZZZ"; "PRIVATEKEYPATH" = "mykey.ppk"; "HOSTKEY" = "ssh-dss 1024 bf:1f:9c:5d:92:a5:dd:2d:b1:ce:e6:c1:20:73:32:71"}

# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom($winscp_path) | Out-Null

# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $sftp_site["HOST"]
$sessionOptions.UserName = $sftp_site["USER"]
$sessionOptions.Password = $sftp_site["PASSWORD"]
$sessionOptions.SshHostKeyFingerprint = $sftp_site["HOSTKEY"]

$session = New-Object WinSCP.Session

try {
# Connect

# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary

$transferResult = $session.PutFiles($work_directory + "*", $sftp_site["LOCATION"], $FALSE, $transferOptions)

# Throw on any error
finally {
# Disconnect, clean up

If I change the host key to an invalid value (deleting the last letter) I get an Regular Expression error - which shows that the Host key is being read.

What can I do to debug the problem?
Guest KarstenWagnerBang


After I read my post I can see I didn't use that much text.

If anyone would like to help but do not have enough information, please write and I'll try to gather all necessary information.

/Karsten Wagner Bang
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24552
Location: Prague, Czechia
You are most likely using from wrong key fingerprint.
Please set Session.SessionLogPath and check the fingerprints there. Attach the log here, if it does not help.

Last edited by martin on 2012-10-15; edited 1 time in total
Guest KarstenWagnerBang


Dooohh - I feel stupid now.

What happened:
1: Very Happy I added session logging.
2: Shocked I was puzzled as the host key was exactly the same key as for my other host.
3: Embarassed I realized I'd been testing the script against the wrong IP - feeling quite stupid now.

Sorry for your trouble, and thanks for your help.
/Karsten Wagner Bang

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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License