Cancelling asynchonous requests in Rebex SFTP

0 votes
asked May 28, 2020 by stefancgn (260 points)

If I understand the Rebex SFTP documentation correctly, the GetFileAsync, PutAsync and GetListAsync can be cancelled with the AbortTransfer method.

It would be great if those methods (and probably more) would have an overload with a CancellationToken, making it consistent with the .NET Framework APIs.

As a workaround, I created wrapper methods which internally work like this:

var state = Guid.NewGuid();
using (cancellationToken.Register(() => sftp.AbortTransfer(state)))
{
    await sftp.PutFileAsync(stream, remotePath, state);
}

Is this correct usage of the state / AbortTransfer? Unfortunately, the documentation is a little bit thin here.

Thank you in advance!

Applies to: Rebex SFTP

1 Answer

0 votes
answered May 28, 2020 by Lukas Pokorny (123,890 points)
selected Jun 4, 2020 by stefancgn
 
Best answer

Yes, your code is a nice workaround for lack of CancellationToken support.

We plan to extend Rebex SFTP API to support CancellationToken for methods that can be canceled using AbortTransfer method - most likely with the next major update of our API next year.

commented Jun 4, 2020 by stefancgn (260 points)
Great, thank you!
...