Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to build a basic FTP server with Indy 10 Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Build a basic FTP server with Indy 10 01-Feb-05
Internet / Web
Delphi 7.x
User Rating
# Votes
Vicens Meier, Guillem
Reference URL:
			It is really difficult to find examples on how to build a FTP server using Indy, so 
here you have the basics about it. This article is written supposing you use Indy 

First of all you should know that FTP works on commands. While with Indy you do not 
need to implement these on your own, at least you should know that they exist and 
which is their purpose. Some examples are:

RETR   --> for retrieving files
PASV   --> for server opening connection and sending data to client (active mode)
PORT   --> for client opening connection and sending data to server(passive mode)
STOR   --> for storing files

You have also to take in consideration that FTP works with 2 connections: one for 
the commands and another for the data. You can find complete information about FTP 
searching on Internet for RFC 959.

For your FTP server you will need a TIdFTPServer component, and I would also 
suggest you add a TIdUserManager for the accounts. Not a requirement though, 
because you can choose to have only anonymous users.

After adding the TidFTPServer the minima you need to do is following:

1 - Set the bindings, i.e., the IPs and ports to which your server will listen. You 
can do this from the Object Inspector.

2 - Decide if your FTP server will always be listening. In this case set property 
Active to true. Otherwise take in consideration you will need to activate it 
somewhere if a client wants to connect.

3 - Implement the event handlers for OnRetrieveFile (RETR command) and OnStoreFile 
(STOR). You will need to pass them a stream. For example:
2   procedure TDataModule.IdFTPServerRetrieveFile(ASender: TIdFTPServerContext;
3     const AFileName: string; var VStream: TStream);
4   begin
5     VStream := TFileStream.Create(MyFileName, fmOpenRead or fmShareExclusive);
6   end;
8   procedure TDataModule.IdFTPServerStoreFile(ASender: TIdFTPServerContext;
9     const AFileName: string; AAppend: Boolean; var VStream: TStream);
10  begin
11    VStream := TFileStream.create(MyFileName, fmCreate or fmShareExclusive ) ;
12  end;

Doing this you will have an extremely simple FTP Server. You can add more 
functionality using the events provided by TidFTPServer. Have a look at them and 
you will see that you can control changing directories, user logins, etc. You can 
also add your own custom commands using the CommandHandlers property, but as long 
as you are not 100% sure about what you are doing you should NOT implement the 
protocol commands (like RETR and so on) on your own. TidFTPServer has command 
handlers for all of them implemented.

You can find more information about TidFTPServer and other Indy 10 components at

Hope this article can help some people, as I went almost crazy the first time I
searched info about FTP server demos ;-)

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC