I'm currently implementing a SFTP client using Jsch.
For this client I need to check the permissions the logged in user has on the SFTP server in order to check if user is able to perform certain operations. Unfortunately I can't seem to find any documentation or examples in which is shown how to to this.
Thanks in advance.
This code will do what you want:
ChannelSftp channel = (ChannelSftp)session.openChannel("sftp");
SftpATTRS attrs = channel.lstat(fileOnServer)
boolean userHasPermissionsToWriteFile = attrs != null && ((attrs.getPermissions() & 00200) != 0) && attrs.getUId() != 0;
Where
attrs.getUId() != 0
checks that user is not root
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With