Sample code for 30+ languages & platforms
VBScript

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

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

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.

set ftp = CreateObject("Chilkat.Ftp2")

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

success = ftp.Connect()
If (success = 0) Then
    outFile.WriteLine(ftp.LastErrorText)
    WScript.Quit
End If

success = ftp.ChangeRemoteDir("public_html")
If (success = 0) Then
    outFile.WriteLine(ftp.LastErrorText)
    WScript.Quit
End If

'  Only enable compression if the server advertises MODE Z support.
If (ftp.HasModeZ) Then
    success = ftp.SetModeZ()
    If (success = 0) Then
        outFile.WriteLine(ftp.LastErrorText)
        WScript.Quit
    End If

    outFile.WriteLine("MODE Z compression enabled.")
Else
    outFile.WriteLine("The server does not support MODE Z.")
End If

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

success = ftp.Disconnect()
If (success = 0) Then
    outFile.WriteLine(ftp.LastErrorText)
    WScript.Quit
End If


outFile.Close