This project is read-only.

RemoteCertificateChainErrors

Nov 17, 2011 at 2:16 PM

I am trying to connect to an AUTH SSL FTPS server and when I try to connect I get the following error.

There were errors validating the SSL certificate RemoteCertificateNameMismatch RemoteCertificateChainErrors

Here is the code I am using to try to make a connection,

Dim FTPS As New FtpClient.FtpClient("User", "Pass", "hostname", 123)

        Try
            FTPS.SslMode = FtpClient.FtpSslMode.Explicit
            FTPS.Connect()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

When I check the connection state after this error is encountered it returns True, but when I try to set the working directory I get the following error.

Command CWD / not accepted during connected

Here is the code that is checking the connection and trying to change the working directory:

  If FTPS.Connected Then
            Try
                MsgBox("We are connected")
                FTPS.SetWorkingDirectory("/")
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                FTPS.Disconnect()
                MsgBox("got here")
            End Try           
  Else
            MsgBox("NOT connected")
  End If

I know I am missing something  ( i.e.. handling some type of event for the certificate error ), but not sure where to start.  Any help would be appreciated.

Thank you,

Coordinator
Nov 17, 2011 at 3:32 PM

Hey,

Handle the InvalidCertificate event of the FTPS object. The event args has an Ignore property, set it to true and this should stop the exception from being thrown when there are errors validating the certificate. Just so you know there have been issues reported with certain versions of ProFTPD on ubuntu 9.04 (I think, check the forums for the specific version) that are due to bugs in the server software, not the client, however I don't think this exception is related to the problem. Just wanted to point it out.

Thanks,

J.P.

Nov 17, 2011 at 7:16 PM

Handling that event and setting Ignore property to true did the trick.

I also had to move the second part of my code that is doing the work to the ready ConnectionReady event.

You were right Ubuntu 9.04 issues did not apply in my case.

Thank you very much for this project and for the quick response to my problem.

This is going to work perfectly for the internal project I am working on. 

Saved me from doing some really sketchy code to try and use an external app to do what I needed.

Again,

Thank you

 

 

Coordinator
Nov 17, 2011 at 7:34 PM

Not a problem, glad I could help out.

Nov 17, 2011 at 7:49 PM

For someone else that is trying to get this to work with vb.net,

Global Declaration :

Private WithEvents FTPS As FtpClient.FtpClient

Button click event which starts the connection :

Private Sub butConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butConnect.Click
        Debug.Print("FTPS -- Trying to Connect")
        FTPS = New FtpClient.FtpClient("User","Pass","HostName", 22)
        Try
            FTPS.SslMode = FtpClient.FtpSslMode.Explicit
            FTPS.Connect()
        Catch ex As Exception
            Debug.Print("FTPS -- Error : " & ex.Message)
            MsgBox("FTPS -- Error : " & ex.Message)
        End Try
End Sub

Handle InvalidCertificateInfo Event :
Private Sub FTPS_InvalidCertificateInfo(ByVal c As FtpClient.FtpChannel, ByVal e As FtpClient.InvalidCertificateInfo) Handles FTPS.InvalidCertificate
       e.Ignore = True
       Debug.Print("FTPS -- Ignore Invalid Certificate Info Error")
End Sub

Handle ConnectionReady Event and get directory listing :
Private Sub FTPS_ConnectionReady(ByVal c As FtpClient.FtpChannel) Handles FTPS.ConnectionReady
        Debug.Print("FTPS -- Connection Ready")
        If FTPS.Connected Then
            Debug.Print("FTPS -- Connected : Running Commands")
            Try
                FTPS.SetWorkingDirectory("/TargetDirectory/")
                Dim FtpsItems As FtpClient.FtpListItem()
                Dim FtpItem As FtpClient.FtpListItem
                FtpsItems = FTPS.GetListing()
                Dim strItems As String = ""
                For Each FtpItem In FtpsItems
                    strItems = strItems & FtpItem.Name & " " & FtpItem.Type & " " & FtpItem.Modify & vbCrLf
                Next
                MsgBox(strItems)
            Catch ex As Exception
                Debug.Print("FTPS -- Error : " & ex.Message)
            Finally
                FTPS.Disconnect()
  End Try Else Debug.Print("FTPS -- NOT Connected : Could NOT Run Commands") End If End Sub