Verify-server-fingerprint-using-SSH - 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 using SSH
VB code
Dim WithEvents wodSSH1 As wodSSHCom
Private Sub Form_Load()
    Set wodSSH1 = New wodSSHCom
    
    'Set server login, password and hostname.
    wodSSH1.HostName = "your_hostname"
    wodSSH1.Protocol = SSH2
    wodSSH1.Login = "your_login"
    wodSSH1.Password = "your_password"
    'Connect to server.
    wodSSH1.Connect
End Sub

'HostFingerprint Event fires when the remote server provides public key fingerprint information.
Private Sub wodSSH1_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

'Connected Event fires when wodSSH connects to the remote server.
Private Sub wodSSH1_Connected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
    If ErrorCode <> 0 Then
        MsgBox "Connected Error:  " & ErrorText
    Else
        MsgBox "Connected"
    End If
End Sub
VB.NET code
Dim WithEvents wodSSH1 As WeOnlyDo.Client.SSH
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    wodSSH1 = New WeOnlyDo.Client.SSH

    'Authenticate with server using hostname, login, password.
    wodSSH1.Hostname = "your_hostname"
    wodSSH1.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSH2
    wodSSH1.Login = "your_login"
    wodSSH1.Password = "your_password"
    wodSSH1.Connect()
End Sub

'HostFingerprint Event fires when the remote server provides public key fingerprint information.
Private Sub wodSSH1_FingerPrintEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SSH.FingerPrintArgs) Handles wodSSH1.FingerPrintEvent
    'Display server fingerprint value and choice if you want to accept it or not.
    If MsgBox(BitConverter.ToString(Args.FingerPrint).Replace("-", ":"), vbYesNo + vbQuestion, "Do you want to accept server fingerprint?") = vbYes Then
        Args.Accept = True
    Else
        Args.Accept = False
    End If
End Sub

'Connected Event fires when wodSSH connects to the remote server.
Private Sub wodSSH1_ConnectedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SSH.ConnectedArgs) Handles wodSSH1.ConnectedEvent
    If Args.Error IsNot Nothing Then
        MsgBox("Connected Error:  " & Args.Error.Message)
    Else
        MsgBox("Connected")
    End If
End Sub
C# code
WeOnlyDo.Client.SSH wodSSH1;
private void Form1_Load(object sender, EventArgs e)
{
    wodSSH1 = new WeOnlyDo.Client.SSH();
    wodSSH1.FingerPrintEvent += new WeOnlyDo.Client.SSH.FingerPrintDelegate(wodSSH1_FingerPrintEvent);
    wodSSH1.ConnectedEvent += new WeOnlyDo.Client.SSH.ConnectedDelegate(wodSSH1_ConnectedEvent);

    wodSSH1.Hostname = "your_hostname";
    wodSSH1.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSH2;
    wodSSH1.Login = "your_login";
    wodSSH1.Password = "your_password";
    wodSSH1.Connect();
}

//HostFingerprint Event fires when the remote server provides public key fingerprint information.
void wodSSH1_FingerPrintEvent(object Sender, WeOnlyDo.Client.SSH.FingerPrintArgs Args)
{
    //Display server fingerprint value and choice if you want to accept it or not.
    DialogResult result = MessageBox.Show(BitConverter.ToString(Args.FingerPrint).Replace("-",":") , "Do you want to accept server fingerprint?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

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

}

//Connected Event fires when wodSSH connects to the remote server.
void wodSSH1_ConnectedEvent(object Sender, WeOnlyDo.Client.SSH.ConnectedArgs Args)
{
    if (Args.Error != null)
    {
        MessageBox.Show("Connected Error:  " + Args.Error.Message);
    }
    else
    {
        MessageBox.Show("Connected");
    }
}