Sample code for 30+ languages & platforms
DataFlex

Check if the FTP Control Connection is Open

See more FTP Examples

Demonstrates the Chilkat Ftp2.CheckConnection method, which returns whether Chilkat currently considers the FTP control connection to be open. It takes no arguments and does not require the session to be authenticated.

Background: This reports the object's view of the control-connection state, which is distinct from being logged in — it can return true after ConnectOnly and before authentication. For a stronger liveness check that the server is actually responding, send a Noop, which requires a positive reply. FTP servers commonly drop idle control connections after a timeout, so long-lived sessions should verify before assuming the connection is still usable.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Demonstrates the Ftp2.CheckConnection method, which returns whether Chilkat currently considers
    //  the FTP control connection to be open.  It takes no arguments and does not require the session
    //  to be authenticated.

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

    Set ComHostname Of hoFtp To "ftp.example.com"
    Set ComUsername Of hoFtp To "myFtpLogin"

    //  Normally you would not hard-code the password in source.  You should instead obtain it
    //  from an interactive prompt, environment variable, or a secrets vault.
    Set ComPassword Of hoFtp To "myPassword"

    //  Connect and log in (Connect performs both).
    Get ComConnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Check whether the control connection is still open.
    Get ComCheckConnection Of hoFtp To bTemp1
    If (bTemp1) Begin
        Showln "The control connection is open."
    End
    Else Begin
        Showln "The control connection is not open."
    End

    Get ComDisconnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure