With Java 7+, you can do this; The code below, of course, assumes a configuration similar to yours that these are POSIX-compatible file systems at both ends.
The trick is to get a set of POSIX file permissions for the file; this is done with:
// "fileToCopy" here is a Path; see Paths.get() Files.getPosixFilePermissions(fileToCopy)
This will return a Set<PosixFilePermissions> , which is actually an enumeration. Converting an enumeration to an integer is done using the following trick:
private static int toIntPermissions(final Set<PosixFilePermission> perms) { int ret = 0; for (final PosixFilePermission perm: PosixFilePermission.values()) { if (perms.contains(perm)) ret++;
Regarding the direct saving of copy permissions, this is not possible in one command: SSH does not guarantee that the file system at the remote end supports them, but it recognizes the existence of such file systems, so it offers a dedicated command to set permissions at the remote end explicitly.
fge
source share