List of usage examples for org.apache.commons.net.ftp FTPFile SYMBOLIC_LINK_TYPE
int SYMBOLIC_LINK_TYPE
To view the source code for org.apache.commons.net.ftp FTPFile SYMBOLIC_LINK_TYPE.
Click Source Link
From source file:lucee.runtime.net.ftp.FTPConstant.java
/** * @param type//from w ww .ja va 2s .c om * @return file type as String */ public static String getTypeAsString(int type) { if (type == FTPFile.DIRECTORY_TYPE) return "directory"; else if (type == FTPFile.SYMBOLIC_LINK_TYPE) return "link"; else if (type == FTPFile.UNKNOWN_TYPE) return "unknown"; else if (type == FTPFile.FILE_TYPE) return "file"; return "unknown"; }
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;// w w w .j ava 2s .c o m 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; }
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 w w w.j a v a 2 s . com 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.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;//from www. ja v a2 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:au.org.intersect.dms.wn.transports.impl.FtpConnection.java
private FileInfo makeFileInfo(String parentPath, FTPFile info) { Date date = info.getTimestamp().getTime(); int ftpType = info.getType(); if (ftpType == FTPFile.SYMBOLIC_LINK_TYPE) { try {//from w w w. jav a2 s . c o m changeWorkingDirectory(PathUtils.joinPath(parentPath, info.getName())); ftpType = FTPFile.DIRECTORY_TYPE; } catch (IOException e) { throw new TransportException("Cannot get list directory (" + info.getName() + ")"); } catch (PathNotFoundException e) { ftpType = FTPFile.FILE_TYPE; } } FileType type = ftpType == FTPFile.DIRECTORY_TYPE ? FileType.DIRECTORY : FileType.FILE; FileInfo item = new FileInfo(type, PathUtils.joinPath(parentPath, info.getName()), info.getName(), info.getSize(), date); return item; }
From source file:com.ai.api.util.UnixFTPEntryParser.java
/** * Parses a line of a unix (standard) FTP server file listing and converts * it into a usable format in the form of an <code> FTPFile </code> * instance. If the file listing line doesn't describe a file, * <code> null </code> is returned, otherwise a <code> FTPFile </code> * instance representing the files in the directory is returned. * <p>// w w w. j a va 2s. com * @param entry A line of text from the file listing * @return An FTPFile instance corresponding to the supplied entry */ public FTPFile parseFTPEntry(String entry) { FTPFile file = new FTPFile(); file.setRawListing(entry); int type; boolean isDevice = false; if (matches(entry)) { String typeStr = group(1); String hardLinkCount = group(15); String usr = group(16); String grp = group(17); String filesize = group(18); String datestr = group(19) + " " + group(20); String name = group(21); String endtoken = group(22); try { //file.setTimestamp(super.parseTimestamp(datestr)); FTPTimestampParserImplExZH Zh2En = new FTPTimestampParserImplExZH(); file.setTimestamp(Zh2En.parseTimestamp(datestr)); } catch (ParseException e) { //logger.error(e, e); //return null; // this is a parsing failure too. //logger.info(entry+":??"); file.setTimestamp(Calendar.getInstance()); } // bcdlfmpSs- switch (typeStr.charAt(0)) { case 'd': type = FTPFile.DIRECTORY_TYPE; break; case 'l': type = FTPFile.SYMBOLIC_LINK_TYPE; break; case 'b': case 'c': isDevice = true; // break; - fall through case 'f': case '-': type = FTPFile.FILE_TYPE; break; default: type = FTPFile.UNKNOWN_TYPE; } file.setType(type); 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("-") && !Character.isUpperCase(execPerm.charAt(0))) { file.setPermission(access, FTPFile.EXECUTE_PERMISSION, true); } else { file.setPermission(access, FTPFile.EXECUTE_PERMISSION, false); } } if (!isDevice) { try { file.setHardLinkCount(Integer.parseInt(hardLinkCount)); } catch (NumberFormatException e) { // intentionally do nothing } } file.setUser(usr); file.setGroup(grp); try { file.setSize(Long.parseLong(filesize)); } catch (NumberFormatException e) { // intentionally do nothing } 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; } else { logger.info("matches(entry) failure:" + entry); } return null; }
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; }/*from w ww .j a v a 2 s .c o 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
@Override public Path readSymbolicLink(Path path) throws XenonException { Path absPath = toAbsolutePath(path); FTPFile file = getFTPFileInfo(absPath); if (file.getType() != FTPFile.SYMBOLIC_LINK_TYPE) { throw new InvalidPathException(ADAPTOR_NAME, "Path is not a symbolic link: " + absPath); }/*from www . j a v a 2 s .co m*/ return new Path(file.getLink()); }
From source file:org.paxle.crawler.ftp.impl.FtpUrlConnection.java
private static void formatStdDirlisting(final OutputStream into, final FTPListParseEngine fileParseEngine) { final Formatter writer = new Formatter(into); FTPFile[] files;// w ww. j a v a 2 s .c o m while (fileParseEngine.hasNext()) { files = fileParseEngine.getNext(16); for (final FTPFile file : files) { if (file == null) continue; // directory char c; switch (file.getType()) { case FTPFile.DIRECTORY_TYPE: c = 'd'; break; case FTPFile.SYMBOLIC_LINK_TYPE: c = 's'; break; default: c = '-'; break; } writer.format("%c", Character.valueOf(c)); // permissions for (final int access : FILE_ACCESS_MODES) { writer.format("%c%c%c", Character.valueOf(file.hasPermission(access, FTPFile.READ_PERMISSION) ? 'r' : '-'), Character.valueOf(file.hasPermission(access, FTPFile.WRITE_PERMISSION) ? 'w' : '-'), Character.valueOf(file.hasPermission(access, FTPFile.EXECUTE_PERMISSION) ? 'x' : '-')); } // other information writer.format(" %2d", Integer.valueOf(file.getHardLinkCount())); writer.format(" %8s", file.getUser()); writer.format(" %8s", file.getGroup()); writer.format(" %12d", Long.valueOf(file.getSize())); writer.format(" %1$tY-%1$tm-%1$td %1$tH:%1$tM", Long.valueOf(file.getTimestamp().getTimeInMillis())); writer.format(" %s", file.getName()); writer.format("%s", System.getProperty("line.separator")); } } writer.flush(); }