Topic "Host key wasn't verified using WinSCP .NET assembly"

Author Message
JustinK
[View user's profile]

Joined: 2012-03-30
Posts: 6
Location: Australia
I used the WinSCP .Net Assemble and wrote a VB script to transfer files.
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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Please, set Session.SessionLogPath and post or email me the log.
_________________
Martin Prikryl
JustinK
[View user's profile]

Joined: 2012-03-30
Posts: 6
Location: Australia
prikryl wrote:
Please, set Session.SessionLogPath and post or email me the log.


Hi
It can't generate the log file because the object didn't open successfully.
The Host Key failed when the object created.
Please refer the code I did modify below.
==============================================

Dim session
Set session = WScript.CreateObject("WinSCP.Session")

' Connect
session.Open sessionOptions
set session.SessionLogPath = "c:\scp.log"
==============================================
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Set the Session.SessionLogFile before calling Session.Open
_________________
Martin Prikryl
JustinK
[View user's profile]

Joined: 2012-03-30
Posts: 6
Location: Australia
prikryl wrote:
Set the Session.SessionLogFile before calling Session.Open


Is it Session.SessionLogFile or SessionLogPath?
I set the SessionLogPath before Session.Open but I got the error "Object required: 'SessionLogPath'"
If I used SessionLogFile, I got error "Object doesn't support this property or method: 'SessionLogFile".

Regards,
Justin
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Sorry, SessionLogPath. Please post an example code that fails.
_________________
Martin Prikryl
JustinK
[View user's profile]

Joined: 2012-03-30
Posts: 6
Location: Australia
prikryl wrote:
Sorry, SessionLogPath. Please post an example code that fails.


My script is as following.


Option Explicit

' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
.Protocol = .Protocol
.HostName = "test.com"
.UserName = "test"
.Password = "password"
.SshHostKey = "ssh-rsa 1023 5b:dd:ff:df:27:8b:06:32:d3:56:94:d1:72:b3:d4:ab"

End With

Dim session
Set session = WScript.CreateObject("WinSCP.Session")

' Connect
set session.SessionLogPath = "c:\scp2.log"
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
I do not know VB much, but I believe you should not use Set to set the SessionLogPath as it is a string, not an object.
Do just:
session.SessionLogPath = "c:\scp2.log"
_________________
Martin Prikryl
JustinK
[View user's profile]

Joined: 2012-03-30
Posts: 6
Location: Australia
prikryl wrote:
I do not know VB much, but I believe you should not use Set to set the SessionLogPath as it is a string, not an object.
Do just:
session.SessionLogPath = "c:\scp2.log"


It didn't resolve my issue. The error is same.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
What error? Please be more specific.
I've tried myself now. Removing the "set" resolved the "Object required: 'SessionLogPath'" error.
_________________
Martin Prikryl
JustinK
[View user's profile]

Joined: 2012-03-30
Posts: 6
Location: Australia
prikryl wrote:
What error? Please be more specific.
I've tried myself now. Removing the "set" resolved the "Object required: 'SessionLogPath'" error.

Hi

Thanks for our help. My problem has been resolved.
The log file can be created now. And the log file shown the finger print is different with the server public key.
the SCP works after I change the finger print.
Thanks a lot.

Justin
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
I have added topic to the FAQ:
https://winscp.net/eng/docs/faq_hostkey
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