📄 ftpcli.pas
字号:
{*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: Fran鏾is PIETTE
Creation: May 1996
Version: V2.97
Object: TFtpClient is a FTP client (RFC 959 implementation)
Support FTPS (SSL) if ICS-SSL is used (RFC 2228 implementation)
EMail: http://www.overbyte.be http://www.rtfm.be/fpiette
francois.piette@overbyte.be francois.piette@rtfm.be
Support: Use the mailing list twsocket@elists.org
Follow "support" link at http://www.overbyte.be for subscription.
Legal issues: Copyright (C) 1996-2005 by Fran鏾is PIETTE
Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
<francois.piette@overbyte.be> <francois.piette@pophost.eunet.be>
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.
4. You must register this software by sending a picture postcard
to the author. Use a nice stamp and mention your name, street
address, EMail address and any comment you like to say.
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
Acct - Send account
Connect - Open the connection, send username, password and account
Quit - Disconnect gracefully from FTP server
Abort - Disconnect (close connection) immediately
AbortXfer - Abort file transfer without disconnecting.
Warning: LocalFilename property is lost after this command.
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 downloading a file & Quit
RestPut - Upload a file, restarting from ResumeAt property value
RestartPut - Connect, Cwd, Restart uploading 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
Feat - Get extensions supported
= SupportedExtensions which features server supports
Mlsd - Download a directory listing to a file, only supported if
ftpFeatMLST in SupportedExtensions - V2.90
Mlst - Get facts for a specified file or directory, only supported if
ftpFeatMLST in SupportedExtensions - V2.90
Result is in RemFacts property, and may be decoded by
DecodeMlsResp (in FtpSrvT)
Mdtm - Get file UTC modification time (to RemFileDT),
only supported if ftpFeatMDTM in SupportedExtensions - V2.90
Mdtmyy - Set file UTC modification time (from RemFileDT),
only supported if ftpFeatMDTMYY in SupportedExtensions - V2.90
AuthSsl - Start SSL authentication (FTPS protocol support)
Mfmt - Modify file UTC modification time (from RemFileDT),
only supported if ftpFeatMFftpFeatMLST in
SupportedExtensionsMT in SupportedExtensionse - V2.94
Md5 - Get MD5 hash sum for file (to ??),
only supported if ftpFeatMD5 in SupportedExtensions - V2.94
(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)
How to use FTPS (SSL) ?
First you need to has ICS-SSL and recompile the component and your projet
having symbol USE_SSL defined.
Then you may either use explicit commands AuthSsl after Open command to
request SSL authentification from server, or you may add ftpAuthSsl in the
options property and use one of the high level commands which will
automatically invoke AuthSsl once connected to the server.
You should use passive mode transfer with SSL authentication.
How to use a Proxy or Firewall ?
First of all, not all proxies or firewalls are the same. So have a look at
product documentation. However, most products support a transparent proxy
which doesn't require any special programming:
1) Instead of connection to a remote FTP server, you connect to the proxy
2) User name is replaced by user name, followed by '@' sign then followed
by target remote FTP server host name.
3) Password is usual remote FTP server password.
4) Most require using Passive mode.
Example: You want to connect to ftp.borland.com, using anonymous connection,
company firewall/proxy is running on host named proxyserver.
FtpCli1.HostName := 'proxyserver';
FtpCli1.UserName := 'anonymous@ftp.borland.com';
FtpCli1.Password := 'your.email@company';
FtpCli1.Passive := TRUE;
FEAT Command - numerous extensions have been made to the FTP protocol over
the past few years, although support of these new commands is very sporadic.
RFC2389 describes the FEAT command, which returns a multiline list of
extension supported by the server. Note that the SIZE command is an extension,
and not supported on all FTP servers. An internet-draft 'Extensions to FTP'
document the most useful new commands. The responses of five common FTP servers
to FEAT are listed below:
Microsoft IIS/5 in Windows 2000
500 'FEAT': command not understood
Microsoft IIS/6 in Windows 2003
211-FEAT
SIZE
MDTM
211 END
RhinoSoft Serv-U FTP 4.1
211-Extension supported
MDTM
MDTM YYYYMMDDHHMMSS[+-TZ] filename
SIZE
SITE PSWD;EXEC;SET;INDEX;ZONE;CHMOD;MSG
REST STREAM
211 End
Ipswich WS_FTP Server 3.14
211-Extensions supported
SIZE
MDTM
MLST size*;type*;perm*;create*;modify*;
LANG EN*
REST STREAM
TVFS
UTF8
AUTH SSL;TLS-P;
PBSZ
PROT C;P;
211 end
Gene6 FTP Server v3.1.0
FEAT
211-Extensions supported:
AUTH TLS
PBSZ
PROT
CLNT
MDTM
MLST type*;size*;created;modify*;
MODE Z
PASV
REST STREAM
SIZE
SSCN
TVFS
UTF8
XCRC "filename" SP EP
XMD5 "filename" SP EP
211 End.
Unknown Unix Daemon
211-Features:
MDTM
REST STREAM
SIZE
211 End
Another Unix Daemon
FEAT
211-Features:
MDTM
REST STREAM
SIZE
AUTH TLS
PBSZ
PROT
211 End
Internet Component Suite TFtpServer V1.39 and later
211-Extensions supported:
SIZE
REST STREAM
MDTM
MDTM YYYYMMDDHHMMSS[+-TZ] filename
MLST size*;type*;perm*;create*;modify*;
MFMT
MD5
211 END
The extensions supported by V2.94 of this component are:
MLST - Machine Listing, two listing commands:
MLSD - much better version of LIST directory
MLST - list a single file
an example response from either command is as follows:
size=17199;type=file;perm=fdrwa;create=20030616152030;
modify=20031001190114; 00master.zip
(note the date and time includes seconds which is missing from most LIST
responses, and the time stamps should be UTC - but don't seem to be in
WS_FTP Server)
MDTM - Get File Modification UTC Time - useful for resumed downloads,
to see if file has changed
SIZE - Get File Size - useful for resumed downloads, to see if file has changed
MDTM YYYYMMDDHHMMSS[+-TZ] filename - Set File Modification Time after
upload (+0 is UTC)
MFMT - Modify File Modification Time after upload (UTC)
MD5 - Check MD5 hash sum for specified file, used to check for corruption
History:
Nov 04, 1996 Better error handling
Property for timeout, default to 15 sec
Dec 03, 1996 Adapted display functionnality for Delphi 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -