0 votes
by (130 points)

Hi,

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

try
{
    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?

Thanks,

Applies to: Rebex SFTP, File Server

1 Answer

0 votes
by (73.5k points)

Hello,

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
    e.Skip();
};
...