Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Guest KarstenWagnerBang

Dooohh - I feel stupid now.

What happened:
1: :D I added session logging.
2: :shock: I was puzzled as the host key was exactly the same key as for my other host.
3: :oops: 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
martin

Re: Problems with .NET SFTP connection and Host Key

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.
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
Guest KarstenWagnerBang

Problems with .NET SFTP connection and Host Key

Hi

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
$session.Open($sessionOptions)

# 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
$transferResult.Check()
}
finally {
# Disconnect, clean up
$session.Dispose()
}
------------------------

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?