Host key wasn't verified using WinSCP .NET assembly
However, I got a error message "Host key wasn't verified!".
My script is as following.
I have added the public key on remote server.
And the host key in the script is the finger print of the private key.
The finger print is same between private key and public key.
There is no problem if I use WinSCP GUI to connect to the remote server.
Could anyone help me to fix the issue?
Option Explicit
' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
.HostName = "test.com"
.UserName = "test"
.Password = "password"
.SshHostKey = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
End With
Dim session
Set session = WScript.CreateObject("WinSCP.Session")
' Connect
session.Open sessionOptions
' Upload files
Dim transferOptions
Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions")
'transferOptions.TransferMode = TransferMode.Binary
Dim transferResult
Set transferResult = session.PutFiles("c:\data\mylogfile.txt", ".", False, transferOptions)
' Throw on any error
transferResult.Check
' Print results
Dim transfer
For Each transfer In transferResult.Transfers
WScript.Echo "Upload of " & transfer.FileName & " succeeded"
Next
' Disconnect, clean up
session.Dispose