List of usage examples for org.apache.commons.net.ftp FTPFile USER_ACCESS
int USER_ACCESS
To view the source code for org.apache.commons.net.ftp FTPFile USER_ACCESS.
Click Source Link
From source file:com.clickha.nifi.processors.util.FTPTransferV2.java
private FileInfo newFileInfo(final FTPFile file, String path) { if (file == null) { return null; }/* w ww.j a v a 2s. c om*/ final File newFullPath = new File(path, file.getName()); final String newFullForwardPath = newFullPath.getPath().replace("\\", "/"); StringBuilder perms = new StringBuilder(); perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-"); perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-"); perms.append(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-"); perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-"); perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-"); perms.append(file.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-"); perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION) ? "r" : "-"); perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION) ? "w" : "-"); perms.append(file.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION) ? "x" : "-"); FileInfo.Builder builder = new FileInfo.Builder().filename(file.getName()) .fullPathFileName(newFullForwardPath).directory(file.isDirectory()).size(file.getSize()) .lastModifiedTime(file.getTimestamp().getTimeInMillis()).permissions(perms.toString()) .owner(file.getUser()).group(file.getGroup()); return builder.build(); }
From source file:it.greenvulcano.util.remotefs.ftp.FTPManager.java
/** * @see it.greenvulcano.util.remotefs.RemoteManager#ls(String, String, date, * int, java.util.Map)// w ww .j a v a2s .c o m */ @Override public Set<FileProperties> ls(String remoteDirectory, String filenamePattern, Date modifiedSince, int fileTypeFilter, Map<String, String> optProperties) throws RemoteManagerException { checkConnected(); Set<FileProperties> resultsSet = new HashSet<FileProperties>(); try { changeWorkingDirectory(remoteDirectory); FTPFile[] results = ftpClient.listFiles(); int detectedFiles = (results != null ? results.length : 0); logger.debug(detectedFiles + " file entries DETECTED into current remote working directory"); if (results != null) { RegExFileFilter fileFilter = new RegExFileFilter(filenamePattern, fileTypeFilter, (modifiedSince != null) ? modifiedSince.getTime() : -1); for (FTPFile currFTPFile : results) { if (currFTPFile != null) { if (fileFilter.accept(currFTPFile)) { FileProperties currFile = new FileProperties(currFTPFile.getName(), currFTPFile.getTimestamp().getTimeInMillis(), currFTPFile.getSize(), currFTPFile.isDirectory(), currFTPFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION), currFTPFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION), currFTPFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); resultsSet.add(currFile); } } else { logger.debug("Remote file entry NULL"); } } } return resultsSet; } catch (Exception exc) { throw new RemoteManagerException("FTP directory scan error", exc); } finally { if (isAutoconnect()) { disconnect(); } } }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
@Test public void testSetuid() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed;//from w w w . j a va 2 s . c om parsed = parser.parseFTPEntry("drwsr--r-- 1 user group 0 Feb 29 18:14 Filename"); assertNotNull(parsed); 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)); }
From source file:lucee.commons.io.res.type.ftp.FTPResource.java
public int getMode() { //if(isRoot()) return 0; FTPResourceClient client = null;//w w w .j ava2 s. c o 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;// w w w . j a v a 2 s . c o 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; }// ww w . j a v a2 s. co 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; }// w w w.j a v a 2s. c o m 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 FsPermission getPermissions(FTPFile ftpFile) { FsAction user, group, others;/*from w w w . ja va 2 s. co m*/ user = getFsAction(FTPFile.USER_ACCESS, ftpFile); group = getFsAction(FTPFile.GROUP_ACCESS, ftpFile); others = getFsAction(FTPFile.WORLD_ACCESS, ftpFile); return new FsPermission(user, group, others); }
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 w w . j a va 2 s . co m*/ 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(); }