⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idftp.pas

📁 photo.163.com 相册下载器 多线程下载
💻 PAS
📖 第 1 页 / 共 5 页
字号:
}
{
{   Rev 1.35    9/28/2003 11:41:06 PM  JPMugaas
{ Reworked Eldos's proposed FTP fix as suggested by Henrick Hellstr鰉 by moving
{ all of the IOHandler creation code to InitDataChannel.  This should reduce
{ the likelihood of error.
}
{
{   Rev 1.33    9/18/2003 11:22:40 AM  JPMugaas
{ Removed a temporary workaround for an OnWork bug that was in the Indy Core.
{ That bug was fixed so there's no sense in keeping a workaround here.
}
{
{   Rev 1.32    9/12/2003 08:05:30 PM  JPMugaas
{ A temporary fix for OnWork events not firing.  The bug is that OnWork events
{ aren't used in IOHandler where ReadStream really is located.
}
{
{   Rev 1.31    9/8/2003 02:33:00 AM  JPMugaas
{ OnCustomFTPProxy added to allow Indy to support custom FTP proxies.  When
{ using this event, you are responsible for programming the FTP Proxy and FTP
{ Server login sequence.
{ GetLoginPassword method function for returning the password used when logging
{ into a FTP server which handles OTP calculation.  This way, custom firewall
{ support can handle One-Time-Password system transparently.  You do have to
{ send the User ID before calling this function because the OTP challenge is
{ part of the reply.
}
{
{   Rev 1.30    6/10/2003 11:10:00 PM  JPMugaas
{ Made comments about our loop that tries several AUTH command variations.
{ Some servers may only accept AUTH SSL while other servers only accept AUTH
{ TLS.
}
{
{   Rev 1.29    5/26/2003 12:21:54 PM  JPMugaas
}
{
{   Rev 1.28    5/25/2003 03:54:20 AM  JPMugaas
}
{
{   Rev 1.27    5/19/2003 08:11:32 PM  JPMugaas
{ Now should compile properly with new code in Core.
}
{
{   Rev 1.26    5/8/2003 11:27:42 AM  JPMugaas
{ Moved feature negoation properties down to the ExplicitTLSClient level as
{ feature negotiation goes hand in hand with explicit TLS support.
}
{
{   Rev 1.25    4/5/2003 02:06:34 PM  JPMugaas
{ TLS handshake itself can now be handled.
}
{
    Rev 1.24    4/4/2003 8:01:32 PM  BGooijen
  now creates iohandler for dataconnection
}
{
{   Rev 1.23    3/31/2003 08:40:18 AM  JPMugaas
{ Fixed problem with QUIT command.
}
{
    Rev 1.22    3/27/2003 3:41:28 PM  BGooijen
  Changed because some properties are moved to IOHandler
}
{
{   Rev 1.21    3/27/2003 05:46:24 AM  JPMugaas
{ Updated framework with an event if the TLS negotiation command fails.
{ Cleaned up some duplicate code in the clients.
}
{
{   Rev 1.20    3/26/2003 04:19:20 PM  JPMugaas
{ Cleaned-up some code and illiminated some duplicate things.
}
{
{   Rev 1.19    3/24/2003 04:56:10 AM  JPMugaas
{ A typecast was incorrect and could cause a potential source of instability if
{ a TIdIOHandlerStack was not used.
}
{
{   Rev 1.18    3/16/2003 06:09:58 PM  JPMugaas
{ Fixed port setting bug.
}
{
{   Rev 1.17    3/16/2003 02:40:16 PM  JPMugaas
{ FTP client with new design.
}
{
    Rev 1.16    3/16/2003 1:02:44 AM  BGooijen
  Added 2 events to give the user more control to the dataconnection, moved
  SendTransferType, enabled ssl
}
{
{   Rev 1.15    3/13/2003 09:48:58 AM  JPMugaas
{ Now uses an abstract SSL base class instead of OpenSSL so 3rd-party vendors
{ can plug-in their products.
}
{
{   Rev 1.14    3/7/2003 11:51:52 AM  JPMugaas
{ Fixed a writeln bug and an IOError issue.
}
{
{   Rev 1.13    3/3/2003 07:06:26 PM  JPMugaas
{ FFreeIOHandlerOnDisconnect to FreeIOHandlerOnDisconnect at Bas's instruction
}
{
{   Rev 1.12    2/21/2003 06:54:36 PM  JPMugaas
{ The FTP list processing has been restructured so that Directory output is not
{ done by IdFTPList.  This now also uses the IdFTPListParserBase for parsing so
{ that the code is more scalable.
}
{
{   Rev 1.11    2/17/2003 04:45:36 PM  JPMugaas
{ Now temporarily change the transfer mode to ASCII when requesting a DIR.
{ TOPS20 does not like transfering dirs in binary mode and it might be a good
{ idea to do it anyway.
}
{
{   Rev 1.10    2/16/2003 03:22:20 PM  JPMugaas
{ Removed the Data Connection assurance stuff.  We figure things out from the
{ draft specificaiton, the only servers we found would not send any data after
{ the new commands were sent, and there were only 2 server types that supported
{ it anyway.
}
{
{   Rev 1.9    2/16/2003 10:51:08 AM  JPMugaas
{ Attempt to implement:
{
{ http://www.ietf.org/internet-drafts/draft-ietf-ftpext-data-connection-assuranc
{ e-00.txt
{
{ Currently commented out because it does not work.
}
{
{   Rev 1.8    2/14/2003 11:40:16 AM  JPMugaas
{ Fixed compile error.
}
{
{   Rev 1.7    2/14/2003 10:38:32 AM  JPMugaas
{ Removed a problematic override for GetInternelResponse.  It was messing up
{ processing of the FEAT.
}
{
{   Rev 1.6    12-16-2002 20:48:10  BGooijen
{ now uses TIdIOHandler.ConstructIOHandler to construct iohandlers
{ IPv6 works again
{ Independant of TIdIOHandlerStack again
}
{
{   Rev 1.5    12-15-2002 23:27:26  BGooijen
{ now compiles on Indy 10, but some things like IPVersion still need to be
{ changed
}
{
{   Rev 1.4    12/15/2002 04:07:02 PM  JPMugaas
{ Started port to Indy 10.  Still can not complete it though.
}
{
{   Rev 1.3    12/6/2002 05:29:38 PM  JPMugaas
{ Now decend from TIdTCPClientCustom instead of TIdTCPClient.
}
{
{   Rev 1.2    12/1/2002 04:18:02 PM  JPMugaas
{ Moved all dir parsing code to one place.  Reworked to use more than one line
{ for determining dir format type along with flfNextLine dir format type.
}
{
{   Rev 1.1    11/14/2002 04:02:58 PM  JPMugaas
{ Removed cludgy code that was a workaround for the RFC Reply limitation.  That
{ is no longer limited.
}
{
{   Rev 1.0    11/14/2002 02:20:00 PM  JPMugaas
}
unit IdFTP;

{
Change Log:
2002-10-25 - J. Peter Mugaas
  - added XCRC support - specified by "GlobalSCAPE Secure FTP Server User抯 Guide"
    which is available at http://www.globalscape.com
    and also explained at http://www.southrivertech.com/support/titanftp/webhelp/titanftp.htm
  - added COMB support - specified by "GlobalSCAPE Secure FTP Server User抯 Guide"
    which is available at http://www.globalscape.com
    and also explained at http://www.southrivertech.com/support/titanftp/webhelp/titanftp.htm
2002-10-24 - J. Peter Mugaas
  - now supports RFC 2640 - FTP Internalization
2002-09-18
  _ added AFromBeginning parameter to InternalPut to correctly honor the AAppend parameter of Put
2002-09-05 - J. Peter Mugaas
  - now complies with RFC 2389 - Feature negotiation mechanism for the File Transfer Protocol
  - now complies with RFC 2428 - FTP Extensions for IPv6 and NATs
2002-08-27 - Andrew P.Rybin
  - proxy support fix (non-standard ftp port's)
2002-01-xx - Andrew P.Rybin
  - Proxy support, OnAfterGet (ex:decrypt, set srv timestamp)
  - J.Peter Mugaas: not readonly ProxySettings
  A Neillans - 10/17/2001
    Merged changes submitted by Andrew P.Rybin
    Correct command case problems - some servers expect commands in Uppercase only.
  SP - 06/08/2001
    Added a few more functions
  Doychin - 02/18/2001
    OnAfterLogin event handler and Login method

    OnAfterLogin is executed after successfull login  but before setting up the
      connection properties. This event can be used to provide FTP proxy support
      from the user application. Look at the FTP demo program for more information
      on how to provide such support.

  Doychin - 02/17/2001
    New onFTPStatus event
    New Quote method for executing commands not implemented by the compoent

-CleanDir contributed by Amedeo Lanza

TODO: Chage the FTP demo to demonstrate the use of the new events and add proxy support
}

interface

uses
  Classes,
  IdAssignedNumbers, IdGlobal, IdCustomTransparentProxy, IdExceptionCore,
  IdExplicitTLSClientServerBase, IdFTPCommon, IdFTPList, IdFTPListParseBase, IdException,
  IdIOHandler, IdIOHandlerSocket,
  IdReplyFTP,
  IdReplyRFC,
  IdReply,
  IdSocketHandle, IdStreamVCL,
  IdTCPConnection, IdTCPClient, IdThread, IdTStrings, IdZLibCompressorBase;

type
  //Added by SP
  TIdCreateFTPList = procedure(ASender: TObject; Var VFTPList: TIdFTPListItems) of object;
//  TIdCheckListFormat = procedure(ASender: TObject; const ALine: String; Var VListFormat: TIdFTPListFormat) of object;
  TOnAfterClientLogin = TNotifyEvent;
  TIdFtpAfterGet = procedure (ASender: TObject; VStream: TStream) of object; //APR
  TIdOnDataChannelCreate = procedure (ASender: TObject; ADataChannel: TIdTCPConnection) of object;
  TIdOnDataChannelDestroy = procedure (ASender: TObject; ADataChannel: TIdTCPConnection) of object;


const
  Id_TIdFTP_TransferType = ftBinary;
  Id_TIdFTP_Passive = False;
  Id_TIdFTP_UseNATFastTrack = False;
  Id_TIdFTP_HostPortDelimiter = ':';
  Id_TIdFTP_DataConAssurance = False;

type
  //APR 011216:
  TIdFtpProxyType = (fpcmNone,//Connect method:
    fpcmUserSite, //Send command USER user@hostname
    fpcmSite, //Send command SITE (with logon)
    fpcmOpen, //Send command OPEN
    fpcmUserPass,//USER user@firewalluser@hostname / PASS pass@firewallpass
    fpcmTransparent, //First use the USER and PASS command with the firewall username and password, and then with the target host username and password.
    fpcmHttpProxyWithFtp, //HTTP Proxy with FTP support. Will be supported in Indy 10
    fpcmCustomProxy // use OnCustomFTPProxy to customize the proxy login
  ); //TIdFtpProxyType
  //This has to be in the same order as TLS_AUTH_NAMES
  TAuthCmd = (tAuto, tAuthTLS, tAuthSSL, tAuthTLSC, tAuthTLSP);

const
    Id_TIdFTP_DataPortProtection = ftpdpsClear;
    DEF_Id_TIdFTP_Implicit = False;
    DEF_Id_FTP_UseExtendedDataPort = False;
    DEF_Id_TIdFTP_UseExtendedData = False;
    DEF_Id_TIdFTP_UseMIS = False;
    DEF_Id_FTP_UseCCC = False;
    DEF_Id_FTP_AUTH_CMD = tAuto;

type
  TIdFTPBannerEvent = procedure (ASender: TObject; const AMsg : String) of object;
  TIdFTPClientIdentifier = class (TPersistent)
  protected
    FClientName : String;
    FClientVersion : String;
    FPlatformDescription : String;
    procedure SetClientName(const AValue: String);
    procedure SetClientVersion(const AValue: String);
    procedure SetPlatformDescription(const AValue: String);
    function GetClntOutput: String;
  public
    procedure Assign(Source: TPersistent); override;
    property ClntOutput : String read GetClntOutput;
  published
    property ClientName : String read FClientName write SetClientName;
    property ClientVersion : String read FClientVersion write SetClientVersion;
    property PlatformDescription : String read FPlatformDescription write SetPlatformDescription;
  end;
  TIdFtpProxySettings = class (TPersistent)
  protected
    FHost, FUserName, FPassword: String;
    FProxyType: TIdFtpProxyType;
    FPort: Integer;
  public
    procedure Assign(Source: TPersistent); override;
  published
    property  ProxyType: TIdFtpProxyType read FProxyType write FProxyType;
    property  Host: String read FHost write FHost;
    property  UserName: String read FUserName write FUserName;
    property  Password: String read FPassword write FPassword;
    property  Port: Integer read FPort write FPort;
  End;//TIdFtpProxySettings

  TIdFTPTZInfo = class(TPersistent)
  protected
    FGMTOffset : TDateTime;
    FGMTOffsetAvailable : Boolean;
  public
    procedure Assign(Source: TPersistent); override;
  published
    property GMTOffset : TDateTime read FGMTOffset write FGMTOffset;
    property GMTOffsetAvailable : Boolean read FGMTOffsetAvailable write FGMTOffsetAvailable;
  end;

  TIdFTP = class(TIdExplicitTLSClient)
  protected
    FAutoLogin: Boolean;
    FCurrentTransferMode : TIdFTPTransferMode;
    FClientInfo : TIdFTPClientIdentifier;

    FUsingSFTP : Boolean; //enable SFTP internel flag
    FUsingCCC : Boolean; //are we using FTP with SSL on a clear control channel?
    FCanUseMLS : Boolean; //can we use MLISx instead of LIST
    FUsedMLS : Boolean; //Did the developer use MLSx commands for the last list command
    FUsingExtDataPort : Boolean; //are NAT Extensions (RFC 2428 available) flag
    FUsingNATFastTrack : Boolean;//are we using NAT fastrack feature
    FCanResume: Boolean;
    FListResult: TIdStrings;
    FLoginMsg: TIdReplyFTP;

    FPassive: boolean;
    FDataPortProtection : TIdFTPDataPortSecurity;
    FAUTHCmd : TAuthCmd;
    FDataPort: Integer;
    FDataPortMin: Integer;
    FDataPortMax: Integer;
    FExternalIP : String;
    FResumeTested: Boolean;
    FSystemDesc: string;
    FTransferType: TIdFTPTransferType;
    FTransferTimeout : Integer;
    FDataChannel: TIdTCPConnection;
    FDirectoryListing: TIdFTPListItems;
    FDirFormat : String;
    FListParserClass : TIdFTPListParseClass;
    FOnAfterClientLogin: TNotifyEvent;
    FOnCreateFTPList: TIdCreateFTPList;
    FOnBeforeGet: TNotifyEvent;
    FOnBeforePut: TIdFtpAfterGet;
    //in case someone needs to do something special with the data being uploaded
    FOnAfterGet: TIdFtpAfterGet; //APR
    FOnAfterPut: TNotifyEvent; //JPM at Don Sider's suggestion
    FOnCustomFTPProxy : TNotifyEvent;
    FOnDataChannelCreate:TIdOnDataChannelCreate;
    FOnDataChannelDestroy:TIdOnDataChannelDestroy;
    FProxySettings: TIdFtpProxySettings;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -