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

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

Introduction

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

Prototype

int USER_ACCESS

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

Click Source Link

Document

A constant indicating user access permissions.

Usage

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

@Test
public void testParse() {
    FTPFile parsed;/*from   www  . j av  a  2s . c om*/

    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.StingrayFTPEntryParserTest.java

/**
 * http://trac.cyberduck.ch/ticket/1198/* w ww  .ja v a 2 s. c o  m*/
 */
@Test
public void testFolder() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry("dr--r--r--                folder          0 Aug  1 10:18 TestCyberduck");
    assertNotNull(parsed);
    assertEquals("TestCyberduck", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_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(18, 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:lucee.commons.io.res.type.ftp.FTPResource.java

private Boolean hasPermission(int permission) {
    FTPResourceClient client = null;/*from  w ww.j  av  a2  s .co m*/
    try {
        provider.read(this);
        client = provider.getClient(data);
        FTPFile file = client.getFTPFile(this);
        if (file == null)
            return null;
        return Caster.toBoolean(file.hasPermission(FTPFile.USER_ACCESS, permission)
                || file.hasPermission(FTPFile.GROUP_ACCESS, permission)
                || file.hasPermission(FTPFile.WORLD_ACCESS, permission));
    } catch (IOException e) {
        return Boolean.FALSE;
    } finally {
        provider.returnClient(client);
    }
}

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

public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {
    cfFTPData ftpdata = getFTPData(_session, argStruct);

    boolean soe = getNamedBooleanParam(argStruct, "stoponerror", true);
    boolean passive = getNamedBooleanParam(argStruct, "passive", false);
    String directory = getNamedStringParam(argStruct, "directory", "/");
    if (!directory.endsWith("/"))
        directory += "/";

    // Perform the directory listing
    FTPFile[] files;/*from ww  w. j  ava  2s.  c o m*/
    try {
        ftpdata.lock();
        ftpdata.setPassive(passive);
        files = ftpdata.listFiles(directory);
        if (soe && !ftpdata.isSucceeded())
            throwException(_session, ftpdata.getErrorText());

    } finally {
        ftpdata.unlock();
    }

    // Returning a query
    cfQueryResultData queryFile = new cfQueryResultData(new String[] { "name", "path", "url", "length",
            "lastmodified", "attributes", "isdirectory", "mode" }, "CFFTP");

    if (!ftpdata.isSucceeded() || files.length == 0)
        return queryFile;

    // Fill out the query
    if (!directory.startsWith("/"))
        directory = "/" + directory;

    List<Map<String, cfData>> resultQuery = new ArrayList<Map<String, cfData>>(files.length);
    for (FTPFile ftpfile : files) {

        Map<String, cfData> HM = new FastMap<String, cfData>();

        HM.put("name", new cfStringData(ftpfile.getName()));
        HM.put("length", new cfNumberData(ftpfile.getSize()));
        HM.put("lastmodified", new cfDateData(ftpfile.getTimestamp().getTime().getTime()));
        HM.put("isdirectory", cfBooleanData.getcfBooleanData(ftpfile.isDirectory()));

        HM.put("path", new cfStringData(directory + ftpfile.getName()));
        HM.put("url", new cfStringData("ftp://" + ftpdata.getServer() + directory + ftpfile.getName()));
        HM.put("attributes", new cfStringData(ftpfile.isDirectory() ? "Directory" : "Normal"));

        String mode = getMode(ftpfile, FTPFile.USER_ACCESS);
        mode += getMode(ftpfile, FTPFile.GROUP_ACCESS);
        mode += getMode(ftpfile, FTPFile.WORLD_ACCESS);
        HM.put("mode", new cfStringData(mode));

        resultQuery.add(HM);
    }

    queryFile.populateQuery(resultQuery);
    return queryFile;
}

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   w  ww . jav a  2s  .co  m*/
}

From source file:hd3gtv.storage.AbstractFileBridgeFtp.java

public boolean canRead() {
    return file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION);
}

From source file:hd3gtv.storage.AbstractFileBridgeFtp.java

public boolean canWrite() {
    if (configurator.readonly) {
        return false;
    }/*from  w w  w  . j  a v  a  2  s. co m*/
    return file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION);
}

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

@Override
public AttributedList<Path> read(final Path directory, final List<String> replies,
        final ListProgressListener listener)
        throws IOException, FTPInvalidListException, ConnectionCanceledException {
    final AttributedList<Path> children = new AttributedList<Path>();
    // At least one entry successfully parsed
    boolean success = false;
    // Call hook for those implementors which need to perform some action upon the list after it has been created
    // from the server stream, but before any clients see the list
    parser.preParse(replies);/*from   www  . j  a  v a  2s  .  c o  m*/
    for (String line : replies) {
        final FTPFile f = parser.parseFTPEntry(line);
        if (null == f) {
            continue;
        }
        final String name = f.getName();
        if (!success) {
            if (lenient) {
                // Workaround for #2410. STAT only returns ls of directory itself
                // Workaround for #2434. STAT of symbolic link directory only lists the directory itself.
                if (directory.getName().equals(name)) {
                    log.warn(String.format("Skip %s matching parent directory name", f.getName()));
                    continue;
                }
                if (name.contains(String.valueOf(Path.DELIMITER))) {
                    if (!name.startsWith(directory.getAbsolute() + Path.DELIMITER)) {
                        // Workaround for #2434.
                        log.warn(String.format("Skip %s with delimiter in name", 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 Path(directory, PathNormalizer.name(name),
                f.getType() == FTPFile.DIRECTORY_TYPE ? EnumSet.of(Path.Type.directory)
                        : EnumSet.of(Path.Type.file));
        switch (f.getType()) {
        case FTPFile.SYMBOLIC_LINK_TYPE:
            parsed.setType(EnumSet.of(Path.Type.file, Path.Type.symboliclink));
            // Symbolic link target may be an absolute or relative path
            final String target = f.getLink();
            if (StringUtils.isBlank(target)) {
                log.warn(String.format("Missing symbolic link target for %s", parsed));
                final EnumSet<AbstractPath.Type> type = parsed.getType();
                type.remove(AbstractPath.Type.symboliclink);
            } else if (StringUtils.startsWith(target, String.valueOf(Path.DELIMITER))) {
                parsed.setSymlinkTarget(new Path(target, EnumSet.of(Path.Type.file)));
            } else if (StringUtils.equals("..", target)) {
                parsed.setSymlinkTarget(directory);
            } else if (StringUtils.equals(".", target)) {
                parsed.setSymlinkTarget(parsed);
            } else {
                parsed.setSymlinkTarget(new Path(directory, target, EnumSet.of(Path.Type.file)));
            }
            break;
        }
        if (parsed.isFile()) {
            parsed.attributes().setSize(f.getSize());
        }
        parsed.attributes().setOwner(f.getUser());
        parsed.attributes().setGroup(f.getGroup());
        Permission.Action u = Permission.Action.none;
        if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)) {
            u = u.or(Permission.Action.read);
        }
        if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)) {
            u = u.or(Permission.Action.write);
        }
        if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
            u = u.or(Permission.Action.execute);
        }
        Permission.Action g = Permission.Action.none;
        if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)) {
            g = g.or(Permission.Action.read);
        }
        if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)) {
            g = g.or(Permission.Action.write);
        }
        if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
            g = g.or(Permission.Action.execute);
        }
        Permission.Action o = Permission.Action.none;
        if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)) {
            o = o.or(Permission.Action.read);
        }
        if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)) {
            o = o.or(Permission.Action.write);
        }
        if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)) {
            o = o.or(Permission.Action.execute);
        }
        final Permission permission = new Permission(u, g, o);
        if (f instanceof FTPExtendedFile) {
            permission.setSetuid(((FTPExtendedFile) f).isSetuid());
            permission.setSetgid(((FTPExtendedFile) f).isSetgid());
            permission.setSticky(((FTPExtendedFile) f).isSticky());
        }
        parsed.attributes().setPermission(permission);
        final Calendar timestamp = f.getTimestamp();
        if (timestamp != null) {
            parsed.attributes().setModificationDate(timestamp.getTimeInMillis());
        }
        children.add(parsed);
    }
    if (!success) {
        throw new FTPInvalidListException(children);
    }
    return children;
}

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);/*  w  w w.j a v a  2 s  . 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:net.sf.jfilesync.plugins.net.items.TCommonsFTP_plugin.java

protected TFileProperties extractFileProperties(FTPFile file, FTPFile[] filesInDir) throws IOException {
    TFileProperties prop = new TFileProperties();

    prop.setFileName(file.getName());// w w w.j  av a  2  s.c o  m

    final String cwd = ftpClient.printWorkingDirectory();
    String fname = null;
    if (cwd.endsWith("/")) {
        fname = cwd + file.getName();
    } else {
        fname = cwd + "/" + file.getName();
    }
    prop.setAbsoluteFileName(fname);

    if (file.getName().startsWith(".")) {
        prop.setHiddenFlag(true);
    }

    // There is a little problem with ftp.getSize(), because it's sometimes
    // 0
    prop.setFileSize(new BigInteger(Long.toString(file.getSize())));
    // System.out.println(file.getName() + " , " + file.getTimestamp());
    prop.setFileModTime(file.getTimestamp().getTimeInMillis());
    // System.out.println("file: " + fname);
    // System.out.println("isDirectory: " + file.isDirectory());
    prop.setDirectoryFlag(file.isDirectory());
    prop.setLinkFlag(file.isSymbolicLink());

    int permissions = 0;

    permissions |= file.isDirectory() ? FilePermissions.S_IFDIR : 0;
    permissions |= file.isSymbolicLink() ? FilePermissions.S_IFLNK : 0;

    permissions |= file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION) ? FilePermissions.S_IRUSR
            : 0;
    permissions |= file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION) ? FilePermissions.S_IWUSR
            : 0;
    permissions |= file.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION) ? FilePermissions.S_IXUSR
            : 0;
    permissions |= file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION) ? FilePermissions.S_IRGRP
            : 0;
    permissions |= file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION) ? FilePermissions.S_IWGRP
            : 0;
    permissions |= file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)
            ? FilePermissions.S_IXGRP
            : 0;
    permissions |= file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION) ? FilePermissions.S_IROTH
            : 0;
    permissions |= file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION) ? FilePermissions.S_IWOTH
            : 0;
    permissions |= file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)
            ? FilePermissions.S_IXOTH
            : 0;

    final TFileAttributes attr = new TFileAttributes();
    attr.setPermissions(permissions);
    prop.setAttributes(attr);

    /*
     * what needs to be done is implement caching of directories which have
     * to be listed for link detection implement recursive link detection
     * for links to links SaHu July 2006
     */

    /*
     * if( file.isSymbolicLink() ) { System.out.println("link target : " +
     * file.getLink()); }
     */

    // if( file.isSymbolicLink() ) {
    // // check if link points to dir
    // final String linkTarget = file.getLink();
    // final String linkTargetBaseName =
    // getPathControl().basename(linkTarget);
    // //System.out.println("link target basename: " + linkTargetBaseName);
    // if( linkTarget != null ) {
    // String linkContaingPath =
    // getPathControl().getPathLevelUp(linkTarget);
    // FTPFile[] targetFiles = null;
    // if( linkContaingPath.equals("") || linkContaingPath.equals(cwd) ) {
    // targetFiles = filesInDir;
    // } else {
    // //System.out.println("check dir : " + linkContaingPath);
    // targetFiles = ftpClient.listFiles(linkContaingPath);
    // }
    //
    //
    // if( targetFiles != null ) {
    // for(int i=0; i<targetFiles.length; i++) {
    // //System.out.println("> " + targetFiles[i].getName());
    // if( targetFiles[i].getName().equals(linkTargetBaseName) ) {
    // if( targetFiles[i].isDirectory() ) {
    // prop.setDirectoryFlag(true);
    // }
    // break;
    // }
    // }
    // }
    // }
    // }

    if (file.isSymbolicLink()) {
        final String linkTarget = file.getLink();
        boolean result = ftpClient.changeWorkingDirectory(linkTarget);
        if (result) {
            prop.setDirectoryFlag(true);
        }
        ftpClient.changeWorkingDirectory(cwd);
    }

    return prop;
}