Provides FTP client functionality.
For a list of all members of this type, see FTPConnection Members.
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
EnterpriseDT.Net.Ftp.FTPConnection
EnterpriseDT.Net.Ftp.ExFTPConnection
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
FTPConnection
provides FTP client functionality. It is a .NET Component which may be used in visual designers, or it may be used as a conventional class.
Constructing and connecting: The constructor for FTPConnection
takes no arguments. Before connecting to a server, the FTPConnection
must be configured with the ServerAddress, UserName and Password. After this has been done, the Connect method should be called, which will connect and log onto the server.
FTPConnection ftp = new FTPConnection(); ftp.ServerAddress = "myservername"; ftp.UserName = "myusername"; ftp.Password = "mypassword"; ftp.Connect(); ftp.Close();The Close method should be called when the required FTP operations have been completed so that the connection to the server is released.
Directory listings: Directory listings may be obtained in two basic forms: (1) The method GetFiles returns strings containing file-names. (2) The method GetFileInfos returns FTPFile objects which contain information about the file including name, size, and date.
Downloading and uploading files: There are many different methods for downloading files from the server and uploading them to the server. Data may be copied from or to:
ExFTPConnection
and SecureFTPConnection
, which are included in EDT's commercial .NET FTP products.
Other file operations: Other operations that may be performed on files are:
Directories: The server maintains a "working directory" for each session. The path of the current working directory may be set and retrieved using the WorkingDirectory property. Changing directory to a subdirectory of the current working directory may be done by setting the same property, or by using the ChangeWorkingDirectory method. Changing up to a parent directory is done using the ChangeWorkingDirectoryUp method. Empty directories may be removed using DeleteDirectory. If a non-empty directory is to be deleted then all the files and subdirectories in it must be deleted first. ExFTPConnection
and SecureFTPConnection
have methods for achieving this in a single method-call.
Events:
FTPConnection
fires events before and after most FTP operations. For example, before a file is downloaded the Downloading event is fired, while it's downloading the BytesTransferred event is fired each time TransferNotifyInterval bytes have been transferred, and after it's been downloaded the Downloaded event is fired. Operations that have corresponding events are:
FTP Operation | Events |
---|---|
Connecting and logging in | Connecting, LoggingIn, LoggedIn, and Connected |
Closing | Closing and Closed |
Downloading data | Downloading, BytesTransferred and Downloaded |
Uploading data | Uploading, BytesTransferred and Uploaded |
Changing directories | DirectoryChanging and DirectoryChanged |
Deleting files/directories | Deleting and Deleted |
Sending FTP commands | CommandSent and ReplyReceived |
Logging: It is often very helpful to look at the detailed logging output if any problems are experienced communicating with FTP servers. All commands sent to the FTP server and subsequent replies are logged, and can be made available on the console or directed to a log file. Much other useful information is also logged.
Operations are logged at different levels, ranging from no logging (Off) to most verbose (All). Intermediate levels are Fatal, Error, Warning and Information.For example, if the overall level is set to Information, then Fatal, Error, Warning and Information log statements will be outputted, but Debug statements will not be logged.
The overall level can be set via the LogLevel property:
ftpConnection.LogLevel = LogLevel.Information;The destination for logging can be set via several properties, described below:
Property | Description |
---|---|
LogToConsole | If set to true , logging is directed to the console. |
LogToTrace | If set to true , logging is directed to .NET's Trace facility. |
LogFile | If to a valid filename, logging is directed to the file. |
Overview of the FTP protocol: FTP is defined in the Request For Comments 959 document (RFC 959), which can be obtained from the Internet Engineering Task Force.
FTP requires a client program (FTP client) and a server program (FTP server). The FTP client can fetch files and file details from the server, and also upload files to the server. The server is generally loginPassword protected.
FTP commands are initiated by the FTP client, which opens a TCP connection called the control connection to the server. This control connection is used for the entire duration of a session between the FTP client and server. A session typically begins when the FTP client logs in, and ends when the quit command is sent to the server. The control connection is used exclusively for sending FTP commands and reading server replies - it is never used to transfer files.
Transient TCP connections called data connections are set up whenever data (normally a file's contents) is to be transferred. For example, the FTP client issues a command to retrieve a file from the server via the control channel. A data connection is then established, and the file's contents transferred to the FTP client across it. Once the transfer is complete, the data connection is closed. Meanwhile, the control connection is maintained.
Compliance: FTPClient implements FTP as defined by RFC959. It attempts to match the standard as closely as possible, but due to variation in the level of compliance of the numerous FTP servers available, it sometime allows servers some tolerance. If the property StrictReturnCodes is set to false
then FTPClient is more tolerant of non-compliant servers.
Namespace: EnterpriseDT.Net.Ftp
Assembly: edtFTPnetCF (in edtFTPnetCF.dll)