Unicode C
Unicode C
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 Unicode C Downloads
#include <C_CkFtp2W.h>
void ChilkatSample(void)
{
BOOL success;
HCkFtp2W ftp;
success = FALSE;
ftp = CkFtp2W_Create();
CkFtp2W_putHostname(ftp,L"ftp.example.com");
CkFtp2W_putUsername(ftp,L"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.
CkFtp2W_putPassword(ftp,L"myPassword");
success = CkFtp2W_Connect(ftp);
if (success == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
// AutoGetSizeForProgress sends a SIZE command before a download so percentage-based progress can
// be computed.
CkFtp2W_putAutoGetSizeForProgress(ftp,TRUE);
// PercentDoneScale sets the value representing one hundred percent in PercentDone callbacks.
// 1000 gives tenth-of-a-percent resolution.
CkFtp2W_putPercentDoneScale(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.
CkFtp2W_putProgressMonSize(ftp,20485760);
success = CkFtp2W_GetFile(ftp,L"public_html/bigfile.zip",L"qa_output/bigfile.zip");
if (success == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
// After a transfer, the current byte counts are available as 32-bit numbers or as strings (the
// string forms avoid integer-size limits).
wprintf(L"Bytes received: %u\n",CkFtp2W_getCurBytesReceived(ftp));
wprintf(L"Bytes received (str): %s\n",CkFtp2W_curBytesReceivedStr(ftp));
wprintf(L"Bytes sent: %u\n",CkFtp2W_getCurBytesSent(ftp));
wprintf(L"Bytes sent (str): %s\n",CkFtp2W_curBytesSentStr(ftp));
success = CkFtp2W_Disconnect(ftp);
if (success == FALSE) {
wprintf(L"%s\n",CkFtp2W_lastErrorText(ftp));
CkFtp2W_Dispose(ftp);
return;
}
CkFtp2W_Dispose(ftp);
}