DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFtp
String sTemp1
Integer iTemp1
Move False To iSuccess
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
// AutoGetSizeForProgress sends a SIZE command before a download so percentage-based progress can
// be computed.
Set ComAutoGetSizeForProgress Of hoFtp To True
// PercentDoneScale sets the value representing one hundred percent in PercentDone callbacks.
// 1000 gives tenth-of-a-percent resolution.
Set ComPercentDoneScale Of hoFtp To 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.
Set ComProgressMonSize Of hoFtp To 20485760
Get ComGetFile Of hoFtp "public_html/bigfile.zip" "qa_output/bigfile.zip" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
// After a transfer, the current byte counts are available as 32-bit numbers or as strings (the
// string forms avoid integer-size limits).
Get ComCurBytesReceived Of hoFtp To iTemp1
Showln "Bytes received: " iTemp1
Get ComCurBytesReceivedStr Of hoFtp To sTemp1
Showln "Bytes received (str): " sTemp1
Get ComCurBytesSent Of hoFtp To iTemp1
Showln "Bytes sent: " iTemp1
Get ComCurBytesSentStr Of hoFtp To sTemp1
Showln "Bytes sent (str): " sTemp1
Get ComDisconnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure