Building an FTP browser frame

By: Piotr Gawronski

Abstract: Ever wonder what C++Builder's frames are for? Here's one example -- a frame for browsing FTP sites. By Piotr Gawronski.

Recently I had to enhance one of my applications to allow it to open files from an FTP server. At first I wanted to design a form and to insert it into my repository. But then I remembered that C++Builder supports something called frames.

Instead of creating a form I have created a frame that supports basic actions for browsing FTP servers (complete code here).

If you want to make it a file-downloading tool you can put frame somewhere on a form and enhance it -- for example, a double-click event for the listview with files list:

void __fastcall TForm1::fmFTPBrowse1lvDirListDblClick(TObject *Sender)
  // *** First call orginal method (it changes directories if necessery)

  if (fmFTPBrowse1->lvDirList->Selected != NULL && // Anything selected ?
      fmFTPBrowse1->lvDirList->Selected->SubItems->Strings[esiAttr].c_str()[0] != 'd') 
      // Is it a file ?
    // *** Caption contains a file name.
    AnsiString name = fmFTPBrowse1->lvDirList->Selected->Caption;

    fmFTPBrowse1->IdFTP->Get(name, "C:TEMP" + name, true);

enum ESIDescriptions { esiSize = 0, esiAttr, esiDate, esiUser, esiGroup };

esiAttr is an enumerated type that is defined in a frmFTPBrowse.h as described above. It makes it easier to access sub-items of listview elements.

This frame may not be perfect yet but I am planning some improvements. Let me know what you think!

Server Response from: ETNASC03