how to set chmod permission in java jsch channelsftp setPermission(int permission, String path)

流过昼夜 提交于 2020-01-05 03:33:32

问题


How can I convert a chmod value like 755 so it fits in channelSftp setPermission(int permission, String path)?

I can't figure it out. :(

EDIT: Here it says I'm suppose to use a bitmask. But I'm not sure how that would be done either. http://epaul.github.com/jsch-documentation/javadoc/com/jcraft/jsch/SftpATTRS.html#setPERMISSIONS(int)


回答1:


Permission perm = new Permission();
//set the permissions you want.
setPermission(perm.getDecimalCode(), path);

You can get the Permission class from here:

http://svn.cyberduck.ch/tags/release-2-3/source/ch/cyberduck/core/Permission.java




回答2:


I know that it's digging up an old grave but I have better solution - SftpChannel.chmod expects decimal integer while unix format (644, 777 etc.) is octal. All you have to do is simple conversion:

SftpChannel.chmod(Integer.parseInt(""+, 8), path);




回答3:


channelSftp.chown(0755, f.getName());


来源:https://stackoverflow.com/questions/12582444/how-to-set-chmod-permission-in-java-jsch-channelsftp-setpermissionint-permissio

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