Sample code for 30+ languages & platforms
DataFlex

Create an FTP Upload Plan

See more FTP Examples

Demonstrates the Chilkat Ftp2.CreatePlan method, which creates and returns a textual upload plan for a local directory. The only argument is the local directory. The object must be connected, because the plan records the current absolute remote directory together with the local source paths.

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 plan is a saved, resumable description of an upload — the list of local files and their absolute remote destinations — computed once and executed later (or on another run) with PutPlan. Separating planning from execution suits large or unreliable transfers: the plan can be reviewed, stored, and re-run, and because it records absolute remote paths it stays correct even if the working directory later changes.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sPlan
    Handle hoSbPlan
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Demonstrates the Ftp2.CreatePlan method, which creates and returns a textual upload plan for a
    //  local directory.  The only argument is the local directory.  The object must be connected,
    //  because the plan records the current absolute remote directory.

    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"

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

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

    //  The plan captures which local files to upload and the absolute remote destination.  Save it so
    //  the upload can be run (or resumed) later with PutPlan.
    Get ComCreatePlan Of hoFtp "qa_data/site" To sPlan
    Get ComLastMethodSuccess Of hoFtp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Persist the plan text for later use.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPlan
    If (Not(IsComObjectCreated(hoSbPlan))) Begin
        Send CreateComObject of hoSbPlan
    End
    Get ComAppend Of hoSbPlan sPlan To iSuccess
    Get ComWriteFile Of hoSbPlan "qa_output/upload_plan.txt" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSbPlan To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Upload plan created."

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



End_Procedure