@Test public void testListDefault() throws Exception { final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials( System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password") )); final FTPSession session = new FTPSession(host); session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final ListService list = new FTPDefaultListService(session, new DisabledPasswordStore(), new DisabledLoginCallback(), new CompositeFileEntryParser(Arrays.asList(new UnixFTPEntryParser())), FTPListService.Command.list); final Path directory = new FTPWorkdirService(session).find(); final Path file = new Path(directory, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session))).touch(file, new TransferStatus()); assertTrue(list.list(directory, new DisabledListProgressListener()).contains(file)); new FTPDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
@Test public void testListDefaultFlag() throws Exception { final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials( System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password") )); final FTPSession session = new FTPSession(host); session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final ListService list = new FTPDefaultListService(session, new DisabledPasswordStore(), new DisabledLoginCallback(), new CompositeFileEntryParser(Arrays.asList(new UnixFTPEntryParser())), FTPListService.Command.lista); final Path directory = new FTPWorkdirService(session).find(); final Path file = new Path(directory, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session))).touch(file, new TransferStatus()); assertTrue(list.list(directory, new DisabledListProgressListener()).contains(file)); new FTPDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
@Test public void testList() throws Exception { final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials( System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password") )); final FTPSession session = new FTPSession(host); session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final ListService service = new FTPStatListService(session, new CompositeFileEntryParser(Collections.singletonList(new UnixFTPEntryParser()))); final Path directory = new FTPWorkdirService(session).find(); final Path file = new Path(directory, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session))).touch(file, new TransferStatus()); final Permission permission = new Permission(Permission.Action.read_write, Permission.Action.read_write, Permission.Action.read_write); new FTPUnixPermissionFeature(session).setUnixPermission(file, permission); final AttributedList<Path> list = service.list(directory, new DisabledListProgressListener()); assertTrue(list.contains(file)); assertEquals(permission, list.get(file).attributes().getPermission()); session.close(); }
@Test public void testParse8006() throws Exception { final List<String> lines = Arrays.asList( "212-Status of /cgi-bin:", " drwxr-xr-x 3 1564466 15000 4 Jan 19 19:56 .", " drwxr-x--- 13 1564466 15000 44 Jun 13 18:36 ..", " drwxr-xr-x 2 1564466 15000 2 May 25 2009 tmp", " End of status", "212 -rw-r--r-- 1 1564466 15000 9859 Jan 19 19:56 adoptees.php"); final FTPFileEntryParser parser = new UnixFTPEntryParser(); final List<String> list = new FTPStatListService(null, parser).parse( 212, lines.toArray(new String[lines.size()])); assertEquals(6, list.size()); final Path parent = new Path("/cgi-bin", EnumSet.of(Path.Type.directory)); final AttributedList<Path> parsed = new FTPListResponseReader(parser, true).read( parent, list, new DisabledListProgressListener() ); assertEquals(2, parsed.size()); assertTrue(parsed.contains(new Path(parent, "tmp", EnumSet.of(Path.Type.directory)))); assertTrue(parsed.contains(new Path(parent, "adoptees.php", EnumSet.of(Path.Type.file)))); }
public List preParse(List orig) { if(orig != null && orig.size() > 0) { String header = (String)orig.get(0); if(header.indexOf("Volume") >= 0 && header.indexOf("Dsname") >= 0) { this.setType(0); super.setRegex("\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+[FV]\\S*\\s+\\S+\\s+\\S+\\s+(PS|PO|PO-E)\\s+(\\S+)\\s*"); } else if(header.indexOf("Name") >= 0 && header.indexOf("Id") >= 0) { this.setType(1); super.setRegex("(\\S+)\\s+\\S+\\s+\\S+\\s+(\\S+)\\s+(\\S+)\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s*"); } else if(header.indexOf("total") == 0) { this.setType(2); this.unixFTPEntryParser = new UnixFTPEntryParser(); } else if(header.indexOf("Spool Files") >= 30) { this.setType(3); super.setRegex("(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*"); } else if(header.indexOf("JOBNAME") == 0 && header.indexOf("JOBID") > 8) { this.setType(4); super.setRegex("(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+).*"); } else { this.setType(-1); } if(this.isType != 3) { orig.remove(0); } } return orig; }
/** * Creates an NT FTP parser: if the config exists, and the system key equals * {@link FTPClientConfig#SYST_NT} then a plain {@link NTFTPEntryParser} is used, * otherwise a composite of {@link NTFTPEntryParser} and {@link UnixFTPEntryParser} is used. * @param config the config to use, may be {@code null} * @return the parser */ private FTPFileEntryParser createNTFTPEntryParser(FTPClientConfig config) { if (config != null && FTPClientConfig.SYST_NT.equals( config.getServerSystemKey())) { return new NTFTPEntryParser(config); } else { return new CompositeFileEntryParser(new FTPFileEntryParser[] { new NTFTPEntryParser(config), new UnixFTPEntryParser(config) }); } }
/** * Creates an OS400 FTP parser: if the config exists, and the system key equals * {@link FTPClientConfig#SYST_OS400} then a plain {@link OS400FTPEntryParser} is used, * otherwise a composite of {@link OS400FTPEntryParser} and {@link UnixFTPEntryParser} is used. * @param config the config to use, may be {@code null} * @return the parser */ private FTPFileEntryParser createOS400FTPEntryParser(FTPClientConfig config) { if (config != null && FTPClientConfig.SYST_OS400.equals(config.getServerSystemKey())) { return new OS400FTPEntryParser(config); } else { return new CompositeFileEntryParser(new FTPFileEntryParser[] { new OS400FTPEntryParser(config), new UnixFTPEntryParser(config) }); } }
public FTPFileEntryParser createUnixFTPEntryParser() { return new UnixFTPEntryParser(); }
private FTPFileEntryParser createNTFTPEntryParser(FTPClientConfig config) { return (FTPFileEntryParser)(config != null && "WINDOWS".equals(config.getServerSystemKey())?new NTFTPEntryParser(config):new CompositeFileEntryParser(new FTPFileEntryParser[]{new NTFTPEntryParser(config), new UnixFTPEntryParser(config)})); }
private FTPFileEntryParser createOS400FTPEntryParser(FTPClientConfig config) { return (FTPFileEntryParser)(config != null && "OS/400".equals(config.getServerSystemKey())?new OS400FTPEntryParser(config):new CompositeFileEntryParser(new FTPFileEntryParser[]{new OS400FTPEntryParser(config), new UnixFTPEntryParser(config)})); }