org.apache.commons.net.ftp.FTPFileEntryParser Java Examples

The following examples show how to use org.apache.commons.net.ftp.FTPFileEntryParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FTPStatListServiceTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testParseEgnyte() throws Exception {
    final List<String> lines = Arrays.asList(
        "200-drwx------   0 - -            0 Jun 17 07:59 core",
        "200 -rw-------   0 David-Kocher -          529 Jun 17 07:59 App.config");
    final FTPFileEntryParser parser = new LaxUnixFTPEntryParser();
    final List<String> list = new FTPStatListService(null, parser).parse(
        200, lines.toArray(new String[lines.size()]));
    assertEquals(2, list.size());
    assertTrue(list.contains("drwx------   0 - -            0 Jun 17 07:59 core"));
    assertTrue(list.contains("-rw-------   0 David-Kocher -          529 Jun 17 07:59 App.config"));
    final Path parent = new Path("/cyberduck", EnumSet.of(Path.Type.directory));
    final AttributedList<Path> parsed = new FTPListResponseReader(parser, true).read(
        parent, list, new DisabledListProgressListener());
    assertEquals(2, parsed.size());
}
 
Example #2
Source File: FTPStatListServiceTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@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))));
}
 
Example #3
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@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
    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));
}
 
Example #4
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testStickyBit() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    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));
}
 
Example #5
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testSetgid() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drwxr-sr--   1 user     group          0 Feb 29 18:14 Filename"
    );
    assertNotNull(parsed);
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));

    parsed = parser.parseFTPEntry(
        "drwxr-Sr--   1 user     group          0 Feb 29 18:14 Filename"
    );
    assertNotNull(parsed);
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
}
 
Example #6
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testSetuid() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    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));
}
 
Example #7
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testParseFTPEntryExpected() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drw-rw-rw-   1 user      ftp             0  Mar 11 20:56 ADMIN_Documentation");
    assertNotNull(parsed);
    assertEquals(parsed.getType(), FTPFile.DIRECTORY_TYPE);
    assertEquals("user", parsed.getUser());
    assertEquals("ftp", parsed.getGroup());
    assertEquals("ADMIN_Documentation", parsed.getName());

    parsed = parser.parseFTPEntry(
        "drwxr--r--   1 user     group          0 Feb 14 18:14 Downloads");
    assertNotNull(parsed);
    assertEquals("Downloads", parsed.getName());
}
 
Example #8
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testSolarisAcl() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    //#215
    parsed = parser.parseFTPEntry(
        "drwxrwsr-x+ 34 cristol  molvis      3072 Jul 12 20:16 molvis");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "molvis");
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("cristol", parsed.getUser());
    assertEquals("molvis", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JULY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(12, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}
 
Example #9
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testCurrentYear() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "-rw-r--r--   1 20708    205             194 Oct 17 14:40 D3I0_805.fixlist");
    assertNotNull(parsed);
    assertTrue(parsed.isFile());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(17, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(14, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(40, parsed.getTimestamp().get(Calendar.MINUTE));
}
 
Example #10
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testUpperCaseMonths() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drwxrwxrwx    41 spinkb  spinkb      1394 Feb 21 20:57 Desktop");
    assertNotNull(parsed);
    assertEquals("Desktop", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("spinkb", parsed.getUser());
    assertEquals("spinkb", parsed.getGroup());
    assertEquals(Calendar.FEBRUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(21, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}
 
Example #11
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testLowerCaseMonths() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drwxrwxrwx    41 spinkb  spinkb      1394 jan 21 20:57 Desktop");
    assertNotNull(parsed);
    assertEquals("Desktop", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("spinkb", parsed.getUser());
    assertEquals("spinkb", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JANUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(21, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}
 
Example #12
Source File: CompositeFileEntryParser.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<String> preParse(final List<String> original) {
    for(FTPFileEntryParser parser : parsers) {
        parser.preParse(original);
    }
    return original;
}
 
Example #13
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testWindowsNTSystem() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("Windows_NT version 5.0");

    FTPFile parsed;

    // #5505
    parsed = parser.parseFTPEntry(
        "drwxrwxrwx   1 owner    group               0 Dec  5  0:45 adele.handmadebyflloyd.com"
    );
    assertNotNull(parsed);
    assertEquals("adele.handmadebyflloyd.com", parsed.getName());
    assertEquals("owner", parsed.getUser());
    assertEquals("group", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(5, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    // #5505
    parsed = parser.parseFTPEntry(
        "drwxrwxrwx   1 owner    group               0 Jan 22  2009 contact"
    );
    assertNotNull(parsed);
    assertEquals("contact", parsed.getName());
    assertEquals("owner", parsed.getUser());
    assertEquals("group", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JANUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(22, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2009, parsed.getTimestamp().get(Calendar.YEAR));
}
 
Example #14
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCarriageReturn() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    // #1521
    parsed = parser.parseFTPEntry(
        "drwxr--r--   1 user     group          0 Feb 29 18:14 Icon\r"
    );
    assertNotNull(parsed);
    assertEquals("Icon\r", parsed.getName());
}
 
Example #15
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Test
@Ignore
public void testLeapYear() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drwxr--r--   1 user     group          0 Feb 29 18:14 Downloads"
    );
    assertNotNull(parsed);
    assertNotNull(parsed.getTimestamp());
}
 
Example #16
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
public void testUnknownTimestampFormat() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "-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);
}
 
Example #17
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
/**
 * http://trac.cyberduck.ch/ticket/1118
 */
@Test
public void testParseNameWithEndingWhitespace() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drw-rw-rw-   1 user      ftp             0  Mar 11 20:56 ADMIN_Documentation ");
    assertNotNull(parsed);
    assertEquals("ADMIN_Documentation ", parsed.getName());
}
 
Example #18
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
/**
 * http://trac.cyberduck.ch/ticket/1066
 */
@Test
public void testParseNameWithBeginningWhitespace() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drw-rw-rw-   1 user      ftp             0  Mar 11 20:56  ADMIN_Documentation");
    assertNotNull(parsed);
    assertEquals(" ADMIN_Documentation", parsed.getName());
}
 
Example #19
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testParseTimestamp() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drw-rw-rw-   1 user      ftp             0  DEC 11 20:56 ADMIN_Documentation");
    assertNotNull(parsed);
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(11, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(20, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(56, parsed.getTimestamp().get(Calendar.MINUTE));

    parsed = parser.parseFTPEntry(
        "drwxr-xr-x    3 ftp      ftp           512 Mar 15  2004 doc");
    assertNotNull(parsed);
    assertNotNull(parsed.getTimestamp());
    assertEquals(2004, parsed.getTimestamp().get(Calendar.YEAR));
    assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(15, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    parsed = parser.parseFTPEntry(
        "drwxrwxr-x    2 ftp      ftp           512 Oct 23  2007 aurox");
    assertNotNull(parsed);
    assertNotNull(parsed.getTimestamp());
    assertEquals(2007, parsed.getTimestamp().get(Calendar.YEAR));
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(23, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}
 
Example #20
Source File: CompositeFileEntryParser.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void configure(final FTPClientConfig config) {
    for(FTPFileEntryParser parser : parsers) {
        if(parser instanceof Configurable) {
            ((Configurable) parser).configure(config);
        }
    }
}
 
Example #21
Source File: CompositeFileEntryParser.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public FTPFile parseFTPEntry(final String line) {
    if(log.isDebugEnabled()) {
        log.debug(String.format("Parse %s", line));
    }
    if(current != null) {
        final FTPFile parsed = current.parseFTPEntry(line);
        if(null != parsed) {
            return parsed;
        }
        if(log.isInfoEnabled()) {
            log.info(String.format("Switching parser implementation because %s failed", current));
        }
        current = null;
    }
    for(FTPFileEntryParser parser : parsers) {
        final FTPFile matched = parser.parseFTPEntry(line);
        if(matched != null) {
            current = parser;
            if(log.isInfoEnabled()) {
                log.info(String.format("Caching %s parser implementation", current));
            }
            return matched;
        }
    }
    log.warn(String.format("Failure parsing line %s", line));
    return null;
}
 
Example #22
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
/**
 * http://trac.cyberduck.ch/ticket/143
 */
@Test
public void testLeadingWhitespace() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "-rw-r--r--   1 20708    205         3553312 Feb 18 2005  D3I0_515.fmr");
    assertNotNull(parsed);
    assertTrue(parsed.isFile());
    assertEquals("D3I0_515.fmr", parsed.getName());
    assertEquals("20708", parsed.getUser());
    assertEquals("205", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.FEBRUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(18, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2005, parsed.getTimestamp().get(Calendar.YEAR));

    parsed = parser.parseFTPEntry(
        "drwxr-sr-x  14 17037    209            4096 Oct  6 2000  v3r7");
    assertNotNull(parsed);
    assertTrue(parsed.isDirectory());
    assertEquals("v3r7", parsed.getName());
    assertEquals("17037", parsed.getUser());
    assertEquals("209", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2000, parsed.getTimestamp().get(Calendar.YEAR));

    // #2895
    parsed = parser.parseFTPEntry(
        "-rwx------ 1 user group          38635 Jul 13 2006  users.xml");
    assertNotNull(parsed);
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("users.xml", parsed.getName());
    assertEquals("user", parsed.getUser());
    assertEquals("group", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JULY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(13, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2006, parsed.getTimestamp().get(Calendar.YEAR));
}
 
Example #23
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
/**
 * http://trac.cyberduck.ch/ticket/1076
 *
 * @
 */
@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));
}
 
Example #24
Source File: FTPStatListService.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
public FTPStatListService(final FTPSession session, final FTPFileEntryParser parser) {
    this.session = session;
    this.reader = new FTPListResponseReader(parser, true);
}
 
Example #25
Source File: FTPListResponseReader.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
public FTPListResponseReader(final FTPFileEntryParser parser, final boolean lenient) {
    this.parser = parser;
    this.lenient = lenient;
}
 
Example #26
Source File: FTPListResponseReader.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
public FTPListResponseReader(final FTPFileEntryParser parser) {
    this(parser, false);
}
 
Example #27
Source File: CompositeFileEntryParser.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
public FTPFileEntryParser getCurrent() {
    return current;
}
 
Example #28
Source File: CompositeFileEntryParser.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
public CompositeFileEntryParser(final List<? extends FTPFileEntryParser> parsers) {
    this.parsers = parsers;
}
 
Example #29
Source File: Client.java    From anthelion with Apache License 2.0 4 votes vote down vote up
public void retrieveList(String path, List entries, int limit,
  FTPFileEntryParser parser)
  throws IOException,
    FtpExceptionCanNotHaveDataConnection,
    FtpExceptionUnknownForcedDataClose,
    FtpExceptionControlClosedByForcedDataClose {
  Socket socket = __openPassiveDataConnection(FTPCommand.LIST, path);

  if (socket == null)
    throw new FtpExceptionCanNotHaveDataConnection("LIST "
      + ((path == null) ? "" : path));

  BufferedReader reader =
      new BufferedReader(new InputStreamReader(socket.getInputStream()));

  // force-close data channel socket, when download limit is reached
  boolean mandatory_close = false;

  //List entries = new LinkedList();
  int count = 0;
  String line = parser.readNextEntry(reader);
  while (line != null) {
    FTPFile ftpFile = parser.parseFTPEntry(line);
    // skip non-formatted lines
    if (ftpFile == null) {
      line = parser.readNextEntry(reader);
      continue;
    }
    entries.add(ftpFile);
    count += line.length();
    // impose download limit if limit >= 0, otherwise no limit
    // here, cut off is up to the line when total bytes is just over limit
    if (limit >= 0 && count > limit) {
      mandatory_close = true;
      break;
    }
    line = parser.readNextEntry(reader);
  }

  //if (mandatory_close)
  // you always close here, no matter mandatory_close or not.
  // however different ftp servers respond differently, see below.
  socket.close();

  // scenarios:
  // (1) mandatory_close is false, download limit not reached
  //     no special care here
  // (2) mandatory_close is true, download limit is reached
  //     different servers have different reply codes:

  try {
    int reply = getReply();
    if (!_notBadReply(reply))
      throw new FtpExceptionUnknownForcedDataClose(getReplyString());
  } catch (FTPConnectionClosedException e) {
    // some ftp servers will close control channel if data channel socket
    // is closed by our end before all data has been read out. Check:
    // tux414.q-tam.hp.com FTP server (hp.com version whp02)
    // so must catch FTPConnectionClosedException thrown by getReply() above
    //disconnect();
    throw new FtpExceptionControlClosedByForcedDataClose(e.getMessage());
  }

}
 
Example #30
Source File: Client.java    From nutch-htmlunit with Apache License 2.0 4 votes vote down vote up
/**
     * retrieve list reply for path
     * @param path
     * @param entries
     * @param limit
     * @param parser
     * @throws IOException
     * @throws FtpExceptionCanNotHaveDataConnection
     * @throws FtpExceptionUnknownForcedDataClose
     * @throws FtpExceptionControlClosedByForcedDataClose
     */
    public void retrieveList(String path, List<FTPFile> entries, int limit,
      FTPFileEntryParser parser)
      throws IOException,
        FtpExceptionCanNotHaveDataConnection,
        FtpExceptionUnknownForcedDataClose,
        FtpExceptionControlClosedByForcedDataClose {
      Socket socket = __openPassiveDataConnection(FTPCommand.LIST, path);

      if (socket == null)
        throw new FtpExceptionCanNotHaveDataConnection("LIST "
          + ((path == null) ? "" : path));

      BufferedReader reader =
          new BufferedReader(new InputStreamReader(socket.getInputStream()));

      // force-close data channel socket, when download limit is reached
//      boolean mandatory_close = false;

      //List entries = new LinkedList();
      int count = 0;
      String line = parser.readNextEntry(reader);
      while (line != null) {
        FTPFile ftpFile = parser.parseFTPEntry(line);
        // skip non-formatted lines
        if (ftpFile == null) {
          line = parser.readNextEntry(reader);
          continue;
        }
        entries.add(ftpFile);
        count += line.length();
        // impose download limit if limit >= 0, otherwise no limit
        // here, cut off is up to the line when total bytes is just over limit
        if (limit >= 0 && count > limit) {
//          mandatory_close = true;
          break;
        }
        line = parser.readNextEntry(reader);
      }

      //if (mandatory_close)
      // you always close here, no matter mandatory_close or not.
      // however different ftp servers respond differently, see below.
      socket.close();

      // scenarios:
      // (1) mandatory_close is false, download limit not reached
      //     no special care here
      // (2) mandatory_close is true, download limit is reached
      //     different servers have different reply codes:

      try {
        int reply = getReply();
        if (!_notBadReply(reply))
          throw new FtpExceptionUnknownForcedDataClose(getReplyString());
      } catch (FTPConnectionClosedException e) {
        // some ftp servers will close control channel if data channel socket
        // is closed by our end before all data has been read out. Check:
        // tux414.q-tam.hp.com FTP server (hp.com version whp02)
        // so must catch FTPConnectionClosedException thrown by getReply() above
        //disconnect();
        throw new FtpExceptionControlClosedByForcedDataClose(e.getMessage());
      }

    }