Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
set ftp [new_CkFtp2]
CkFtp2_put_Hostname $ftp "ftp.example.com"
CkFtp2_put_Username $ftp "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.
CkFtp2_put_Password $ftp "myPassword"
set success [CkFtp2_Connect $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# AutoGetSizeForProgress sends a SIZE command before a download so percentage-based progress can
# be computed.
CkFtp2_put_AutoGetSizeForProgress $ftp 1
# PercentDoneScale sets the value representing one hundred percent in PercentDone callbacks.
# 1000 gives tenth-of-a-percent resolution.
CkFtp2_put_PercentDoneScale $ftp 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.
CkFtp2_put_ProgressMonSize $ftp 20485760
set success [CkFtp2_GetFile $ftp "public_html/bigfile.zip" "qa_output/bigfile.zip"]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# After a transfer, the current byte counts are available as 32-bit numbers or as strings (the
# string forms avoid integer-size limits).
puts "Bytes received: [CkFtp2_get_CurBytesReceived $ftp]"
puts "Bytes received (str): [CkFtp2_curBytesReceivedStr $ftp]"
puts "Bytes sent: [CkFtp2_get_CurBytesSent $ftp]"
puts "Bytes sent (str): [CkFtp2_curBytesSentStr $ftp]"
set success [CkFtp2_Disconnect $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
delete_CkFtp2 $ftp