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:lucee.runtime.net.ftp.FTPConstant.java

/**
 * @param file/*  ww w. j  a  va 2s  .  co  m*/
 * @return permission as integer
 */
public static Integer getPermissionASInteger(FTPFile file) {
    int rtn = 0;
    // world
    if (file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION))
        rtn += ACCESS_WORLD * PERMISSION_READ;
    if (file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION))
        rtn += ACCESS_WORLD * PERMISSION_WRITE;
    if (file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION))
        rtn += ACCESS_WORLD * PERMISSION_EXECUTE;

    // group
    if (file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION))
        rtn += ACCESS_GROUP * PERMISSION_READ;
    if (file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION))
        rtn += ACCESS_GROUP * PERMISSION_WRITE;
    if (file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION))
        rtn += ACCESS_GROUP * PERMISSION_EXECUTE;

    // user
    if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION))
        rtn += ACCESS_USER * PERMISSION_READ;
    if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION))
        rtn += ACCESS_USER * PERMISSION_WRITE;
    if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION))
        rtn += ACCESS_USER * PERMISSION_EXECUTE;

    return Integer.valueOf(rtn);
}

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

@Test
public void testParse() throws Exception {
    FTPFile parsed;//w w w. j  av a  2s  .c  o  m

    // #3689
    parsed = parser.parseFTPEntry("drwxr-xr-x+  5 niels    staff          7 Sep  6 13:46 data");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "data");
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals(7, parsed.getSize());
    assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

From source file:at.beris.virtualfile.client.ftp.FtpFileTranslator.java

private static Set<FileAttribute> createAttributes(FTPFile ftpFile) {
    Set<FileAttribute> attributeSet = new HashSet<>();

    for (int accessType : new int[] { FTPFile.USER_ACCESS, FTPFile.GROUP_ACCESS, FTPFile.WORLD_ACCESS }) {
        for (int permissionType : new int[] { FTPFile.READ_PERMISSION, FTPFile.WRITE_PERMISSION,
                FTPFile.EXECUTE_PERMISSION }) {
            if (ftpFile.hasPermission(accessType, permissionType)) {
                FileAttribute fileAttribute = calculateAttribute(accessType, permissionType);
                if (fileAttribute != null)
                    attributeSet.add(fileAttribute);
            }/* w w w .ja  v a2s.  c  o  m*/
        }
    }

    return attributeSet;
}

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

@Test
public void testParse() throws Exception {
    FTPFile parsed;/*from   w  ww .j  a  v a2s  .c  o m*/

    parsed = parser.parseFTPEntry("drwxr-xr-x               folder        0 Oct 18 13:02 Akrilik");
    assertNotNull(parsed);
    assertEquals("Akrilik", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(18, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));

    parsed = parser.parseFTPEntry("drwxrwxrwx               folder        0 Oct 11 14:53 Uploads");
    assertNotNull(parsed);
    assertEquals("Uploads", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(11, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));

    parsed = parser.parseFTPEntry("-rw-r--r--        0      589878   589878 Oct 15 13:03 WebDAV SS.bmp");
    assertNotNull(parsed);
    assertEquals("WebDAV SS.bmp", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(15, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

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

@Test
public void testParse() throws Exception {
    FTPFile parsed;/*  w  w  w  .j  a v a 2 s.  c  o  m*/

    //#1213
    parsed = parser.parseFTPEntry("-rw-r--r--  FTP  User       10439 Apr 20 05:29 ASCheckbox_2_0.zip");
    assertNotNull(parsed);
    assertEquals("ASCheckbox_2_0.zip", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(10439, parsed.getSize());
    assertEquals(Calendar.APRIL, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(20, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

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

/**
 * http://trac.cyberduck.ch/ticket/1198//from  w  w  w  .  j av  a  2s .  c o m
 */
@Test
public void testFile() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry("-r--r--r--          0     165100     165100 Aug  1 10:24 grau2.tif");
    assertNotNull(parsed);
    assertEquals("grau2.tif", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(Calendar.AUGUST, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(10, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(24, parsed.getTimestamp().get(Calendar.MINUTE));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

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

@Test
public void testParse() throws Exception {
    FTPFile parsed;//from  w ww. j  av a  2  s  . c  o  m

    parsed = parser.parseFTPEntry("-rwx------          17      332      640 Dec 20 08:54 file 1");
    assertNotNull(parsed);
    assertEquals("file 1", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(640, parsed.getSize());

    parsed = parser.parseFTPEntry("drwx------             folder          2 Dec 20 08:55 folder1");
    assertNotNull(parsed);
    assertEquals("folder1", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(20, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

From source file:at.beris.virtualfile.client.ftp.FtpFileTranslator.java

private static FileAttribute calculateAttribute(int accessType, int permissionType) {
    if (accessType == FTPFile.USER_ACCESS) {
        if (permissionType == FTPFile.READ_PERMISSION)
            return PosixFilePermission.OWNER_READ;
        else if (permissionType == FTPFile.WRITE_PERMISSION)
            return PosixFilePermission.OWNER_WRITE;
        else if (permissionType == FTPFile.EXECUTE_PERMISSION)
            return PosixFilePermission.OWNER_EXECUTE;
    } else if (accessType == FTPFile.GROUP_ACCESS) {
        if (permissionType == FTPFile.READ_PERMISSION)
            return PosixFilePermission.GROUP_READ;
        else if (permissionType == FTPFile.WRITE_PERMISSION)
            return PosixFilePermission.GROUP_WRITE;
        else if (permissionType == FTPFile.EXECUTE_PERMISSION)
            return PosixFilePermission.GROUP_EXECUTE;
    } else if (accessType == FTPFile.WORLD_ACCESS) {
        if (permissionType == FTPFile.READ_PERMISSION)
            return PosixFilePermission.OTHERS_READ;
        else if (permissionType == FTPFile.WRITE_PERMISSION)
            return PosixFilePermission.OTHERS_WRITE;
        else if (permissionType == FTPFile.EXECUTE_PERMISSION)
            return PosixFilePermission.OTHERS_EXECUTE;
    }/*from  w w w  .j  av  a2 s.c  om*/
    return null;
}

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

@Test
public void testParse() {
    FTPFile parsed;/*  www.  ja  v  a 2 s  .com*/

    parsed = parser.parseFTPEntry(
            "-rw-r--r--   1  freebox  freebox 2064965868 Apr 15 21:17 M6 - Capital 15-04-2007 21h37 1h40m.ts");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "M6 - Capital 15-04-2007 21h37 1h40m.ts");
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("freebox", parsed.getUser());
    assertEquals("freebox", parsed.getGroup());
    assertEquals(2064965868, parsed.getSize());
    assertEquals(Calendar.APRIL, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(15, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    parsed = parser.parseFTPEntry(
            "-rw-r--r--   1  freebox  freebox 75906880 Sep 08 06:33 Direct 8 - Gym direct - 08-09-2007 08h30 1h08m.ts");
    assertNotNull(parsed);
    assertEquals("Direct 8 - Gym direct - 08-09-2007 08h30 1h08m.ts", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("freebox", parsed.getUser());
    assertEquals("freebox", parsed.getGroup());
    assertEquals(75906880, parsed.getSize());
    assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(8, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));

    parsed = parser.parseFTPEntry(
            "-rw-r--r--   1  freebox  freebox 1171138668 May 19 17:20 France 3 national - 19-05-2007 18h15 1h05m.ts");
    assertNotNull(parsed);
    assertEquals("France 3 national - 19-05-2007 18h15 1h05m.ts", parsed.getName());
}

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

protected FTPFile parseFTPEntry(String typeStr, String usr, String grp, long filesize, String datestr,
        String name, String endtoken) {
    final FTPExtendedFile file = new FTPExtendedFile();
    int type;/*from w w  w  .j  a v  a 2 s  . com*/
    try {
        file.setTimestamp(this.parseTimestamp(datestr));
    } catch (ParseException e) {
        log.warn(e.getMessage());
    }

    // bcdlfmpSs-
    switch (typeStr.charAt(0)) {
    case 'd':
        type = FTPFile.DIRECTORY_TYPE;
        break;
    case 'l':
        type = FTPFile.SYMBOLIC_LINK_TYPE;
        break;
    case 'b':
    case 'c':
    case 'f':
    case '-':
        type = FTPFile.FILE_TYPE;
        break;
    default:
        type = FTPFile.UNKNOWN_TYPE;
    }

    file.setType(type);
    file.setUser(usr);
    file.setGroup(grp);

    int g = 4;
    for (int access = 0; access < 3; access++, g += 4) {
        // Use != '-' to avoid having to check for suid and sticky bits.
        file.setPermission(access, FTPFile.READ_PERMISSION, (!group(g).equals("-")));
        file.setPermission(access, FTPFile.WRITE_PERMISSION, (!group(g + 1).equals("-")));

        String execPerm = group(g + 2);
        if (execPerm.equals("-")) {
            file.setPermission(access, FTPFile.EXECUTE_PERMISSION, false);
        } else {
            file.setPermission(access, FTPFile.EXECUTE_PERMISSION, Character.isLowerCase(execPerm.charAt(0)));
            if (0 == access) {
                file.setSetuid(execPerm.charAt(0) == 's' || execPerm.charAt(0) == 'S');
            }
            if (1 == access) {
                file.setSetgid(execPerm.charAt(0) == 's' || execPerm.charAt(0) == 'S');
            }
            if (2 == access) {
                file.setSticky(execPerm.charAt(0) == 't' || execPerm.charAt(0) == 'T');
            }
        }
    }

    file.setSize(filesize);

    if (null == endtoken) {
        file.setName(name);
    } else {
        // oddball cases like symbolic links, file names
        // with spaces in them.
        name += endtoken;
        if (type == FTPFile.SYMBOLIC_LINK_TYPE) {

            int end = name.indexOf(" -> ");
            // Give up if no link indicator is present
            if (end == -1) {
                file.setName(name);
            } else {
                file.setName(name.substring(0, end));
                file.setLink(name.substring(end + 4));
            }

        } else {
            file.setName(name);
        }
    }
    return file;
}