neubert
neubert

Reputation: 16792

How to determine if you can write to a file with SFTP because of your group?

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?

Upvotes: 1

Views: 266

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202232

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.

Upvotes: 1

Related Questions