@Override
    public void setUnixPermission(final Path file, final TransferStatus status) throws BackgroundException {
        final FileAttributes attr = new FileAttributes.Builder()
                .withPermissions(Integer.parseInt(status.getPermission().getMode(), 8))
                .build();
        try {
            session.sftp().setAttributes(file.getAbsolute(), attr);
        }
        catch(IOException e) {
            throw new SFTPExceptionMappingService().map("Failure to write attributes of {0}", e, file);
        }
    }
@Test
    public void testSetUnixPermission() throws Exception {
        final Path home = new SFTPHomeDirectoryService(session).find();
        {
            final Path file = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
            new SFTPTouchFeature(session).touch(file, new TransferStatus());
            new SFTPUnixPermissionFeature(session).setUnixPermission(file, new Permission(666));
            assertEquals("666", new SFTPListService(session).list(home, new DisabledListProgressListener()).get(file).attributes().getPermission().getMode());
            new SFTPDeleteFeature(session).delete(Collections.<Path>singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
        }
        {
            final Path directory = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory));
            new SFTPDirectoryFeature(session).mkdir(directory, new TransferStatus());
            new SFTPUnixPermissionFeature(session).setUnixPermission(directory, new Permission(666));
            assertEquals("666", new SFTPListService(session).list(home, new DisabledListProgressListener()).get(directory).attributes().getPermission().getMode());
            new SFTPDeleteFeature(session).delete(Collections.<Path>singletonList(directory), new DisabledLoginCallback(), new Delete.DisabledCallback());
        }
    }