edtFTPnet/Free - Open-source FTP component for .NET | Download
Provides FTP client functionality.

Namespace: EnterpriseDT.Net.Ftp
Assembly: edtFTPnet (in edtFTPnet.dll) Version:


public class FTPConnection : Component, 
Visual Basic
Public Class FTPConnection _
	Inherits Component _
	Implements IFTPComponent
Visual C++
public ref class FTPConnection : public Component, 


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.

 Copy imageCopy
              FTPConnection ftp = new FTPConnection();
              ftp.ServerAddress = "myservername";
              ftp.UserName = "myusername";
              ftp.Password = "mypassword";
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(String) returns strings containing file-names. (2) The method GetFileInfos(String) 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:

  1. Files (DownloadFile(String, String) and UploadFile(String, String)
  2. Streams (DownloadStream(Stream, String) and UploadStream(Stream, String))
  3. Byte-arrays (DownloadByteArray(String) and UploadByteArray(array<Byte>[]()[][], String)
Methods for downloading and uploading multiple files and directories are available in 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(String) method. Changing up to a parent directory is done using the ChangeWorkingDirectoryUp()()()() method. Empty directories may be removed using DeleteDirectory(String). 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 OperationEvents
Connecting and logging inConnecting, LoggingIn, LoggedIn, and Connected
ClosingClosing and Closed
Downloading dataDownloading, BytesTransferred and Downloaded
Uploading dataUploading, BytesTransferred and Uploaded
Changing directoriesDirectoryChanging and DirectoryChanged
Deleting files/directoriesDeleting and Deleted
Sending FTP commandsCommandSent 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:

 Copy imageCopy
              ftpConnection.LogLevel = LogLevel.Information;
The destination for logging can be set via several properties, described below:
LogToConsoleIf set to true, logging is directed to the console.
LogToTraceIf set to true, logging is directed to .NET's Trace facility.
LogFileIf 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.

Inheritance Hierarchy


See Also