Topic "error: Host key not verified."

Author Message
masterdineen
[View user's profile]

Joined: 2013-02-13
Posts: 4
Location: Loughton, Essex
Hello there.

I am trying to download files to local folder with the below script.

But i keep getting "error Host key wasn't verified"

The host key has a password attached to it, i dont know if you have to define the HostKey password in the code. I can log onto the FTP via WinSCP using the Pageant,


can someone point me in the right direction please.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Globalization
Imports System.IO
Imports WinSCP


<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSE xecResult.Success''has space to get round the word s e x
Failure = Microsoft.SqlServer.Dts.Runtime.DTSE xecResult.Failure''Success''has space to get round the word s e x

End Enum




Public Sub Main()
'



Try
' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = "sftp.ftpserver.com"
.UserName = "username"
.Password = "password"
.SshHostKeyFingerprint = "ssh-dss 1024 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
.SshPrivateKeyPath = ("E:\SSIS\private-key.ppk")

End With
Using session As Session = New Session
' Connect
session.ExecutablePath = "C:\Program Files (x86)\WinSCP\WinSCP.exe"
session.Open(sessionOptions)

Dim stamp As String = DateTime.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture)
Dim fileName As String = "LCCCTix_20130212_050002.txt"
Dim remotePath As String = "/d/testfolder/" & fileName
Dim localPath As String = "E:\SSIS\FTPFiles\" & fileName


If session.FileExists(remotePath) Then
Dim download As Boolean
If Not File.Exists(localPath) Then
MsgBox(String.Format("File {0} exists, local backup {1} does not", remotePath, localPath))
download = True
Else
Dim remoteWriteTime As DateTime = session.GetFileInfo(remotePath).LastWriteTime
Dim localWriteTime As DateTime = File.GetLastWriteTime(localPath)

If remoteWriteTime > localWriteTime Then
MsgBox( _
String.Format("File {0} as well as local backup {1} exist, " & _
"but remote file is newer ({2}) than local backup ({3})", _
remotePath, localPath))
download = True
Else
Console.WriteLine( _
String.Format("File {0} as well as local backup {1} exist, " & _
"but remote file is not newer ({2}) than local backup ({3})", _
remotePath, localPath, remoteWriteTime, localWriteTime))
download = False
End If
End If

If download Then
' Download the file and throw on any error
session.GetFiles(remotePath, localPath).Check()

MsgBox("Download to backup done.")
End If
Else
MsgBox(String.Format("File {0} does not exist yet", remotePath))
End If
End Using

Catch e As Exception
MsgBox(String.Format("Error: {0}", e.Message))

End Try

End Sub




End Class
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Can you include a complate error message or even better a debug log file? (Session.DebugLogPath)
masterdineen
[View user's profile]

Joined: 2013-02-13
Posts: 4
Location: Loughton, Essex
prikryl wrote:
Can you include a complate error message or even better a debug log file? (Session.DebugLogPath)


where would i insert the debuglogpath, sorry very new to vb
rke002
[View user's profile]

Joined: 2012-12-19
Posts: 9
session.DebugLogPath = "MyDebugPath"

this should work. And dont forget to set the path!
masterdineen
[View user's profile]

Joined: 2013-02-13
Posts: 4
Location: Loughton, Essex
when i define a debug path, will that just save txt or xml file automatically.

Regards

Rob
masterdineen
[View user's profile]

Joined: 2013-02-13
Posts: 4
Location: Loughton, Essex
hiya, sorry to waste your time,

i was was using an incorrect Host key.

thank you for your time.

Have a good weekend
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