Sample code for 30+ languages & platforms
DataFlex

Enable FTP MODE Z Compression

See more FTP Examples

Demonstrates the Chilkat Ftp2.SetModeZ method, which enables MODE Z compression for subsequent data connections. It takes no arguments. Call it after connecting and only when the HasModeZ property is true.

Background: MODE Z compresses data on the fly (using zlib) as it crosses the wire, which can meaningfully speed up transfers of compressible content — text, HTML, logs — over a slow link. It is a server extension, so check HasModeZ first and expect it to be unavailable on many servers. There is little benefit for already-compressed data such as images or archives, where the CPU cost of compression buys almost nothing.

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.SetModeZ method, which enables MODE Z compression for subsequent data
    //  connections.  It takes no arguments.  Call it after connecting, and only when the HasModeZ
    //  property indicates the server supports it.

    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

    //  Only enable compression if the server advertises MODE Z support.
    Get ComHasModeZ Of hoFtp To bTemp1
    If (bTemp1) Begin
        Get ComSetModeZ Of hoFtp To iSuccess
        If (iSuccess = False) Begin
            Get ComLastErrorText Of hoFtp To sTemp1
            Showln sTemp1
            Procedure_Return
        End

        Showln "MODE Z compression enabled."
    End
    Else Begin
        Showln "The server does not support MODE Z."
    End

    //  Subsequent uploads, downloads, and listings are transferred compressed.

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



End_Procedure