How can I set priority to upload or download, Like I want all txt files to download first and then other files?

0 votes
asked Sep 25, 2019 by PrabhuRavi (160 points)

I am happy with how Rebex works, with exclude and include in the fileSet. But If I wanted to upload all txt files first and then upload xml files and the rest of files how can I achieve this?

Applies to: Rebex SFTP

1 Answer

+1 vote
answered Sep 25, 2019 by Lukas Matyska (56,670 points)

Unfortunately, it is not possible using FileSet class. The class only filters the items to process, but it cannot prioritize them.

However, you can do it relatively simply.

  1. Define your FileSet and call GetLocalItems(). You will get the list of all local items to be uploaded (matching the specified set). You can process it and upload files in cycle using the Sftp.PutFile() method.

  2. Or, you can use maybe even easier approach. Call Sftp.Upload() method multiple times for each file extension you want to process.


for (int i = 0; i < 3; i++)
    // define file set
    var set = new FileSet(@"c:\data");
    switch (i)
        case 0:
            set.Include("*.txt", TraversalMode.MatchFilesDeep);

        case 1:
            set.Include("*.xml", TraversalMode.MatchFilesDeep);

        case 2:
            set.Include("*", TraversalMode.MatchFilesDeep);
            set.Exclude("*.txt", TraversalMode.MatchFilesDeep);
            set.Exclude("*.xml", TraversalMode.MatchFilesDeep);

            throw new InvalidOperationException("Undefined value.");

    // upload files
    client.Upload(set, "/");
commented Sep 26, 2019 by PrabhuRavi (160 points)
Any filters to pick the newer files first for uploading?
commented Sep 26, 2019 by Lukas Pokorny (109,270 points)
Unfortunately, this is not supported.
However, you might work around this by calling FileSet's GetLocalItems() method to retrieve the list of matching files, sorting the list yourself, and then iterating over the sorted list and uploading each file separately via client.PutFile method.