error: Host key not verified.

Advertisement

masterdineen
Joined:
Posts:
4
Location:
Loughton, Essex

error: Host key not verified.

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

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: error: Host key not verified.

Can you include a complate error message or even better a debug log file? (Session.DebugLogPath)

Reply with quote

masterdineen
Joined:
Posts:
4
Location:
Loughton, Essex

Re: error: Host key not verified.

martin 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

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum