Get Download Status; C++; IdFTPClient

Giganews Newsgroups
Subject: Get Download Status; C++; IdFTPClient
Posted by:  Joe Pool (jpo…@letourneau-inc.com)
Date: Wed, 7 Sep 2005

How can I determine the progress of a download (i.e. to update a Progress
Bar)?

Below is a "mock-up" of my code.

void GetUpdate(void* params)  {
  ...
  TIdFTPListItem* Item = new TIdFTPListItem(NULL);
  try {
    IdFtp1->Connect(true);                        // Open a connection
    IdFtp1->List(NULL, "", true);
    do  {
      Item = IdFtp1->DirectoryListing->Items[i++];
      if (Item->FileName == "setup.exe")  {
        ProgressBar1->Max = Item->Size;          // assign setup.exe Size
to Max
        FileStream = new TFileStream("C:\setup.exe", fmCreate |
fmShareDenyWrite);
        IdFtp1->Get(Item->FileName, FileStream);  // download the file
        i = IdFtp1->DirectoryListing->Count + 1;  // forces to exit the loop
      }
    } while (IdFtp1->DirectoryListing->Count > i);
  } __finally  {
    IdFtp1->Quit();                              // Close FTP Connection
  }
  ...
}

The file transfers to my local computer, but I do not know how to update a
progress bar with ProgressBar1->Position.  Any ideas?

Regards,
Joe

Replies