List of usage examples for org.apache.commons.net.ftp FTPFile WORLD_ACCESS
int WORLD_ACCESS
To view the source code for org.apache.commons.net.ftp FTPFile WORLD_ACCESS.
Click Source Link
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 ww . j a va 2 s . c om*/ return null; }
From source file:ch.cyberduck.core.ftp.parser.StingrayFTPEntryParserTest.java
/** * http://trac.cyberduck.ch/ticket/1198// w w w. j a v a 2s . 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;/* ww w. j a va 2 s. c om*/ 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 w ww.j av a 2 s.com*/ 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: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 ww w . j a va 2 s .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: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());//from w ww . j av a2 s . c om 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; }
From source file:com.clickha.nifi.processors.util.FTPTransferV2.java
private FileInfo newFileInfo(final FTPFile file, String path) { if (file == null) { return null; }//from w w w .ja v a 2 s.co m 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:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
@Test public void testStickyBit() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed;/*from w w w . ja v a 2 s . c o m*/ 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 w ww .j av a2 s . com 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 .j ava 2s.c om 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); } }