Retrieving full directory tree

Giganews Newsgroups
Subject: Retrieving full directory tree
Posted by:  Egon (no-mail@spammers.com)
Date: Sat, 12 Jul 2003

Hello,

I try to retrieve full directory (and subdirectory)
listing from a remote FTP server. Using snippet
shown below I've got "Connection Closed Gracefully"
message after reading root directory listing.
What to do ?

//----------------------------------------<snippet>
void __fastcall TEFTP::Button1Click(TObject *Sender)
{
// What is what:
// -------------
// TListView *lista;
// TIdFTP *ftp;
//
lista->Items->Clear();
try
  {
  ftp->Connect(true, 3000);
  }
catch ( ... )
  {
  }

if(ftp->Connected())
  {
  try
    {
    ftp->ChangeDir("\\");
    ftp->TransferType = ftASCII;
    ftp->List(NULL, "", true);
    WypelnijListView();
    }
  catch ( ... )
    {
    }
  TListItem *item;
  for(int a=0; a<lista->Items->Count; a++)
    {
    item = lista->Items->Item[a];
    if(item->SubItems->Strings[0] == "::DIR::")
      {
      ftp->ChangeDir(item->SubItems->Strings[0] + "\\");
      ftp->List(NULL, "", true);
      WypelnijListView();
      }
    }
  ftp->Disconnect();
  }    // End of IF
}
//--------------------------------------------------------------------------
-
bool __fastcall TEFTP::WypelnijListView()
{
//
TIdFTPListItems *DirItems = ftp->DirectoryListing;

  int C = DirItems->Count;
  if(C < 1)return false;

for(int i=0; i<C; i++)
  {
  TIdFTPListItem *DirItem = DirItems->Items[i];
  TListItem *LvItem = lista->Items->Add();
  LvItem->Caption = DirItem->FileName;
  if(DirItem->ItemType == ditDirectory)
    {
    LvItem->SubItems->Add("::DIR::");
    LvItem->ImageIndex = 0;
    }
  else
    {
    LvItem->SubItems->Add(ExtractFileExt(DirItem->FileName));
    LvItem->ImageIndex = 1;
    }
  LvItem->SubItems->Add(DirItem->Size);
  }
return true;
}
//----------------------------------------<snippet>

TIA,
Egon

Replies