Home arrow Delphi-Kylix arrow Page 3 - 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 - Deleting Files
(Page 3 of 6 )

The client sends the name of the file to be deleted in the APathName variable. The procedure below basically takes that pathname and checks to see if the file exists before deleting it.

procedure TForm1.IdFTPServer1DeleteFile(ASender:TIdFTPServerContext; const APathName: String); begin if fileexists(APathName) then begin DeleteFile(APathName); end; end;

This event gets fired when the client wants to verify whether a file exists. The procedure uses the file exists() function to carry out the request:

procedure TForm1.IdFTPServer1FileExistCheck(ASender:TIdFTPServerContext; const APathName: String; var VExist: Boolean); begin if fileexists(APathName) then begin VExist:=true; end else begin VExist:=False; end; end;

procedure TForm1.IdFTPServer1GetFileDate(ASender: TIdFTPServerContext; const AFilename: String; var VFileDate: TDateTime); var fdate:tdatetime; begin //put the file date in a variable fdate:= FileAge(AFilename);  if  not (fdate=-1) then  begin VFileDate:=fdate; end; end;

We use the FindNext and FindFirst functions to get the requested file size as below:

procedure TForm1.IdFTPServer1GetFileSize(ASender:TIdFTPServerContext;   const AFilename: String; var VFileSize: Int64);   Var LFile : String; rec:tsearchrec; ASize: Int64 ;   begin LFile := setslashes(homedir + AFilename ); try if FindFirst(Lfile, faAnyFile, rec) = 0 then  repeat              Asize:=rec.Size;              until FindNext(rec) <> 0;         finally             FindClose(rec); end; if Asize > 1 then VFileSize:= Asize else VFilesize:=0; 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 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials