Example usage for org.apache.commons.net.ftp FTPFile EXECUTE_PERMISSION

List of usage examples for org.apache.commons.net.ftp FTPFile EXECUTE_PERMISSION

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPFile EXECUTE_PERMISSION.

Prototype

int EXECUTE_PERMISSION

To view the source code for org.apache.commons.net.ftp FTPFile EXECUTE_PERMISSION.

Click Source Link

Document

A constant indicating file execute permission or directory listing permission.

Usage

From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java

@Test
public void testStickyBit() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;//w ww  .  ja va 2s  .  c  om

    parsed = parser.parseFTPEntry("drwxr--r-t   1 user     group          0 Feb 29 18:14 Filename");
    assertNotNull(parsed);
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));

    parsed = parser.parseFTPEntry("drwxr--r-T   1 user     group          0 Feb 29 18:14 Filename");
    assertNotNull(parsed);
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

From source file:lucee.commons.io.res.type.ftp.FTPResource.java

public int getMode() {
    //if(isRoot()) return 0;

    FTPResourceClient client = null;//from  ww  w  .ja va2 s. co  m
    try {
        provider.read(this);
        client = provider.getClient(data);

        FTPFile file = client.getFTPFile(this);
        int mode = 0;
        if (file == null)
            return 0;

        // World
        if (file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION))
            mode += 01;
        if (file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION))
            mode += 02;
        if (file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION))
            mode += 04;

        // Group
        if (file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION))
            mode += 010;
        if (file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION))
            mode += 020;
        if (file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION))
            mode += 040;

        // Owner
        if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION))
            mode += 0100;
        if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION))
            mode += 0200;
        if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION))
            mode += 0400;

        return mode;

    } catch (IOException e) {
    } finally {
        provider.returnClient(client);
    }

    return 0;
}

From source file:lucee.commons.io.res.type.ftp.FTPResource.java

public void setMode(int mode) throws IOException {
    //if(isRoot()) throw new IOException("can't change mode of root");

    FTPResourceClient client = null;/*from w ww.  java 2s.  co  m*/
    try {
        provider.lock(this);
        client = provider.getClient(data);

        FTPFile file = client.getFTPFile(this);
        if (file != null) {
            // World
            file.setPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION, (mode & 01) > 0);
            file.setPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION, (mode & 02) > 0);
            file.setPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION, (mode & 04) > 0);

            // Group
            file.setPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION, (mode & 010) > 0);
            file.setPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION, (mode & 020) > 0);
            file.setPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION, (mode & 040) > 0);

            // Owner
            file.setPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION, (mode & 0100) > 0);
            file.setPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION, (mode & 0200) > 0);
            file.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION, (mode & 0400) > 0);

            client.unregisterFTPFile(this);
        }
    } catch (IOException e) {
    } finally {
        provider.returnClient(client);
        provider.unlock(this);
    }

}

From source file:ch.cyberduck.core.ftp.FTPPath.java

protected boolean parseListResponse(final AttributedList<Path> children, final FTPFileEntryParser parser,
        final List<String> replies) {
    if (null == replies) {
        // This is an empty directory
        return false;
    }//w  w w . j a va 2  s .  c o  m
    boolean success = false;
    for (String line : replies) {
        final FTPFile f = parser.parseFTPEntry(line);
        if (null == f) {
            continue;
        }
        final String name = f.getName();
        if (!success) {
            // Workaround for #2410. STAT only returns ls of directory itself
            // Workaround for #2434. STAT of symbolic link directory only lists the directory itself.
            if (this.getAbsolute().equals(name)) {
                log.warn(String.format("Skip %s", f.getName()));
                continue;
            }
            if (name.contains(String.valueOf(DELIMITER))) {
                if (!name.startsWith(this.getAbsolute() + Path.DELIMITER)) {
                    // Workaround for #2434.
                    log.warn("Skip listing entry with delimiter:" + name);
                    continue;
                }
            }
        }
        success = true;
        if (name.equals(".") || name.equals("..")) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Skip %s", f.getName()));
            }
            continue;
        }
        final Path parsed = new FTPPath(this.getSession(), this.getAbsolute(),
                StringUtils.removeStart(name, this.getAbsolute() + Path.DELIMITER),
                f.getType() == FTPFile.DIRECTORY_TYPE ? DIRECTORY_TYPE : FILE_TYPE);
        parsed.setParent(this);
        switch (f.getType()) {
        case FTPFile.SYMBOLIC_LINK_TYPE:
            parsed.setSymlinkTarget(f.getLink());
            parsed.attributes().setType(SYMBOLIC_LINK_TYPE | FILE_TYPE);
            break;
        }
        if (parsed.attributes().isFile()) {
            parsed.attributes().setSize(f.getSize());
        }
        parsed.attributes().setOwner(f.getUser());
        parsed.attributes().setGroup(f.getGroup());
        if (this.getSession().isPermissionSupported(parser)) {
            parsed.attributes()
                    .setPermission(
                            new Permission(new boolean[][] {
                                    { f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION),
                                            f.hasPermission(FTPFile.USER_ACCESS,
                                                    FTPFile.WRITE_PERMISSION),
                                            f.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION) },
                                    { f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION),
                                            f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION),
                                            f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION) },
                                    { f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION),
                                            f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION),
                                            f.hasPermission(FTPFile.WORLD_ACCESS,
                                                    FTPFile.EXECUTE_PERMISSION) } }));
        }
        final Calendar timestamp = f.getTimestamp();
        if (timestamp != null) {
            parsed.attributes().setModificationDate(timestamp.getTimeInMillis());
        }
        children.add(parsed);
    }
    return success;
}

From source file:nl.esciencecenter.xenon.adaptors.filesystems.ftp.FtpFileSystem.java

private PosixFilePermission getPosixFilePermission(int userType, int permissionType) {
    PosixFilePermission permission = null;
    if (userType == FTPFile.USER_ACCESS) {
        if (permissionType == FTPFile.EXECUTE_PERMISSION) {
            permission = PosixFilePermission.OWNER_EXECUTE;
        }/*  ww w  .  j a v  a 2s  .  c om*/
        if (permissionType == FTPFile.WRITE_PERMISSION) {
            permission = PosixFilePermission.OWNER_WRITE;
        }
        if (permissionType == FTPFile.READ_PERMISSION) {
            permission = PosixFilePermission.OWNER_READ;
        }
    }
    if (userType == FTPFile.GROUP_ACCESS) {
        if (permissionType == FTPFile.EXECUTE_PERMISSION) {
            permission = PosixFilePermission.GROUP_EXECUTE;
        }
        if (permissionType == FTPFile.WRITE_PERMISSION) {
            permission = PosixFilePermission.GROUP_WRITE;
        }
        if (permissionType == FTPFile.READ_PERMISSION) {
            permission = PosixFilePermission.GROUP_READ;
        }
    }
    if (userType == FTPFile.WORLD_ACCESS) {
        if (permissionType == FTPFile.EXECUTE_PERMISSION) {
            permission = PosixFilePermission.OTHERS_EXECUTE;
        }
        if (permissionType == FTPFile.WRITE_PERMISSION) {
            permission = PosixFilePermission.OTHERS_WRITE;
        }
        if (permissionType == FTPFile.READ_PERMISSION) {
            permission = PosixFilePermission.OTHERS_READ;
        }
    }
    return permission;
}

From source file:org.apache.hadoop.fs.ftp.FTPFileSystem.java

private FsAction getFsAction(int accessGroup, FTPFile ftpFile) {
    FsAction action = FsAction.NONE;/*from w  w w  .  j  av a2  s .com*/
    if (ftpFile.hasPermission(accessGroup, FTPFile.READ_PERMISSION)) {
        action.or(FsAction.READ);
    }
    if (ftpFile.hasPermission(accessGroup, FTPFile.WRITE_PERMISSION)) {
        action.or(FsAction.WRITE);
    }
    if (ftpFile.hasPermission(accessGroup, FTPFile.EXECUTE_PERMISSION)) {
        action.or(FsAction.EXECUTE);
    }
    return action;
}

From source file:org.paxle.crawler.ftp.impl.FtpUrlConnection.java

private static void formatStdDirlisting(final OutputStream into, final FTPListParseEngine fileParseEngine) {
    final Formatter writer = new Formatter(into);
    FTPFile[] files;/*  ww  w.  j  a  v  a 2 s . c  om*/
    while (fileParseEngine.hasNext()) {
        files = fileParseEngine.getNext(16);
        for (final FTPFile file : files) {
            if (file == null)
                continue;

            // directory
            char c;
            switch (file.getType()) {
            case FTPFile.DIRECTORY_TYPE:
                c = 'd';
                break;
            case FTPFile.SYMBOLIC_LINK_TYPE:
                c = 's';
                break;
            default:
                c = '-';
                break;
            }
            writer.format("%c", Character.valueOf(c));

            // permissions
            for (final int access : FILE_ACCESS_MODES) {
                writer.format("%c%c%c",
                        Character.valueOf(file.hasPermission(access, FTPFile.READ_PERMISSION) ? 'r' : '-'),
                        Character.valueOf(file.hasPermission(access, FTPFile.WRITE_PERMISSION) ? 'w' : '-'),
                        Character.valueOf(file.hasPermission(access, FTPFile.EXECUTE_PERMISSION) ? 'x' : '-'));
            }

            // other information
            writer.format("  %2d", Integer.valueOf(file.getHardLinkCount()));
            writer.format("  %8s", file.getUser());
            writer.format("  %8s", file.getGroup());
            writer.format("  %12d", Long.valueOf(file.getSize()));
            writer.format("  %1$tY-%1$tm-%1$td %1$tH:%1$tM",
                    Long.valueOf(file.getTimestamp().getTimeInMillis()));
            writer.format("  %s", file.getName());

            writer.format("%s", System.getProperty("line.separator"));
        }
    }

    writer.flush();
}

From source file:org.springframework.integration.ftp.session.FtpFileInfo.java

public String getPermissions() {
    StringBuffer sb = new StringBuffer();
    if (this.ftpFile.isDirectory()) {
        sb.append("d");
    } else if (this.ftpFile.isSymbolicLink()) {
        sb.append("l");
    } else {//from w  ww.  j a  v a  2 s .  com
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)) {
        sb.append("r");
    } else {
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)) {
        sb.append("w");
    } else {
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
        sb.append("x");
    } else {
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)) {
        sb.append("r");
    } else {
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)) {
        sb.append("w");
    } else {
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
        sb.append("x");
    } else {
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)) {
        sb.append("r");
    } else {
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)) {
        sb.append("w");
    } else {
        sb.append("-");
    }
    if (this.ftpFile.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
        sb.append("x");
    } else {
        sb.append("-");
    }
    return sb.toString();
}