0 votes
by (630 points)

Does the SFTP members GetFile() and PutFile() throw exceptions?

Applies to: Rebex SFTP

1 Answer

0 votes
by (144k points)

Yes, these and other Sftp methods throw exceptions when an error is encountered, and these exceptions are of 3 kinds:

  1. ArgumentException, InvalidOperationException and ObjectDisposedException
    These exceptions are thrown where one would expect it.

  2. SftpException
    These exceptions covers all exceptional states of SFTP operations. Their Status property can be used to determine what kind of error occurred.

  3. IOException, UnauthorizedAccessException, PathTooLongException, SecurityException
    These exceptions are thrown by method that work with the file system when a related error occurs.

Other than this, no other exceptions should be thrown by Rebex SFTP. However, lower level APIs from Rebex.Networking or Rebex.Common assembly might use other exceptions such as SshException, CertificateException or CryptographicException.

by (630 points)
Thanks Lukas.
Is it documented in the API? Where can I find the exceptions thrown for a given method?
by (144k points)
by (630 points)
During file transfer, when SFTP server stops then what happens - ProblemDetected event will be raised or exception thrown?
In my case, neither the event nor exception is thrown?
by (70.2k points)
What do you mean by "SFTP server stops"?

1. If the SFTP server terminates and all connections are aborted. You will get SftpException with status: SocketError.

2. If the SFTP server stops and it is not responding. You will get SftpException with status: Timeout. You can set timeout using Sftp.Timeout property (default is 60 seconds).
by (630 points)
I didn't receive any exception when I used the Rebex Tiny SFTP server. Is it the behavior of this server?
by (144k points)
No. When you stop Rebex Tiny SFTP server, it aborts all active connections, which means that GetFile or PutFile methods should fail. Would it be possible to let us know how to reproduce the issue you encountered?
by (630 points)
I had set a breakpoint in my progress update event and when it was 50% downloaded, I stopped the Tiny SFTP server. No exception / failure event was raised.
by (144k points)
I tried reproducing this issue, but the behavior I observed was correct. This is what I tried exactly:
1. Launched Tiny SFTP Server.
2. Opened SftpWinFormClient sample in Visual Studio. Started it in debug mode and connected to Tiny SFTP Server. Browserd into a directory with a long file.
3. Put conditional breakpoint at the first line of TransferProgressChanged method in MainForm.cs file with 'e.ProgressPercentage > 50' condition.
4. Started downloading the long file.
5. When the breakpoint got hit, I pressed the 'Stop' button in Tiny SFTP Server.
6. SftpWinFormClient failed with exception: 'Rebex.Net.SftpException: The server has closed the connection.'

Please give this a try as well and let me know whether you got the exception or not.
...