Home arrow Delphi-Kylix arrow The Implementation of an FTP Server

The Implementation of an FTP Server

In the previous article, we discussed RFC 959, which defines how an FTP server should work. We also walked through some of the commands that are used in this protocol. In this article, we will be creating an example FTP server in Delphi.

Author Info:
By: Leidago
Rating: 5 stars5 stars5 stars5 stars5 stars / 26
February 05, 2007
  1. · The Implementation of an FTP Server
  2. · The Code
  3. · Deleting Files
  4. · Listing Files
  5. · Making and Removing Directories
  6. · Authenticating Users

print this article

The Implementation of an FTP Server
(Page 1 of 6 )

Required Tools

Delphi 6 or higher and Indy 10.1.5, the latest snapshot. I've only tested this application on Windows XP, so, although  I do not think you will encounter any problems on most other platforms, please let me know if you do. I will try to make the application as platform agnostic as possible.

The application

To create our FTP server, we are going to use the idftpserver component available in Delphi. This component implements all the commands needed to create a viable server application. As always, I am going to implement as many commands as possible in this application, but by no means all of them. To implement an FTP server application that meets the minimum requirements you need to:

  • Be able to show all files in a given directory.
  • Change and remove a directory.
  • Upload and download files.
  • Delete and view file details.
  • Authenticate a user.

There are many more commands, but you can just about get on with implementing the minimum. To see how many commands you can implement with Indy,  drop an idftpserver component on a form and look at the object inspectors events tab. Indy has done most of the interpreting of the FTP protocol, and thus makes it easy to implement the commands. 

Start Delphi and create a new application. On the form add the following components:

  •  One Memo
  • Three Edits
  • Two Buttons
  • Four Labels

In edit1's text property add "myusername" and on edit2's text property add "mypassword."  Then from the Indy servers tab drop the idFTPServer component, and from the Indy intercepts tab drop a TidServerInterceptlogfile component; rename it to logfile1.  Now we need to connect this intercept to the idftpserver component. So click on the idftpserver component, go to its intercept property on the object inspector and click on the drop down arrow. It should contain the word "logfile1." Select it and we're done.

On button1 add the caption "Connect" and on button2 add the caption "Exit." Double click on button1 and add the following code:

procedure TForm1.Button1Click(Sender: TObject); begin idftpserver1.DefaultPort:=strtoint(edit3.text); idftpserver1.Active:=true; showmessage('Connected'); end;

Then do the same for button2 but add the following code:

procedure TForm1.Button2Click(Sender: TObject); begin idftpserver1.Active:=false; close; end;

Button1 does a couple of things. It activates the ftpserver application and also sets the default port, which is number 21. The port number is very important because it is where the client application is going to try to connect to the server.  Button2 just closes down the application. Your form should now look something like this:

blog comments powered by Disqus

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials