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

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

Introduction

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

Prototype

public boolean hasPermission(int access, int permission) 

Source Link

Document

Determines if the given access group (one of the _ACCESS constants) has the given access permission (one of the _PERMISSION constants) to the file.

Usage

From source file:lucee.runtime.net.ftp.FTPConstant.java

/**
 * @param file//  w  w  w  .ja  v  a  2s . com
 * @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:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java

private static EnumSet<AccessMode> calculateAccess(final FTPFile file) {
    final EnumSet<AccessMode> ret = EnumSet.noneOf(AccessMode.class);
    if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION))
        ret.add(AccessMode.READ);
    if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION))
        ret.add(AccessMode.WRITE);
    if (file.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION))
        ret.add(AccessMode.EXECUTE);
    return ret;/*from  ww  w.j  a v  a2 s  .c  o  m*/
}

From source file:com.jaeksoft.searchlib.crawler.file.process.fileInstances.FtpFileInstance.java

public static List<SecurityAccess> getSecurity(FTPFile ftpFile) {
    List<SecurityAccess> accesses = new ArrayList<SecurityAccess>();
    if (ftpFile == null)
        return accesses;
    if (ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)) {
        SecurityAccess access = new SecurityAccess();
        access.setGrant(SecurityAccess.Grant.ALLOW);
        access.setType(SecurityAccess.Type.USER);
        access.setId(ftpFile.getUser());
        accesses.add(access);/*from w  ww.  ja  v a 2s  .  c o m*/
    }

    if (ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)) {
        SecurityAccess access = new SecurityAccess();
        access.setGrant(SecurityAccess.Grant.ALLOW);
        access.setType(SecurityAccess.Type.GROUP);
        access.setId(ftpFile.getGroup());
        accesses.add(access);
    }

    return accesses;
}

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);
            }//from   w  w w.  jav a 2s.c  om
        }
    }

    return attributeSet;
}

From source file:com.naryx.tagfusion.cfm.tag.net.ftp.FtpList.java

private String getMode(FTPFile ftpfile, int access) {
    int octet = 0;

    if (ftpfile.hasPermission(access, FTPFile.READ_PERMISSION))
        octet += 4;/*  w w  w  . ja  va  2 s.c  o m*/
    if (ftpfile.hasPermission(access, FTPFile.WRITE_PERMISSION))
        octet += 2;
    if (ftpfile.hasPermission(access, FTPFile.SYMBOLIC_LINK_TYPE)
            || ftpfile.hasPermission(access, FTPFile.EXECUTE_PERMISSION))
        octet += 1;

    return octet + "";
}

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

@Test
public void testParse() throws Exception {
    FTPFile parsed;

    // #3689// w  w w  .  j  a  v  a 2 s.  co  m
    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:ch.cyberduck.core.ftp.parser.vsFTPdEntryParserTest.java

@Test
public void testParse() throws Exception {
    FTPFile parsed;

    // #5437/*from   ww w.  jav  a 2 s. co  m*/
    parsed = parser.parseFTPEntry("-rw-r--r--    1 3642     3643          106 Nov 15 22:20 index.html");
    assertNotNull(parsed);
    assertEquals("index.html", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(106, parsed.getSize());
    assertEquals(Calendar.NOVEMBER, 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));
}

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

@Test
public void testParse() throws Exception {
    FTPFile parsed;

    // #3119/*from  w w w .  j av  a2  s .  co m*/
    parsed = parser.parseFTPEntry("-rw-r--r-- 1 ftp ftp         100847 Sep 10  2004 octfront2.jpg");
    assertNotNull(parsed);
    assertEquals("octfront2.jpg", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(100847, parsed.getSize());
    assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(10, 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));
}

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

@Test
public void testParse() throws Exception {
    FTPFile parsed;

    //#1213/*from   ww  w  .  j  a va  2s.  co m*/
    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.UnixFTPEntryParserTest.java

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

    FTPFile parsed;

    parsed = parser.parseFTPEntry("drwsr--r--   1 user     group          0 Feb 29 18:14 Filename");
    assertNotNull(parsed);//ww  w. java2 s.  c o  m
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));

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