0 votes
by (130 points)


I'm using the Rebex SFTP client and I'm managing to upload an entire directory structuring using UploadAsync using the following:

    await sftpClient.UploadAsync(
        localPath: Path.Combine(localPath, "*"),
        remoteDirectoryPath: serverPath,
        traversalMode: Rebex.IO.TraversalMode.Recursive,
        transferMethod: Rebex.IO.TransferMethod.Copy,
        existingFileMode: Rebex.IO.ActionOnExistingFiles.SkipAll);
catch (Exception ex)
    Console.WriteLine($"UPLOAD FAILED: {ex.Message}");

However, if there is a single error (e.g. access is denied on one of the files), the upload fails for all the remaining files.

Is there a way that I can handle the errors and/or specify that they should be ignored?

...or do I have to manually upload each file individually and handle separately?


Applies to: Rebex SFTP, File Server

1 Answer

0 votes
by (70.2k points)


To handle transfer errors please use the Sftp.ProblemDetected event.

For more information and sample of use, please read the Transfer problem handling topic.

In short, it can be done like this:

sftpClient.ProblemDetected += (s, e) =>
    // Log useful information such as:
    // e.LocalPath, e.RemotePath, e.ProblemType, e.Exception
    // ...

    // Skip the problematic file