* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: François PIETTE
Email: francois.piette@ping.be http://www.rtfm.be/fpiette
francois.piette@rtfm.be
Creation: May 1996
Version: 2.35
Object: TFtpClient is a FTP client (RFC 959 implementation)
Support: Please ask your question in the support mailing list.
See website for details on subscription.
Legal issues: Copyright (C) 1997 by François PIETTE
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Quick Reference:
Properties:
HostName - FTP server host name or IP address
UserName - User name for authentication on FTP server
PassWord - Passwor needed for user, can be blank
HostDirName - Directory as knwon of FTP server
HostFileName - File name as known on FTP server
LocalFileName - Local file name (complete path)
Binary - Select binary or ascii file transfert (Need to call TypeSet
or TypeSetAsync to send it to FTP server).
(There are other less used properties, see code below)
Methods:
Open - Open the connection with the FTP server
User - Send username
Pass - Send password
Connect - Open the connection, send username and password
Quit - Disconnect gracefully from FTP server
Abort - Disconnect (close connection) immediately
Pwd - Get current working directory
Cwd - Change Working Directory
CDup - Change to parent directory
TypeSet - Set type for file transfert (see Binary property)
TypeBinary - Set to binary type transfert and call TypeSet
TypeAscii - Set to ascii type transfert and call TypeSet
Put - Upload a file
Transmit - Connect, Cwd, Upload a file & Quit
Append - Upload a file, appending to existing
AppendFile - Connect, Cwd, Append a file & Quit
Get - Download a file
Receive - Connect, Cwd, Download a file & Quit
RestGet - Download a file, restarting from current local file size
RestartGet - Connect, Cwd, Restart a file & Quit
Dir - Download a directory listing to a file
Directory - Connect, Cwd, Download a directory listing to a file & Quit
Ls - Download a file name listing to a file
List - Connect, Cwd, Download a file name listing to a file & Quit
Mkd - Create a directory on the server
Mkdir - Connect, Cwd, Create a directory on the server & Quit
Ren - Rename a file or directory on the server
Rename - Connect, Cwd, Rename a file or directory on the server & Quit
Dele - Delete a file on the server
Delete - Connect, Cwd, Delete a file on the server & Quit
Rmd - Remove a directoy from the server
Rmdir - Connect, Cwd, Remove a directoy from the server & Quit
Syst - Get system information from the server
System - Connect, Cwd, Get system information from the server & Quit
Size - Get file size
FileSize - Connect, Cwd, get file size & Quit
Quote - Send literal command (use LocalFileName as command to send)
DoQuote - Connect, Cwd, send literal command & Quit
(There are two set of methods: Async and Sync. The Async are the prefered
ones to build robust applications. Their name end with Async like GetAsync)
(There are other less used methods, see code below)
History:
Nov 04, 1996 Better error handling
Property for timeout, defualt to 15 sec
Dec 03, 1996 Adapted display functionnality for Delphi 2
Dec 27, 1996 Added transmit functions
Changed all procedure to function returning boolean status
Aug 13, 1997 Added multiline response support
Added support for strange Microsoft PWS FTP behaviour
Sep 10, 1997 Added support for Dir and Ls commands
Corrected bugs to enable correct use of separate commands
Oct 16, 1997 V2.07 Adapted for changes in TWSocket object
Added FtpCliVersion constant
Nov 25, 1997 V2.08 Accept 250 as well as 226 for succesfull file transfert
Suggested by fdragon@world-net.net
Nov 26, 1997 V2.09 don't display error message in the receive event when
the socket is no more connected.
Nov 29, 1997 V2.10 added Mkd and Mkdir functions to create a directory.
As suggested by Christian Rösner
Dec 04, 1997 V2.11 Added Ren, Dele, Rmd functions
As suggested by Frank Riemann
Changed Mkd and Mkdir functions to take HostFileName to
specify the directory name. This is more consistent with the
rest of the component usage.
Dec 29, 1997 V2.12 Added a TrimLeft function for Delphi 1
Dec 30, 1997 V2.13 Added Syst and System commands as suggested by
Fire Dragon
Added the LastResponse property
Corrected a message ("Daniel Fazekas" )
Jan 10, 1998 V2.14 Accept response 150 and 125 for Get Submitted by Fire
Dragon .
Added a quick reference for most used properties and methods.
Made TFtpCli a TComponent descendant.
Added the Size, FileSize, Quote, DoQuote, RestartGet method.
Made ControlSocket a readonly property (allow easy DNSLookup).
Added a Port property.
Jan 25, 1998 V2.15
Completely revised to make it asynchronous.
This means that a new set of functions is born. They all have
a name ending with Async. For example GetAsync. Asynchronous
means that when you call the function, it returns almost
immediately. The operation is done in the background.
The asynchronous operation allows to make several request
simultaneously WITHOUT using threads. Just use two or more
TFtpClient and call each GetAsync (or other) method as those
method returns almost instantly, all the request will be done
in the background, generating the OnRequestDone when finished.
Added a State property
This allows to check for component work in the background.
You can call methods only when State = ftpReady (except the
Abort method which can be called at any time)
The Asynchronous methods are the prefered ones.
Added Pwd command
Returns the current working directory on the server.
Added CDup command
Change to parrent directory on FTP server.
Added DirResult property
Parse the LastResponse property to return the directory.
Do no always work when the server returns multi-line responses.
(updated by Pwd, Cwd, CDup and Mkd commands).
Changed function IsConnected to Connected, a read-only property.
It's more object oriented.
Replaced file I/O by stream I/O.
It's the first step to allow Stream I/O outside of the component.
New sample application (Delphi only now, CPP later).
Every command has now a button to excercize it
(async version only)
The synchronous commands (old commands) are implemented by
calling the asynchronous version and waiting.
Multi-threaded property
Tells the component how to wait for command completion.
Removed the TWait component use.
No need to have a TWait component.
Jan 31, 1998 V2.16 Accept response 150 and 125 for Put.
Feb 01, 1998 V2.17 Added intermediate message for OnRequestDone event
Feb 02, 1998 V2.18 Corrected a bug: all sync function returned always FALSE.
Added User and Pass synchronous functions.
Made PutAsync return ftpPutAsync in the OnrequestDone event.
Feb 04, 1998 V2.19 Added an OnCommand event to give a chance to the user to
modify the commands to make some custom commands. Also added the
OnResponse event to allow custom commands to get the response
and alter it as necessary.
Feb 15, 1998 V2.20 Added a FindClose after the FindFirst in GetFileSize routine
as pointed by "Daniel Fazekas"
Feb 21, 1998 V2.21 Enabled progress updated on put
Feb 22, 1998 V2.22 Accept result code 250 after Put command
Implemented Append and AppendFile commands
Mar 07, 1998 V2.23 Made RequestType a R/O property
Mar 15, 1998 V2.24 Reordered PORT/REST/RETR
Added a port command
The ByteCount passed to OnProgress now take into account the
restart byte offset.
Renamed Disply to TriggerDisplay and made it virtual
Used TriggerDisplay everywhere.
Modified the Timeout mechanism to reset the timeout each
time the OnProgress event is called.
Abort command call CancelDnsLookup approprietedly
Mar 27, 1998 V2.25 Adapted for C++Builder 3
Avr 01, 1998 V2.26 Made a valid LastResponse and ErrorMessage when DNS lookup
failed. Added some compiler options.
Apr 10, 1998 V2.27 Added some ftpFctCwd in some highlevel functions.
Suggested by Ray Andrews .
Apr 13, 1998 V2.28 Save error code when the data connection is closed to use
it later to return the status for file transfert.
Implemented passive mode, with help from Yaron Golan
. A new property Passive enable this mode.
Put do not work [yet] is passive mode.
Apr 14, 1998 V2.29 Made passive mode PUT work.
Added ShareMode property (see TFileStream.Create on-line help)
Made ResumeAt property.
Apr 15, 1998 V2.30 Added the OnReadyToTransmit event.
Correctly handled error when local file not found.
Checked if socket connected in SendCommand
Apr 22, 1998 V2.31 Corrected CDupAsync procedure (thanks to Eric
Engler englere@swcp.com)
Apr 26, 1998 V2.32 Added TypeBinary and TypeAscii just to help a little bit.
May 01, 1998 V2.33 Added check for continuation lines in NextxPutAsync
May 05, 1998 V2.34 Added some more delay in WMFtpCloseData.
May 13, 1998 V2.35 In passive mode STOR or APPE, changed the sequence: now
wait for connection established before sending the STOR or APPE
command to FTP server.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * TCustomFtpCli -
TFtpClient -
Register - Do not evaluate boolean expressions more than necessary } {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TFtpCommand
TFtpDisplay
TFtpFct
TFtpFctSet
TFtpNextProc
TFtpProgress
TFtpReadyToTransmit
TFtpRequest
TFtpRequestDone
TFtpShareMode
TFtpState
BLOCK_SIZE
FtpCliVersion
FTP_RCV_BUF_SIZE
WM_FTP_CLOSEDATA
WM_FTP_REQUEST_DONE
procedure Register;
Do not evaluate boolean expressions more than necessary } {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
TFtpCommand = procedure(Sender : TObject;
var Cmd : String) of object
TFtpDisplay = procedure(Sender : TObject;
var Msg : String) of object
TFtpFct = (ftpFctNone, ftpFctOpen, ftpFctUser,
ftpFctPass, ftpFctCwd, ftpFctSize,
ftpFctMkd, ftpFctRmd, ftpFctRenFrom,
ftpFctRenTo, ftpFctGet, ftpFctDir,
ftpFctQuit, ftpFctSyst, ftpFctDele,
ftpFctPwd, ftpFctQuote, ftpFctPut,
ftpFctTypeSet, ftpFctRest, ftpFctCDup,
ftpFctLs, ftpFctAppend, ftpFctPort);
TFtpFctSet = set of TFtpFct
TFtpNextProc = procedure of object
TFtpProgress = procedure(Sender : TObject;
Count : LongInt;
var Abort : Boolean) of object
TFtpReadyToTransmit = procedure(Sender : TObject;
var bCancel : Boolean) of object
TFtpRequest = (ftpNone, ftpOpenAsync, ftpUserAsync,
ftpPassAsync, ftpCwdAsync, ftpConnectAsync,
ftpReceiveAsync, ftpDirAsync, ftpLsAsync,
ftpPortAsync, ftpGetAsync, ftpDirectoryAsync,
ftpListAsync, ftpSystemAsync, ftpSystAsync,
ftpQuitAsync,
ftpSizeAsync, ftpPutAsync, ftpAppendAsync,
ftpFileSizeAsync, ftpRqAbort, ftpMkdAsync,
ftpRmdAsync, ftpRenameAsync, ftpDeleAsync,
ftpRenAsync, ftpRenToAsync, ftpRenFromAsync,
ftpDeleteAsync, ftpMkdirAsync, ftpRmdirAsync,
ftpPwdAsync, ftpQuoteAsync, ftpCDupAsync,
ftpDoQuoteAsync, ftpTransmitAsync, ftpTypeSetAsync,
ftpRestAsync, ftpRestGetAsync, ftpRestartGetAsync);
TFtpRequestDone = procedure(Sender : TObject;
RqType : TFtpRequest;
Error : Word) of object
TFtpShareMode = (ftpShareCompat, ftpShareExclusive,
ftpShareDenyWrite, ftpShareDenyRead,
ftpShareDenyNone);
TFtpState = (ftpNotConnected, ftpReady, ftpInternalReady,
ftpDnsLookup, ftpConnected, ftpAbort,
ftpInternalAbort, ftpWaitingBanner, ftpWaitingResponse);
BLOCK_SIZE = 1024
FtpCliVersion = 235
Enable partial boolean evaluation } {$T-} { Untyped pointers } {$IFNDEF VER80} { Not for Delphi 1 } {$J+} { Allow typed constant to be modified } {$ENDIF} {_DEFINE TRACE
FTP_RCV_BUF_SIZE = 4096
WM_FTP_CLOSEDATA = WM_USER + 2
WM_FTP_REQUEST_DONE = WM_USER + 1