edtFTPnet/PRO - Secure FTP component for .NET | Free Trial | Pricing

How to transfer multiple files and directories

edtFTPnet/PRO is able to download and upload multiple files and directories in a single method call.

These capabilities are not available in FTPConnection, but are in ExFTPConnection and SecureFTPConnection.

The relevant methods are listed below:

void DownloadMultiple(string localDir, string remoteDir, string wildcard, bool includeSubDirs)
	void DownloadMultiple(string localDir, string remoteDir, FileFilter filter, bool includeSubDirs)
	void UploadMultiple(string localDir, string remoteDir, string wildcard, bool includeSubDirs)
	void UploadMultiple(string localDir, string  remoteDir, FileFilter filter, bool includeSubDirs)

The arguments to each of these methods are (1) the path of the directory in the local file- system, (2) the path of the directory on the server, (3) a wildcard or a FileFilter, and (4) a flag indicating whether or not to include subdirectories.

The wildcard argument is a string that may contain markers for unknown characters.  The question-mark (?) character matches a single unknown character.  The asterisk (*) character matches one or more unknown character.  For example, the wildcard "file*.dat" would match the following strings, "file1.dat", "file10.dat", "fileA.dat", and "fileABC.dat", whereas the wildcard "file?.dat" would match the following strings, "file1.dat" and "fileA.dat", but not "file10.dat" and "fileABC.dat".

FileFilter is somewhat more complex, but also a lot more powerful.  It is a delegate, so it may be used to reference a method.  It takes an FTPFile object as an argument and returns a bool.  The FTPFile object describes a local file when uploading and a remote file when downloading.  This method must have the following signature:

bool MethodName(FTPFile file)

where MethodName can be any valid method-name.

As an example, if one wanted to download any files less than 1000 bytes, then one would define the following method:

bool IsFileSmall(FTPFile file)
	{
		return file.Size<=1000;
	}

and would then use it as follows:

ftpConnection.DownloadMultiple(localDir, remoteDir, new FileFilter(IsFileSmall), false);

In this case, the final bargument is false meaning that only file from the directory specified by remoteDir will be downloaded and files in subdirectories will be bypassed.