Indy 9
|
TIdFTPServer = class(TIdTCPServer)
FTP is a basic file-sharing system for uploading and downloading files, as well as managing files and directories. The FTP protocol is commonly used for software distribution, uploading files to a web-server, and providing archives for various purposes.
TIdFTPServer implements properties that can be used to configure and control FTP server options, including:
TIdFTPServer provides a default implementation that uses TIdCommandHandler instances and TIdCommand reply event handlers to perform file and directory handling functions. The server can also be implemented using the OnExecute event handler to respond to multi-threaded client connections when the CommandHandlersEnabled property is False.
TIdFTPServer provides a collection and event handlers to allow access to TIdUserAccount instances for Authentication of client accounts. There are also event handler that allow handling the FTP USER and PASS commands when User Accounts are maintained external to the FTP server implementation.
property AllowAnonymousLogin: Boolean;
When AllowAnonymousLogin is False, accounts names and passwords will be authenticated using UserAccounts, or the OnUserLogin event handler when UsetrAccounts are not assigned.
The default value for AllowAnonymousLogin if False, as assigned in the Create constructor.
property AnonymousAccounts: TStringList;
AnonymousAccounts is initialized in the Create constructor, and contains the default values 'anonymous' and 'guest'. Note: By default, AllowAnonymousLogin is set to False in Create.
AnonymousAccounts is freed and released in the Destroy destructor.
AnonymousAccounts is used in the FTP USER command action handler, when the server handles the user name for the account provided in the TIdCommand instance triggering the command action handler. The USER command action handler compares the value found in the TIdFTPServerThread.UnparsedParams against AnonymousAccounts, and sets the UserType and Username for the associated Thread in ASender when the user account is found.
Note: AnonymousAccounts is not used to authenicate anonymous logins in the FTP server implementation when UserAccounts has not been assigned. In this situation, OnUserLogin is signalled to perfrom username and password authentication.
property AnonymousPassStrictCheck: Boolean;
When AnonymousPassStrictCheck check is True, and the password for the client connection is not blank, the password is checked to insure that the value contains an RFC-compliant email address. When the password is valid, the authentication status in TIdFTPServerThread.Authenticated is set to True.
When the password is blank for the anonymous account, UserType and Authenticated properties in the threaded client connection are reverted to their unauthenticated values.
The default value for AnonymousPassStrictCheck is True, as assigned in the Create constructor.
property DefaultDataPort: Integer;
DefaultDataPort is used frequently in TIdFTPServer. DefaultDataPort is the value provided as a parameter when creating the TIdFTPServerThread instances for threaded client connections to the FTP server. In turn, DefaultDataPort is also used when the TIdFTPServerThread needs to create a TIdDataChannelThread or intitialize the data channel for the threaded client connection.
property EmulateSystem: TIdFTPSystems;
The default value for EmulateSystem is ftpsDOS, as assigned in the Create constructor.
property HelpReply: Tstrings;
HelpReply contents are sent in responses using the Control channel for the client connection.
Applications should assign lines of text to the property that indicate the FTP commands supported in the server implementation, or to provide site-specific implementation status information.
property SystemType: string;
SystemType is updated when the value in the EmulateSystem property is changed, and SystemType contains a standard value. SystemType will contain one of the following for the associated EmulateSystem value:
The default value for SystemType is 'Windows 9x/NT', as assigned in the Create constructor.
property UserAccounts: TIdUserManager;
An application can create a TIdUserAccounts class instance for the property to enable use of UserAccounts and its AuthenticateUser, Accounts, and OnAuthentication properties and methods. The application must also free the resources allocated to UserAccount prior to destruction of the object instance.
UserAccounts is used by the command reply handlers for the FTP USER and PASS commands to perform authorization using the user name and password values from the corresponding CommandHandlers. UserAccounts should use its OnAuthenticate event handler to insure that valid accounts are added to the collection maintained by the component. A user account is accessed using the ItemsByUserName property, and provides values that indicate the user name, real name, password, and user-defined attributes associated with the account used by the threaded client connection.
constructor Create(AOwner: TComponent); override;
Create assigns TIdFTPServerThread to the ThreadClass property used for creating new threaded client connections.
Create sets the default values for properties in the FTP server implementation, including:
Create also allocates resources required for properties in the object instance, including the following:
When the FTP Server component is not being used in the IDE, Create will populate CommandHandlers with the TIdCommandHandler instances and command reply event handlers used to implement the FTP commands.
destructor Destroy; override;
property OnAfterUserLogin: TOnAfterUserLoginEvent;
OnAfterUserLogin canbe used to perform server logging, set default values or file system path based on the user account, or to perform additional processing required to maintain state for the client connection. Note: Applications must assign a procedure to the event handler to allow responding to the event notification.
property OnChangeDirectory: TOnDirectoryEvent;
ASender is the threaded client connection for the event notification. ADirectory is the file system path to be selected after execution of the command event handler. ADirectory will contain the directory path after resolving the directory path using the file handling required for the system in EmulateSystem. When triggered for the FTP CDUP command, ADirectory contains the notation required to change to the parent directory in the local file system.
An FTP server implementation must assign a procedure to the event handler to allow responding to the event notifications. The TIdFTPServerThread.CurrentDir property will be updated to the value used by the event handler.
property OnDeleteFile: TOnFileEvent;
property OnGetCustomListFormat: TIdOnGetCustomListFormat;
The event handler for OnGetCustomListFormat is also assigned to the TIdFTPListItems.OnGetCustomListFormat event handler and TIdFTPListItems.ListFormat is given the value flfCustom.
Applications must assign a procedure to the event handler to allow responding to the event notification. The procedure must examine the properties and/or raw data in AItem to generate the textual representation of the directory listing item in VText.
property OnGetFileSize: TOnGetFileSizeEvent;
OnGetFileSize is used when the command event handler is executed after receiving the FTP SIZE command verb from the client connection in ASender. AFileSize will contain the number of bytes in the file specified by AFilename, or -1 when the file size cannot be determined.
property OnListDirectory: TOnListDirectoryEvent;
OnListDirectoryEvent allows the server to examine, validate, or maintain items that appear in the directory listing using the TIdFTPListItems.ListFormat as indicated by EmulateSystem.
OnListDirectoryEvent allows the server to use properties from the connection for the client thread specified in ASender, the current directory in APath, and the collection with file information in ADirectoryListing. The event handler can also add or delete TIdFTPListItem entries in ADirectoryListing. Use the platform-specific API calls needed to retrieve the list of files for the specified directory, and populate the contents of ADirectoryListing.
An FTP server implementation must assign a procedure to the event handler for the TOnListDirectoryEvent event to allow responding to the event notification. When a procedure has not been assigned to the event handler, an EIdTFTPException will be raised.
property OnMakeDirectory: TOnDirectoryEvent;
OnMakeDirectory allows the FTP server to perform the platform-specific API calls needed to create the resolved directory path in ADirectory on the server file system.
An FTP server implementation must assign a procedure to the event handler to allow responding to the event notification.
Use OnRemoveDirectory to implement removal of a directory on the server file system.
property OnRemoveDirectory: TOnDirectoryEvent;
OnRemoveDirectory allows the server to perform the platform-specific API calls need to removed the resolved file directory path specified in ADirectory.
An FTP server implementation must assign a procedure to the event handler to allow responding to the event notification.
property OnRenameFile: TOnRenameFileEvent;
OnRenameFile is examined in the command event handler for the FTP RNFR command verb, and indicates that file renaming can be performed for the FTP server implementation. OnRenameFile is triggered when the command event handler for the FTP RNTO command verb is executed.
OnRenameFile allows the server to peform the platform-specific API calls need to rename the file. ARenameFromFile indicates the orginal file name in the server file system. ARenameToFile indicates the new file name in the server file system.
An FTP server implementation must assign a procedure to the event handler to allow responding to the event notification.
property OnRetrieveFile: TOnRetrieveFileEvent;
OnRetrieveFile allows the server to load the contents of the file specified in AFilename into the stream specified by AStream. OnRetrieveFile must create a stream to use for transferring the contents of the file, and assign the reference to AStream. OnRetrieveFile may also use the default value of AStream (Nil) to indicate that the specified file could not be found, or is not available for transfer to the client connection.
When the stream has been assigned in OnRetrieveFile, the restart position indicated in TIdFTPSErverThread.RESTPos is located in AStream prior to transfer of data on the data channel.
An FTP server implementation must assign a procedure to the event handler to allow responding to the event notification.
property OnStoreFile: TOnStoreFileEvent;
OnStoreFile allows the server to perform the platform-specific API calls needed to load the data for the file specified in AFilename using the stream AStream constructed by the event handler. OnStoreFile responsible for determining if the authenticated client can store files on the local file system, and creating the stream used to load the contents of the file. AAppend indicates that data can be appended to the end of an existing file on the server file system.
An FTP server implementation must assign a procedure to the event handler to allow responding to the event notification.
property OnUserLogin: TOnUserLoginEvent;
OnUserLogin allows the server to perform authentication for the user account using the AUsername and APassword values supplied by the threaded client connection. OnUserLogin is used when the value in TIdFTPServerThread.UserType is utNormalUser, and UserAccounts have not been assigned for authenticating accounts in the server implementation.
OnUserLogin can be used to access resources external to the server to perform account authentication, and must set the value in AAuthenticated to indicate that the client has access to the FTP server.
When the account has been authenticated in the event handler, values in the TIdFTPServerThread client connection are updated to indicate the status and password used in the authorization process.
An FTP server implementation must assign a procedure to the event handler to allow responding to the event notification.
Use OnAfterUserLogin to perform server maintenance required after a successful authentication attempt for the client connection.