Re: FTPServer List of Files Does Not Send to Client. Why ?

Giganews Newsgroups
Subject: Re: FTPServer List of Files Does Not Send to Client. Why ?
Posted by:  Remy Lebeau (TeamB) (
Date: Wed, 22 Mar 2006

"Edward" <eduglobo20…> wrote in message

> Why the client are not receive the List of files ?

Because your code is not populating the list correctly.

>  ADirectory = ASender->HomeDir + APath;

Did you verify whether this is producing the correct path or not?  Also, I
do not see you doing any kind of translation from FTP-formatted paths into
actual file system paths.

>  if (FindFirst( AnsiString("*.*"), iAttributes, sr) == 0)

That is wrong.  You need to specify a full path in addition to the mask.
Specifying just a mask, the function will look in the calling process's
current working directory instead, which will usually be the wrong place to

>    if(sr.Name.SubString(1,1) == "." || sr.Name.SubString(1,2) == "..")

You should be adding those to the listing first before the actual

>    ADirectoryListing->Items[ct]->ItemType + ditDirectory;

You need to use the '=' operator instead of '+'.

With that said, try this code instead:

    void __fastcall TForm1::IdFTPServer1ListDirectory(TIdFTPServerThread
*ASender, const AnsiString APath, TIdFTPListItems *ADirectoryListing)
        TSearchRec sr;

        AnsiString ADirectory = ASender->HomeDir + APath;
        // translate ADirectory into a real machine path as needed, then ...

        if( FindFirst( ADirectory + "\\*.*", faAnyFile, sr) == 0 )
                if( (sr.Name != ".") && (sr.Name != "..") )
                    Item = ADirectoryListing->Add();
                    Item->FileName = sr.Name;
                    Item->Size = sr.Size;
                    Item->ModifiedDate = FileDateToDateTime(sr.Time);
                    if( sr.Attr & faDirectory )
                        Item->ItemType = ditDirectory;
                        Item->ItemType = ditFile;
            while( FindNext(sr) == 0 );



In response to

FTPServer List of Files Does Not Send to Client. Why ? posted by Edward on Wed, 22 Mar 2006