Sample code for 30+ languages & platforms
DataFlex

FTP Connect, Examine Server Certificate, and then Authenticate

See more FTP Examples

Demonstrates how to connect to an FTP server, examine the server's SSL/TLS certificate, and then, if it meets the application's security requirements, proceed to authenticate.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    Variant vServerCert
    Handle hoServerCert
    String sTemp1

    Move False To iSuccess

    // This example assumes Chilkat Ftp2 to have been previously unlocked.
    // See Unlock Ftp2 for sample code.

    Get Create (RefClass(cComChilkatFtp2)) To hoFtp
    If (Not(IsComObjectCreated(hoFtp))) Begin
        Send CreateComObject of hoFtp
    End

    Set ComHostname Of hoFtp To "www.authtls-ftps-server.com"
    Set ComUsername Of hoFtp To "FTP_LOGIN"
    Set ComPassword Of hoFtp To "FTP_PASSWORD"
    Set ComAuthTls Of hoFtp To True
    Set ComPort Of hoFtp To 21

    // Connect to the FTP server using explicit TLS (AUTH TLS).
    Get ComConnectOnly Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Get the FTP server's certificate.
    Get Create (RefClass(cComChilkatCert)) To hoServerCert
    If (Not(IsComObjectCreated(hoServerCert))) Begin
        Send CreateComObject of hoServerCert
    End
    Get pvComObject of hoServerCert to vServerCert
    Get ComGetServerCert Of hoFtp vServerCert To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Now that we have the certificate, we can check it in any way we desire.
    // (See the online reference documentation for the certificate object's methods
    // and properties)...

    // Assuming the certificate is OK, proceed to authenticate with the FTP server.
    Get ComLoginAfterConnectOnly Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // 
    // Proceed with uploading/download files, etc...
    // 

    Get ComDisconnect Of hoFtp To iSuccess
    Showln "Success."


End_Procedure