Sample code for 30+ languages & platforms
DataFlex

FTP Upload / Download to StringBuilder

Demonstrate how to upload from a Chilkat StringBuilder object, and download into a StringBuilder object.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    Variant vSbA
    Handle hoSbA
    Boolean iBIncludeBOM
    String sRemoteFilename
    Variant vSbB
    Handle hoSbB
    Boolean iBCaseSensitive
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    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.my-ftp-server.com"
    Set ComUsername Of hoFtp To "mFtpLogin"
    Set ComPassword Of hoFtp To "myFtpPassword"

    // Connect to the FTP server.
    Get ComConnectOnly Of hoFtp To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Authenticate with the FTP server.
    Get ComLoginAfterConnectOnly Of hoFtp To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbA
    If (Not(IsComObjectCreated(hoSbA))) Begin
        Send CreateComObject of hoSbA
    End
    Get ComLoadFile Of hoSbA "qa_data/hamlet.xml" "utf-8" To iSuccess

    // Upload the contents of sbA to the FTP server.
    Move False To iBIncludeBOM
    Move "hamletFromSb.xml" To sRemoteFilename
    Get pvComObject of hoSbA to vSbA
    Get ComPutFileSb Of hoFtp vSbA "utf-8" iBIncludeBOM sRemoteFilename To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Download...
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbB
    If (Not(IsComObjectCreated(hoSbB))) Begin
        Send CreateComObject of hoSbB
    End
    Get pvComObject of hoSbB to vSbB
    Get ComGetFileSb Of hoFtp sRemoteFilename "utf-8" vSbB To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Verify that sbA and sbB have the exact same contents.
    Get ComLength Of hoSbA To iTemp1
    Showln "size of sbA: " iTemp1
    Move True To iBCaseSensitive
    Get ComContentsEqualSb Of hoSbA     Get pvComObject of hoSbB to vSbB
vSbB iBCaseSensitive To bTemp1
    If (bTemp1 = True) Begin
        Showln "Contents are equal. Success."
    End
    Else Begin
        Showln "Contents are NOT equal.  Failed."
    End

    Get ComDisconnect Of hoFtp To iSuccess


End_Procedure