1

I want to upload files to remote server via SSH.NET. Users login with their SSH credentials. And then I ask users where they're want to upload files. And then I need to check if there there are read/write permissions on this directory.

How can I check read/write permission on any directory?

I tried SftpFile.OwnerCanWrite/OthersCanWrite/GroupCanWrite but these are not working for current login user.

foreach (var directory in directories)
{
     if (!directory.Name.Equals(directoryName)) continue;

     // I want to check here if is there read/write permission.
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

0

It's not possible to "check" for actual (aka effective) permissions for a specific operation with SFTP protocol. SFTP API does not provide such functionality nor enough information for you to decide on your own.
See also How to check for read permission using JSch with SFTP protocol?

The only way is to actually try to create the file. E.g. using SftpClient.Create method. And after all, that's what you want to do, isn't it?


Alternative solution is to execute a shell command like test -w path to check for the permissions, instead SFTP.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992