FTP downloading files using patterns

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.

Download using wildcard pattern

// C#

using (Ftp ftp = new Ftp())
{
    ftp.Connect("ftp.example.com");    // or ConnectSSL
    
    Directory.CreateDirectory(@"c:\Downloads");

    RemoteSearchOptions options = new RemoteSearchOptions("*.txt", true);
    ftp.DownloadFiles("Uploads", @"c:\Downloads", options);

    ftp.Close();
}
' VB.NET

Using ftp As New Ftp()
    ftp.Connect("ftp.example.com")    ' or ConnectSSL

    Directory.CreateDirectory("c:\Downloads")
    
    Dim options As RemoteSearchOptions = _
        New RemoteSearchOptions("*.txt", True)
    ftp.DownloadFiles("Uploads", "c:\Downloads", options)

    ftp.Close()
End Using

Download using regex pattern

You can also use RemoteSearchOptions.UseRegexMatch method, if you want to use regex patterns on remote names:

// C#

using (Ftp ftp = new Ftp())
{
    ftp.Connect("ftp.example.com");    // or ConnectSSL
    
    Directory.CreateDirectory(@"c:\Downloads");

    RemoteSearchOptions options = new RemoteSearchOptions();
    options.UseRegexMatch(@"^.*$", @"^.*\.txt$", true);
    ftp.DownloadFiles("Uploads", @"c:\Downloads", options);

    ftp.Close();
}
' VB.NET

Using ftp As New Ftp()
    ftp.Connect("ftp.example.com")	' or ConnectSSL

    Directory.CreateDirectory("c:\Downloads")

    Dim options As RemoteSearchOptions = _
        New RemoteSearchOptions()
    options.UseRegexMatch("^.*$", "^.*\.txt$", True)
    ftp.DownloadFiles("Uploads", "c:\Downloads", options)

    ftp.Close()
End Using

Tags:  

Questions?

Consider using our Q&A forum for asking questions.

2 Responses to “FTP downloading files using patterns”

  1. Oren Rosen Says:

    Hello,

    I’m currently in the process of selecting an FTPS component.
    I’ve tested your library and it’s working quite nice.
    When downloading a file, I noticed it does not overwrite if file already exist. Is it possible to add the option to overwrite on download and upload commands?
    (e.g. client.Download(string src, string dst, bool overwrite).

    Regards,
    Oren

  2. Limilabs support Says:

    @Oren

    I’ve just checked the code and I’m sure that Download method overrides existing files.