Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

li_Success = 0

//  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.

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.Username = "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.
loo_Ftp.Password = "myPassword"

li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

li_Success = loo_Ftp.ChangeRemoteDir("public_html")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Only enable compression if the server advertises MODE Z support.
if loo_Ftp.HasModeZ then
    li_Success = loo_Ftp.SetModeZ()
    if li_Success = 0 then
        Write-Debug loo_Ftp.LastErrorText
        destroy loo_Ftp
        return
    end if

    Write-Debug "MODE Z compression enabled."
else
    Write-Debug "The server does not support MODE Z."
end if

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

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if



destroy loo_Ftp