Verify-Server-Certificate-in-FTPS-Protocol - 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 Certificate in FTPS Protocol
VB code
Dim WithEvents wodFtpDLX As wodFtpDLXCom
Private Sub Form_Load()
    Set wodFtpDLX = New wodFtpDLXCom
    
    wodFtpDLX.HostName = "xx"
    wodFtpDLX.Login = "xx"
    wodFtpDLX.Password = "xx"
    wodFtpDLX.Protocol = FTPSwithdata
    
    wodFtpDLX.Connect
    
End Sub

Private Sub wodFtpDLX_Connected(ByVal ErrorCode As Long, ByVal ErrorText As String)
    If ErrorCode <> 0 Then
        MsgBox ErrorText
    Else
        MsgBox "Connected to server."
    End If
End Sub

Private Sub wodFtpDLX_HostCertificate(ByVal Cert As wodFtpDLXComLib.ICertificate, ByVal ErrorCode As Long, ByVal ErrorText As String, Accept As Boolean)
    If MsgBox("Do you accept server certificate?" & vbCrLf & "Certificate issued to: " & Cert.CommonName, vbYesNo) = vbYes Then
        Accept = True
    Else
        Accept = False
    End If
End Sub
C# code
private WeOnlyDo.Client.FtpDLX wodFtpDLX;
private void Form1_Load(object sender, EventArgs e)
{
    wodFtpDLX = new WeOnlyDo.Client.FtpDLX();
    wodFtpDLX.HostCertificateEvent += new WeOnlyDo.Client.FtpDLX.HostCertificateDelegate(wodFtpDLX_HostCertificateEvent);
    wodFtpDLX.ConnectedEvent += new WeOnlyDo.Client.FtpDLX.ConnectedDelegate(wodFtpDLX_ConnectedEvent);

    wodFtpDLX.Hostname = "xx";
    wodFtpDLX.Login = "xx";
    wodFtpDLX.Password = "xx";
    wodFtpDLX.Protocol = WeOnlyDo.Client.Protocols.FTPS;

    // It's time to connect to server. All we now need to do is call Connect method.
    wodFtpDLX.Connect();

}

void wodFtpDLX_ConnectedEvent(object Sender, WeOnlyDo.Client.FtpConnectedArgs Args)
{
    if (Args.Error != null)
    {
        MessageBox.Show(Args.Error.Message);
    }
    else
    {
        MessageBox.Show("Connected to server.");
    }           
}

void wodFtpDLX_HostCertificateEvent(object Sender, WeOnlyDo.Client.HostCertificateArgs Args)
{
    if(MessageBox.Show("Do you wish to accept this certificate: " + Environment.NewLine + Args.Certificate.Issuer, "Accept Certificate?",MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        Args.Accept = true;
    }
    else
    {
        Args.Accept = false;
    }
}
VB.NET code
Dim WithEvents wodFtpDLX As WeOnlyDo.Client.FtpDLX
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    wodFtpDLX = New WeOnlyDo.Client.FtpDLX

    wodFtpDLX.Hostname = "xx"
    wodFtpDLX.Login = "xx"
    wodFtpDLX.Password = "xx"
    wodFtpDLX.Protocol = WeOnlyDo.Client.Protocols.FTPS

    wodFtpDLX.Connect()

End Sub

Private Sub wodFtpDLX_ConnectedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.FtpConnectedArgs) Handles wodFtpDLX.ConnectedEvent
    If (Args Is Nothing) Then
        MsgBox(Args.Error.Message)
    Else
        MsgBox("Connected to server.")
    End If
End Sub

Private Sub wodFtpDLX_HostCertificateEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.HostCertificateArgs) Handles wodFtpDLX.HostCertificateEvent
    If (MsgBox("Do you wish to accept this certificate: " & Environment.NewLine & Args.Certificate.Issuer, MsgBoxStyle.YesNo)) = MsgBoxResult.Yes Then
        Args.Accept = True
    Else
        Args.Accept = False
    End If
End Sub