0 votes
by (160 points)

Hello,
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
by (73.6k 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.

Example:

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);
            break;

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

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

        default:
            throw new InvalidOperationException("Undefined value.");
    }

    // upload files
    client.Upload(set, "/");
}
by (160 points)
Any filters to pick the newer files first for uploading?
by (148k 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.
...