1

You could do mode & 00002 to see if a file is writable by the public and you could get a directory listing and see if the owner of the file matches the user that you logged in with (although stat doesn't usually return the longname for SFTPv3 servers, which is what you'd need to get the username from that) but what about group permissions?

I guess you could create a file on the filesystem, see what it's group is, and see if that group matches the group of the file in question. But what if the group of the file in question is a secondary group that you're a member of? At that point you wouldn't see that group when you received the stat response.

Any ideas?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
neubert
  • 15,947
  • 24
  • 120
  • 212

1 Answers1

1

Just try to open the file for writing. You do not have to write anything to it. If the opening fails with SSH_FX_PERMISSION_DENIED (SSH_FXP_STATUS response), you do not have write permissions.

Use the SSH_FXF_WRITE bit in the pflag field of the SSH_FXP_OPEN request.

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