List of usage examples for org.apache.commons.net.ftp FTPFile getGroup
public String getGroup()
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
/** * http://trac.cyberduck.ch/ticket/1076/*from www .java 2 s. c o m*/ * * @ */ @Test public void testSizeWithIndicator() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed; parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 9.0M Mar 22 17:44 Cyberduck-2.7.3.dmg"); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals("Cyberduck-2.7.3.dmg", parsed.getName()); assertEquals((long) (9.0 * 1048576), parsed.getSize()); assertEquals(parsed.getUser(), "ftp"); assertEquals(parsed.getGroup(), "operator"); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(22, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 61.8M Mar 7 18:42 GC Wayfinding pics.zip "); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals((long) (61.8 * 1048576), parsed.getSize()); assertEquals("ftp", parsed.getUser()); assertEquals("operator", parsed.getGroup()); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(7, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 172.4k Mar 7 16:01 HEALY071.TXT "); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals((long) (172.4 * 1024), parsed.getSize()); assertEquals(parsed.getUser(), "ftp"); assertEquals(parsed.getGroup(), "operator"); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(7, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
@Test public void testMVSParser() { FTPFileEntryParser parser = new FTPParserSelector() .getParser("MVS is the operating system of this server. FTP Server is running on z/OS."); FTPFile parsed; final String entry = "drwxr-xr-x 6 START2 SYS1 8192 Oct 28 2008 ADCD"; parser.preParse(new ArrayList<String>(Arrays.asList("total 66", entry))); // #7717/*from ww w . j a v a2s .c o m*/ parsed = parser.parseFTPEntry(entry); assertNotNull(parsed); assertEquals("ADCD", parsed.getName()); assertEquals("START2", parsed.getUser()); assertEquals("SYS1", parsed.getGroup()); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(28, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(2008, parsed.getTimestamp().get(Calendar.YEAR)); }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
public void testUnknownTimestampFormat() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed; parsed = parser.parseFTPEntry(//from w ww . jav a 2 s.c o m "-rw-rw-rw- 1 hoerspiel hoerspiel 3722053 19. Sep 13:24 Offenbarung 23 - Menschenopfer - 02.mp3"); assertNotNull(parsed); assertEquals(parsed.getName(), "Offenbarung 23 - Menschenopfer - 02.mp3"); parsed = parser.parseFTPEntry( "-rw-rw-rw- 1 hoerspiel hoerspiel 10128531 19. Sep 13:24 Offenbarung 23 - Menschenopfer - 01.mp3"); assertNotNull(parsed); assertEquals(parsed.getName(), "Offenbarung 23 - Menschenopfer - 01.mp3"); parsed = parser.parseFTPEntry( "-rw-rw-rw- 1 hoerspiel hoerspiel 11714687 19. Sep 13:25 Offenbarung 23 - Menschenopfer - 08.mp3"); assertNotNull(parsed); assertEquals(parsed.getName(), "Offenbarung 23 - Menschenopfer - 08.mp3"); parsed = parser.parseFTPEntry("-rw-r--r-- 1 www-data www-data 10089849 Dec 20 09:30 Stone Catalog"); assertNotNull(parsed); assertEquals(parsed.getName(), "Stone Catalog"); assertEquals(parsed.getUser(), "www-data"); assertEquals(parsed.getGroup(), "www-data"); assertEquals(parsed.getSize(), 10089849); parsed = parser.parseFTPEntry( "-rw-r--r-- 1 www-data www-data 34524204 Dec 20 13:41 Winter 2008 Newsletter.sit"); assertNotNull(parsed); assertEquals(parsed.getName(), "Winter 2008 Newsletter.sit"); assertEquals(parsed.getUser(), "www-data"); assertEquals(parsed.getGroup(), "www-data"); assertEquals(parsed.getSize(), 34524204); }
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 ww . jav a2 s . c o 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.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 a 2s . c om*/ 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: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 ww . j a va2s.co 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:nl.esciencecenter.xenon.adaptors.filesystems.ftp.FtpFileSystem.java
private PathAttributes convertAttributes(Path path, FTPFile attributes) { PathAttributesImplementation result = new PathAttributesImplementation(); result.setPath(path);/* ww w . j a v a 2s.c om*/ result.setDirectory(attributes.isDirectory()); result.setRegular(attributes.isFile()); result.setOther(attributes.isUnknown()); result.setSymbolicLink(attributes.isSymbolicLink()); result.setLastModifiedTime(attributes.getTimestamp().getTimeInMillis()); result.setCreationTime(attributes.getTimestamp().getTimeInMillis()); result.setLastAccessTime(attributes.getTimestamp().getTimeInMillis()); result.setSize(attributes.getSize()); Set<PosixFilePermission> permission = getPermissions(attributes); result.setExecutable(permission.contains(PosixFilePermission.OWNER_EXECUTE)); result.setReadable(permission.contains(PosixFilePermission.OWNER_READ)); result.setWritable(permission.contains(PosixFilePermission.OWNER_WRITE)); result.setPermissions(permission); result.setGroup(attributes.getGroup()); result.setOwner(attributes.getUser()); return result; }
From source file:nl.nn.adapterframework.filesystem.FtpFileSystem.java
@Override public Map<String, Object> getAdditionalFileProperties(FTPFile f) { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("user", f.getUser()); attributes.put("group", f.getGroup()); attributes.put("type", f.getType()); attributes.put("rawListing", f.getRawListing()); attributes.put("link", f.getLink()); attributes.put("hardLinkCount", f.getHardLinkCount()); return attributes; }
From source file:org.apache.ftpserver.clienttests.ListTest.java
public void testListFilesInDir() throws Exception { TEST_DIR1.mkdirs();// w ww. j a v a2 s . c o m TEST_FILE_IN_DIR1.createNewFile(); TEST_DIR_IN_DIR1.mkdirs(); FTPFile[] files = client.listFiles(TEST_DIR1.getName()); assertEquals(2, files.length); FTPFile file = getFile(files, TEST_FILE_IN_DIR1.getName()); assertEquals(TEST_FILE_IN_DIR1.getName(), file.getName()); assertEquals(0, file.getSize()); assertEquals("group", file.getGroup()); assertEquals("user", file.getUser()); assertTrue(file.isFile()); assertFalse(file.isDirectory()); file = getFile(files, TEST_DIR_IN_DIR1.getName()); assertEquals(TEST_DIR_IN_DIR1.getName(), file.getName()); assertEquals(0, file.getSize()); assertEquals("group", file.getGroup()); assertEquals("user", file.getUser()); assertFalse(file.isFile()); assertTrue(file.isDirectory()); }
From source file:org.apache.ftpserver.clienttests.ListTest.java
public void testListFile() throws Exception { TEST_DIR1.mkdirs();/*w w w. j a v a 2s . co m*/ TEST_FILE1.createNewFile(); TEST_FILE2.createNewFile(); FTPFile[] files = client.listFiles(TEST_FILE1.getName()); assertEquals(1, files.length); FTPFile file = getFile(files, TEST_FILE1.getName()); assertEquals(TEST_FILE1.getName(), file.getName()); assertEquals(0, file.getSize()); assertEquals("group", file.getGroup()); assertEquals("user", file.getUser()); assertTrue(file.isFile()); assertFalse(file.isDirectory()); Calendar expectedTimestamp = Calendar.getInstance(); expectedTimestamp.setTimeInMillis(TEST_FILE1.lastModified()); // server does not supply seconds and milliseconds expectedTimestamp.clear(Calendar.SECOND); expectedTimestamp.clear(Calendar.MILLISECOND); assertEquals(expectedTimestamp, file.getTimestamp()); }