Sftp.GetStream throws Permision Denied exception

0 votes
asked Jun 18 by JorgeFD (120 points)

When I try to Open a Read stream using the Sftp.GetStream function I get an exception indicating PermissionDenied exception.
I've been able to download the file using the Download function an I've been able to open a Stream to the file using a different SFTP library. So the permissions are correct, cause I've been able to read and delete the file.

This only happens in a particular server, the same line works fine with other servers. I don't have information of this particular server, but I know it runs under a Linux machine, while the working servers are Bitvise servers under Windows.

Both IsConnected and IsAuthenticated returned true before calling the function.

This is the exception information:
Sftp ProblemType: 0.
ProtocolCode: 3.
Message: Permission denied.
Code: PermissionDenied.
ToString: Rebex.Net.SftpException: Permission denied; Permission denied. at utgp.mjcj(yffv arx, Type ary) at utgp.mjbk(String aom, uthq aon, Boolean aoo, utfz aop) at Rebex.Net.Sftp.pntx(String ur, uthq us, utfz ut)

Applies to: Rebex SFTP

1 Answer

0 votes
answered Jun 18 by Lukas Pokorny (116,670 points)

Please try using Sftp.GetDownloadStream method instead of Sftp.GetStream. Does that work, or does it fail with 'Permission denied' error as well?

commented Jun 18 by JorgeFD (120 points)
The GetDownloadStream seams to works just fine.

Now i'm worried because in other parts of the program I use GetStream to open a Write Stream, and the GetUploadStream won't allow me to choose the fileMode. Sometimes I want to override an existing file and others I need to throw an error.
commented Jun 18 by Lukas Pokorny (116,670 points)
If GetDownloadStream(remotePath) works fine, then GetStream(remotePath, FileMode.Open, FileAccess.Read) should work as well. Can you give that a try?
commented Jun 18 by JorgeFD (120 points)
GetStream(remotePath, FileMode.Open, FileAccess.Read) works fine, GetStream(remotePath, FileMode.Open, FileAccess.ReadWrite) fails with PermisionDenied.

GetStream uses ReadWrite by default? I should have write permisions, but I'm not so sure about that, I'm gonna ask to the admins of the SFTP if my user is in the group of the owner.

Thank you!
commented Jun 18 by JorgeFD (120 points)
I've been confirmed that the user that I use only have read permisions.

Thank you very much for your support
commented Jun 18 by Lukas Pokorny (116,670 points)
Thanks for letting us know!
GetStream uses FileAccess.ReadWrite by default (except for FileMode.Append, which defaults to FileAccess.Write).
...