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?
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?