Sample code for 30+ languages & platforms
DataFlex

Set the FTP Transfer Type to Binary

See more FTP Examples

Demonstrates the Chilkat Ftp2.SetTypeBinary method, which sets the FTP representation type to binary (TYPE I) for subsequent transfers. It takes no arguments.

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: Binary mode transfers bytes verbatim and is the correct choice for essentially every file, text included. Chilkat already defaults to binary, so no call is needed to use it — this method exists to switch back explicitly after a prior SetTypeAscii. The alternative ASCII mode applies line-ending translation that corrupts binary files, so binary is the safe default to keep in place.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Ftp2.SetTypeBinary method, which sets the FTP representation type to binary
    //  (TYPE I) for subsequent transfers.  It takes no arguments.

    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

    //  Binary mode preserves file bytes exactly and is the appropriate choice for nearly all modern
    //  file types, text included.  Chilkat already defaults to binary, so this call is only needed to
    //  switch back after a prior SetTypeAscii.
    Get ComSetTypeBinary 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/archive.zip" "qa_output/archive.zip" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

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



End_Procedure