Verify-server-fingerprint - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Verify server fingerprint
VB code
Dim WithEvents wodSSHTunnel1 As wodTunnelCom
Private Sub Form_Load()
    Set wodSSHTunnel1 = New wodTunnelCom

    'Authenticate with SSH server using hostname, login, password.
    wodSSHTunnel1.HostName = "your_hostname"
    wodSSHTunnel1.Login = "your_login"
    wodSSHTunnel1.Password = "your_password"
    wodSSHTunnel1.Connect
End Sub

'HostFingerprint Event fires when the remote server provides public key fingerprint information.
Private Sub wodSSHTunnel1_HostFingerprint(ByVal Fingerprint As String, Accept As Boolean)
    'Display server fingerprint value and choice if you want to accept it or not.
    If MsgBox(Fingerprint, vbYesNo + vbQuestion, "Do you want to accept server fingerprint?") = vbYes Then
        Accept = True
    Else
        Accept = False
    End If
End Sub

'Disconnected Event fires when wodSSHTunnel disconnects from the server.
Private Sub wodSSHTunnel1_Disconnected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
    If ErrorCode <> 0 Then
        MsgBox "DISCONNECTED: " & ErrorText 'Connection error is received here
    End If
End Sub
VB.NET code
Dim WithEvents wodSSHTunnel1 As wodSSHTunnelCOMLib.wodTunnelCom
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    wodSSHTunnel1 = New wodSSHTunnelCOMLib.wodTunnelCom

    'Authenticate with SSH server using hostname, login, password.
    wodSSHTunnel1.Hostname = "your_hostname"
    wodSSHTunnel1.Login = "your_login"
    wodSSHTunnel1.Password = "your_password"
    wodSSHTunnel1.Connect()
End Sub

'HostFingerprint Event fires when the remote server provides public key fingerprint information.
Private Sub wodSSHTunnel1_HostFingerprint(ByVal Fingerprint As String, ByRef Accept As Boolean) Handles wodSSHTunnel1.HostFingerprint
    'Display server fingerprint value and choice if you want to accept it or not.
    If MsgBox(Fingerprint, vbYesNo + vbQuestion, "Do you want to accept server fingerprint?") = vbYes Then
        Accept = True
    Else
        Accept = False
    End If
End Sub

'Disconnected Event fires when wodSSHTunnel disconnects from the server.
Private Sub wodSSHTunnel1_Disconnected(ByVal ErrorCode As Short, ByVal ErrorText As String) Handles wodSSHTunnel1.Disconnected
    If ErrorCode <> 0 Then
        MsgBox("DISCONNECTED: " & ErrorText) 'Connection error is received here
    End If
End Sub
C# code
wodSSHTunnelCOMLib.wodTunnelCom wodSSHTunnel1;
private void Form1_Load(System.Object sender, System.EventArgs e)
{
    wodSSHTunnel1 = new wodSSHTunnelCOMLib.wodTunnelCom();
    wodSSHTunnel1.HostFingerprint += new wodSSHTunnelCOMLib._IwodTunnelComEvents_HostFingerprintEventHandler(wodSSHTunnel1_HostFingerprint);
    wodSSHTunnel1.Disconnected += new wodSSHTunnelCOMLib._IwodTunnelComEvents_DisconnectedEventHandler(wodSSHTunnel1_Disconnected);


    //Authenticate with SSH server using hostname, login, password.
    wodSSHTunnel1.Hostname = "your_hostname";
    wodSSHTunnel1.Login = "your_login";
    wodSSHTunnel1.Password = "your_password";
    wodSSHTunnel1.Connect(wodSSHTunnel1.Hostname, wodSSHTunnel1.Port, wodSSHTunnel1.Protocol);
}

//HostFingerprint Event fires when the remote server provides public key fingerprint information.
void wodSSHTunnel1_HostFingerprint(string Fingerprint, ref bool Accept)
{
    //Display server fingerprint value and choice if you want to accept it or not.
    DialogResult result = MessageBox.Show(Fingerprint, "Do you want to accept server fingerprint?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

    if (result == DialogResult.Yes)
    {
        Accept = true;
    }
    else if (result == DialogResult.No)
    {
        Accept = false;
    }
}

//Disconnected Event fires when wodSSHTunnel disconnects from the server.
private void wodSSHTunnel1_Disconnected(short ErrorCode, string ErrorText)
{
    if (ErrorCode != 0)
    {
        MessageBox.Show("DISCONNECTED: " + ErrorText); //Connection error is received here
    }
}