Sample code for 30+ languages & platforms
DataFlex

Monitor, Cancel, and Keep-Alive Long FTP Transfers

See more FTP Examples

Demonstrates the HeartbeatMs, AbortCurrent, and LargeFileMeasures properties, which monitor long operations, allow cancellation, and keep the control connection alive during long transfers.

Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: A large transfer blocks for a long time, and these properties make that manageable. HeartbeatMs fires a periodic AbortCheck callback so an application can show progress and remain responsive, and AbortCurrent — set from that callback or another thread — cancels the running operation. LargeFileMeasures addresses a subtler problem: while data flows on the data connection, an idle control connection can be dropped by a firewall, so this sends a periodic NOOP to keep it alive.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sTemp1

    Move False To iSuccess

    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"

    //  HeartbeatMs sets how often the AbortCheck event fires during long operations.  The default 0
    //  disables it.  A nonzero value lets an application monitor progress and request cancellation.
    Set ComHeartbeatMs Of hoFtp To 100

    //  AbortCurrent may be set to True (typically from another thread, or from an AbortCheck
    //  callback) to cancel a running operation.  Left False here so nothing is pre-emptively aborted.
    Set ComAbortCurrent Of hoFtp To False

    //  LargeFileMeasures (default False) sends a NOOP on the control channel once per minute during
    //  a long transfer, keeping the control connection alive while data flows.
    Set ComLargeFileMeasures Of hoFtp To True

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

    Get ComGetFile Of hoFtp "public_html/hugefile.iso" "qa_output/hugefile.iso" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Transfer complete."

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



End_Procedure