sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
3.88k stars 919 forks source link

Renci.SshNet.Common.SshException: Failed to open local file #1309

Open paritoshnagar2016 opened 4 months ago

paritoshnagar2016 commented 4 months ago

I have been seeing below error while downloading file from SFTP and I am unsure why it throw below exception, what does that signifies?

Renci.SshNet.Common.SshException: Failed to open local file at Renci.SshNet.Common.AsyncResult.EndInvoke() at Renci.SshNet.Sftp.SftpSession.EndOpen(SftpOpenAsyncResult asyncResult) at Renci.SshNet.ServiceFactory.CreateSftpFileReader(String fileName, ISftpSession sftpSession, UInt32 bufferSize) at Renci.SshNet.SftpClient.InternalDownloadFile(String path, Stream output, SftpDownloadAsyncResult asyncResult, Action`1 downloadCallback)

Rob-Hague commented 4 months ago

I think that message "Failed to open local file" is coming from your server, so you might start there if you have access.

You might be able to get some more information from the client-side but unfortunately it's not easy with the current version. I think basically you are receiving a SftpStatusResponse defined here:

https://github.com/sshnet/SSH.NET/blob/develop/src/Renci.SshNet/Sftp/Responses/SftpStatusResponse.cs

The ErrorMessage property corresponds to your "Failed to open local file message" message. The StatusCode property might contain more pertinent information. Unfortunately all this stuff is internal currently, but you could probably access it with a local build of the library and some crafty debugging.