Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
FTP Upload with Progress Monitoring
C++ source code to FTP upload a file. // To get FTP progress monitoring callbacks, declare a C++ class
// that inherits from the CkFtpProgress base class and provide
// implementations for FtpPercentDone and AbortCheck.
class MyFtpProgress : public CkFtpProgress
{
// pctDone is a percent value between 1 and 100.
// FtpPercentDone is called each time pctDone increases.
// The abort argument can be set to cause the FTP to abort while in progress.
void FtpPercentDone(long pctDone, bool *abort)
{
printf("%d Percent Done!\n",pctDone);
// In this example, we will abort the transfer after it is 40% complete.
//if (pctDone >= 40)
//{
//*abort = true;
//}
}
// Called periodically to check to see if the transfer should be aborted.
void AbortCheck(bool *abort)
{
printf("Abort Check!\n");
// Set the *abort argument to true to force a transfer to abort.
// For example:
//*abort = true;
}
};
// Upload a file to an FTP server.
void FtpUpload(void)
{
CkFtp2 ftp;
MyFtpProgress myProgress;
ftp.UnlockComponent("anything for 30-day trial");
ftp.put_Hostname("ftp.chilkatsoft.com");
ftp.put_Username("****");
ftp.put_Password("****");
// non-passive (active) connections are most likely to work if firewalls are present.
ftp.put_Passive(false);
// The HeartbeatMs property controls the frequency of AbortCheck callbacks.
// The default value is 0 (no callbacks). Set it to a reasonable number of milliseconds:
ftp.put_HeartbeatMs(250);
// Set the SendBufferSize to a smaller value than the default of 512K to get more frequent callbacks:
// This may slightly degrade performance.
ftp.put_SendBufferSize(4096);
bool success = ftp.Connect();
if (!success)
{
ftp.SaveLastError("ftpLog.txt");
return;
}
// Call PutFile2 to upload with progress monitoring.
// Call PutFile to upload without progress monitoring.
success = ftp.PutFile2("testUpload.dat","testUpload.dat",myProgress);
if (!success)
{
ftp.SaveLastError("ftpLog.txt");
}
ftp.Disconnect();
|
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.