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

JustinK

Re: Host key wasn't verified using WinSCP .NET assembly

martin 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

Re: Host key wasn't verified using WinSCP .NET assembly

What error? Please be more specific.
I've tried myself now. Removing the "set" resolved the "Object required: 'SessionLogPath'" error.
JustinK

Re: Host key wasn't verified using WinSCP .NET assembly

martin 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

Re: Host key wasn't verified using WinSCP .NET assembly

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"
JustinK

Re: Host key wasn't verified using WinSCP .NET assembly

martin 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

Re: Host key wasn't verified using WinSCP .NET assembly

Sorry, SessionLogPath. Please post an example code that fails.
JustinK

Re: Host key wasn't verified using WinSCP .NET assembly

martin 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

Re: Host key wasn't verified using WinSCP .NET assembly

Set the Session.SessionLogFile before calling Session.Open
JustinK

Re: Host key wasn't verified using WinSCP .NET assembly

martin 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

Re: Host key wasn't verified using WinSCP .NET assembly

Please, set Session.SessionLogPath and post or email me the log.
JustinK

Host key wasn't verified using WinSCP .NET assembly

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