+1 vote

Hi guys,

is it possible to somehow return filenames of files downloaded using regex pattern?

using (var client = new Ftp())
{
    StartUpFtpConnection(client);

    Directory.CreateDirectory(downloadsDirectory);

    var options = new RemoteSearchOptions();
    options.UseRegexMatch(directoryPattern, filePattern, ignoreCase);
    options.Recursive = recursive;
    client.DownloadFiles(remotePath, downloadsDirectory, options);

    client.Close(); // After this I need to work with downloaded files names
}
by (250 points)

1 Answer

0 votes

Download method doesn't return the list of downloaded files.

You can use Ftp.Search method:

List<RemoteSearchItem> Search(RemoteSearchOptions options)

When you have list with remote items you can download each file yourself:

List<RemoteSearchItem> remote = ftp.Search(options)

// do something with remote list

ftp.DownloadFiles("c:\\", remote);

There is a second option. Subscribe to Ftp.BatchProgress event and use BatchProgressEventArgs.CurrentFile property (it returns remote file name):

List<string> remotes = new List<string>();
client.BatchProgress += (sender, args) => remotes.Add(args.CurrentFile);
by (297k points)
edited by
...