Re: FTP Server problems

Giganews Newsgroups
Subject: Re: FTP Server problems
Posted by:  Remy Lebeau (TeamB) (gambit…@yahoo.com)
Date: Fri, 29 Aug 2003

"Luka Gabric" <luka.gabr…@hi.hinet.hr> wrote in message
news:7AEB7386CC7CE240luka.gabr…@hi.hinet.hr...
> I'd like to make a program(FTP Server) that allows other FTP
> clients to access a computer that has this server on. I can get it
> to log in but nothing else, how to exchange dirs and files etc?

Assuming you are using TIdFTPServer, you are supposed to assign event
handlers to the various events of the server, such as OnListDirectory,
OnRetreiveFile, OnStoreFile, etc. in order to respond to the cooresponding
client requests.  For example:

    procedure TForm1.IdFTPServer1ListDirectory(ASender: TIdFTPServerThread;
APath: string; ADirectoryListing: TIdFTPListItems);
    var
        sr: TSearchRec;
    begin
        if FindFirst(APath + '*.*', faAnyFile, sr) = 0 then
        begin
            do
                with ADirectoryListing.Add do
                begin
                    FileName := sr.Name;
                    if sr.Attr and faDirectory then
                        ItemType := ditDirectory
                    else
                        ItemType := ditFile;
                    ModifiedDate = FileDateToDateTime(sr.Time);
                    Size := sr.Size;
                end;
            until( FindNext(sr) != 0 );
            FindClose(sr);
        end;
    end;

    procedure TForm1.IdFTPServer1RetrieveFile(ASender: TIdFTPServerThread;
AFilename: string; var VStream: TStream);
    begin
        VStream := TFileStream.Create(AFilename, fmOpenRead or
fmShareDenyWrite);
    end;

    procedure TForm1.IdFTPServer1StoreFile(ASender: TIdFTPServerThread;
AFilename: string; AAppend: Boolean; var VStream: TStream);
    begin
        if AAppend then
            VStream := TFileStream.Create(AFilename, fmOpenReadWrite or
fmShareDenyWrite)
        else
            VStream := TFileStream.Create(AFilename, fmCreate or
fmShareDenyWrite);
    end;

Gambit

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/03

Replies

In response to

FTP Server problems posted by Luka Gabric on Fri, 29 Aug 2003