0 votes
by (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
by (144k points)

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

by (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.
by (144k points)
If GetDownloadStream(remotePath) works fine, then GetStream(remotePath, FileMode.Open, FileAccess.Read) should work as well. Can you give that a try?
by (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!
by (120 points)
I've been confirmed that the user that I use only have read permisions.

Thank you very much for your support
by (144k points)
Thanks for letting us know!
GetStream uses FileAccess.ReadWrite by default (except for FileMode.Append, which defaults to FileAccess.Write).
...