问题
I have a user account, but on trying using this am getting exception for rssh. Is there any possibility to give permission of directory using other way other than ChannelExec
. Based on the exception I come to know this account can't use ChannelExec
to give permission of a directory or file. Thus is there any other way this account could give file permission without getting access to this user account for rssh
. Please give you thoughts.
Code :
channelSftp = (ChannelSftp) channel;
ChannelExec channelexe = (ChannelExec) session.openChannel("exec");
channelexe.setCommand("chmod 777 -R " + depDir);
channelexe.connect();
System.out.println("channelexe.getExitStatus:"+channelexe.getExitStatus());
Output :
channelexe.getExitStatus:-1:
This account is restricted by rssh.
Allowed commands: scp sftp
If you believe this is in error, please contact your system administrator.
回答1:
There's no need to use the "exec" channel for this.
Use the ChannelSftp.chmod:
public void chmod(int permissions, String path)
Note that the method takes the permissions as an integer. So you cannot use 777
, as that's an octal representation of the permissions.
An equivalent decimal representation is 511
(=7*8^2 + 7*8^1 + 7*8^0).
See also Decimal to Octal Conversion.
来源:https://stackoverflow.com/questions/33821446/change-file-permissions-with-sftp-or-scp-uing-jsch