Sample code for 30+ languages & platforms
Unicode C++

FTP Upload with Progress Event Callbacks

See more FTP Examples

FTP upload with progress event callbacks.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkFtp2W.h>

#include <CkFtp2ProgressW.h>

class ftpProgress : public CkFtp2ProgressW {

  public:
  ftpProgress() { }
  virtual ~ftpProgress() { }

  void PercentDone(int percentDone, bool *abort) {
    wprintf(L"Percent Done: %d\n",percentDone);
  }

  void ProgressInfo(const wchar_t *name, const wchar_t *value) {
    wprintf(L"%s: %s\n",name,value);
  }

};

void ChilkatSample(void)
    {
    bool success = false;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkFtp2W ftp;
    ftpProgress ftp_progress;
    ftp.put_EventCallbackObject(&ftp_progress);

    ftp.put_Hostname(L"ftp.someFtpServer.com");
    ftp.put_Username(L"my_ftp_username");
    ftp.put_Password(L"my_ftp_password");

    // Connect and login to the FTP server.
    success = ftp.Connect();
    if (success != true) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    // Change to the remote directory where the file will be uploaded.
    success = ftp.ChangeRemoteDir(L"junk");
    if (success != true) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    // Upload a file.
    const wchar_t *localPath = L"c:/temp/hamlet.xml";
    const wchar_t *remoteFilename = L"hamlet.xml";

    success = ftp.PutFile(localPath,remoteFilename);
    if (success != true) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    success = ftp.Disconnect();

    wprintf(L"File Uploaded!\n");
    }