Home arrow Delphi-Kylix arrow Page 5 - The Implementation of an FTP Server
DELPHI-KYLIX

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 / 18
February 05, 2007
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
The Implementation of an FTP Server - Making and Removing Directories
(Page 5 of 6 )

The MakeDirectory command enables us to create a new directory on the  server side. The event below does that by using Delphi's CreateDir function:

procedure TForm1.IdFTPServer1MakeDirectory(ASender:TIdFTPServerContext; var VDirectory: String); var ldir:string; begin ldir:= setslashes(Homedir+VDirectory); if not DirectoryExists(ldir) then if not CreateDir(ldir) then raise Exception.Create('Cannot create '+ldir); end;

The retrieve file event enables the client to download a file. We use Tstreams to open and read a given file:

procedure TForm1.IdFTPServer1RetrieveFile(ASender:TIdFTPServerContext; const AFileName: String; var VStream: TStream); begin VStream := TFileStream.Create(setSlashes
(HomeDir+AFilename),fmOpenRead); end;

procedure TForm1.IdFTPServer1RenameFile(ASender:TIdFTPServerContext;   const ARenameFromFile, ARenameToFile: String); begin if not Renamefile(ARenameFromFile,ARenameToFile) then begin    Raise Exception.Create('Could not rename file'); end; end;

The event below executes when the client requests a directory to be removed. Here we use Delphi's RemoveDir() function to delete a directory:

procedure TForm1.IdFTPServer1RemoveDirectory(ASender:TIdFTPServerContext; var VDirectory: String); Var LFile : String; begin LFile := setslashes(homedir + VDirectory); if directoryexists(LFile) then begin RemoveDir(LFile); end else begin Raise Exception.Create('Could not remove directory');   end; end;


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- 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...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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