Sample code for 30+ languages & platforms
PowerBuilder

Monitor FTP Transfer Progress

See more FTP Examples

Demonstrates the progress properties CurBytesReceived, CurBytesReceivedStr, CurBytesSent, CurBytesSentStr, ProgressMonSize, PercentDoneScale, and AutoGetSizeForProgress.

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: Percentage progress needs a known total, but FTP does not always report a file's size up front — so AutoGetSizeForProgress issues a SIZE command before a download, and ProgressMonSize supplies an expected size when even that is unavailable (a one-shot value consumed by the next transfer). PercentDoneScale sets the resolution of progress callbacks. The current byte counts are exposed both as 32-bit integers and as strings, the string forms avoiding integer-width limits for very large transfers.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

li_Success = 0

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

//  AutoGetSizeForProgress sends a SIZE command before a download so percentage-based progress can
//  be computed.
loo_Ftp.AutoGetSizeForProgress = 1

//  PercentDoneScale sets the value representing one hundred percent in PercentDone callbacks.
//  1000 gives tenth-of-a-percent resolution.
loo_Ftp.PercentDoneScale = 1000

//  ProgressMonSize is a one-shot expected size for the next download when the size is not
//  otherwise known.  It is consumed by the next download and reset to 0.
loo_Ftp.ProgressMonSize = 20485760

li_Success = loo_Ftp.GetFile("public_html/bigfile.zip","qa_output/bigfile.zip")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  After a transfer, the current byte counts are available as 32-bit numbers or as strings (the
//  string forms avoid integer-size limits).
Write-Debug "Bytes received: " + string(loo_Ftp.CurBytesReceived)
Write-Debug "Bytes received (str): " + loo_Ftp.CurBytesReceivedStr
Write-Debug "Bytes sent: " + string(loo_Ftp.CurBytesSent)
Write-Debug "Bytes sent (str): " + loo_Ftp.CurBytesSentStr

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



destroy loo_Ftp