Change file permissions with SFTP or SCP uing JSch

↘锁芯ラ 提交于 2020-01-04 05:30:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!