Downloading files using patters is a unique feature of our FTP .NET component. It allows you fast download of files of certain types.
Here’s the sample that download all text files (*.txt) files from remote Uploads folder to Downloads folder located on C drive. Remote search includes all child folders recursively – note the true parameter in RemoteSearchOptions constructor. Ftp component is going to create all necessary folders on the local computer.
// C# using (Ftp ftp = new Ftp()) { ftp.Connect("ftp.example.com"); // or ConnectSSL Directory.CreateDirectory(@"c:\Downloads"); ftp.DownloadFiles("Uploads", @"c:\Downloads", new RemoteSearchOptions("*.txt", true)); ftp.Close(); }
' VB.NET Using ftp As New Ftp() ftp.Connect("ftp.example.com") ' or ConnectSSL Directory.CreateDirectory("c:\Downloads") ftp.DownloadFiles("Uploads", "c:\Downloads", New RemoteSearchOptions("*.txt", True)) ftp.Close() End Using
You can also set RemoteSearchOptions.UseRegex property to true, if you want to use regex patterns on remote names:
// C# RemoteSearchOptionsoptions = new RemoteSearchOptions(@"^.*\.txt$", true); options.FolderPattern = @"^.*$"; options.UseRegex = true; ftp.DownloadFiles("Uploads", @"c:\Downloads", options);
' VB.NET Dim options As New RemoteSearchOptions("^.*\.txt$", True) options.FolderPattern = "^.*$" options.UseRegex = True ftp.DownloadFiles("Uploads", "c:\Downloads", options)