Set Directory Permissions CHMOD with JSCH

java, jsch

Solution

The file permissions code in Unix (`777`, for example) are octal, not decimal. As in: when you do something like `chmod -R 777`, the digits are interpreted as octal input instead of decimal input.

This system comes from the fact that there are 3 permission groups:

- owner

- group

- world

and each group has an "on/off bit" for:

- read

- write

- execute

so octal-base is sufficient to represent all possible permission configurations for a group. The 3 octal-digits each correspond to a permission group.

(For further reading on this: http://www.december.com/unix/ref/chmod.html)

Back to your problem with JSCH: the decimal integer `775`'s octal representation is `0o1407`, my suspicion is that the decimal 775 is actually sent instead of the octal 775, and FileZilla may very well be truncating the stuff to the left of the 3rd least significant digit of `0o1407` (because it's not unreasonable for it to assume there's nothing past the 3rd least significant bit)

Now, `509` is the decimal representation of octal `775`, try using that with JSCH instead.

Problem

In Unix, how do I set the directory permissions with JSCH? I am looking to do drwxrwxrwx. Filezilla says the integer for that is 775 but JSCH is not setting the permissions correctly. After JSCH sets the permissions Filezilla says that it is 407.

Original source