Package org.apache.commons.net.ftp

Examples of org.apache.commons.net.ftp.FTPFile


     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
     */
    @Override
    public void testParseFieldsOnFile() throws Exception
    {
        FTPFile f = getParser().parseFTPEntry("05-22-97  12:08AM                  5000000000 AUTOEXEC.BAK");
        assertNotNull("Could not parse entry.", f);
        assertEquals("Thu May 22 00:08:00 1997",
                     df.format(f.getTimestamp().getTime()));
        assertTrue("Should have been a file.",
                   f.isFile());
        assertEquals("AUTOEXEC.BAK", f.getName());
        assertEquals(5000000000L, f.getSize());

        // test an NT-unix style listing that does NOT have a leading zero
        // on the hour.

        f = getParser().parseFTPEntry(
                "-rw-rw-r--   1 mqm        mqm          17707 Mar 12  3:33 killmq.sh.log");
        assertNotNull("Could not parse entry.", f);
        Calendar cal = Calendar.getInstance();
        cal.setTime(f.getTimestamp().getTime());
        assertEquals("hour", 3, cal.get(Calendar.HOUR));
        assertTrue("Should have been a file.",
                f.isFile());
        assertEquals(17707, f.getSize());
    }
View Full Code Here


     *
     * @throws Exception
     */
    public void testDirectoryBeginningWithNumber() throws Exception
    {
        FTPFile f = getParser().parseFTPEntry(directoryBeginningWithNumber);
        assertEquals("name", "123xyz", f.getName());
    }
View Full Code Here

        assertEquals("name", "123xyz", f.getName());
    }

    public void testDirectoryBeginningWithNumberFollowedBySpaces() throws Exception
    {
        FTPFile f = getParser().parseFTPEntry("12-03-96  06:38AM       <DIR>          123 xyz");
        assertEquals("name", "123 xyz", f.getName());
        f = getParser().parseFTPEntry("12-03-96  06:38AM       <DIR>          123 abc xyz");
        assertNotNull(f);
        assertEquals("name", "123 abc xyz", f.getName());
    }
View Full Code Here

    /**
     * Test that group names with embedded spaces can be handled correctly
     *
     */
    public void testGroupNameWithSpaces() {
        FTPFile f = getParser().parseFTPEntry("drwx------ 4 maxm Domain Users 512 Oct 2 10:59 .metadata");
        assertNotNull(f);
        assertEquals("maxm", f.getUser());
        assertEquals("Domain Users", f.getGroup());
    }
View Full Code Here

     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
     */
    @Override
    public void testParseFieldsOnFile() throws Exception
    {
        FTPFile file = getParser().parseFTPEntry("-C--E-----FTP B QUA1I1      18128       5000000000 Aug 12 13:56 QUADTEST");
        Calendar today  = Calendar.getInstance();
        int year        = today.get(Calendar.YEAR);

        assertTrue("Should be a file.",
                   file.isFile());
        assertEquals("QUADTEST",
                     file.getName());
        assertEquals(5000000000L,
                     file.getSize());
        assertEquals("QUA1I1",
                     file.getUser());
        assertEquals("18128",
                     file.getGroup());

        if (today.get(Calendar.MONTH) < Calendar.AUGUST) {
            --year;
        }

        Calendar timestamp = file.getTimestamp();
        assertEquals(year, timestamp.get(Calendar.YEAR));
        assertEquals(Calendar.AUGUST, timestamp.get(Calendar.MONTH));
        assertEquals(12, timestamp.get(Calendar.DAY_OF_MONTH));
        assertEquals(13, timestamp.get(Calendar.HOUR_OF_DAY));
        assertEquals(56, timestamp.get(Calendar.MINUTE));
View Full Code Here

     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
     */
    @Override
    public void testParseFieldsOnDirectory() throws Exception {
        String reply = "d [-W---F--] testUser                        512 Apr 13 23:12 testFile";
        FTPFile f = getParser().parseFTPEntry(reply);

        assertNotNull("Could not parse file", f);
        assertEquals("testFile", f.getName());
        assertEquals(512L, f.getSize());
        assertEquals("testUser", f.getUser());
        assertTrue("Directory flag is not set!", f.isDirectory());

        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.MONTH, 3);
        cal.set(Calendar.DAY_OF_MONTH, 13);
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 12);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.YEAR, f.getTimestamp().get(Calendar.YEAR));

        assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp()
                .getTime()));

    }
View Full Code Here

     */
    @Override
    public void testParseFieldsOnFile() throws Exception {
        String reply = "- [R-CEAFMS] rwinston                        19968 Mar 12 15:20 Document name with spaces.doc";

        FTPFile f = getParser().parseFTPEntry(reply);

        assertNotNull("Could not parse file", f);
        assertEquals("Document name with spaces.doc", f.getName());
        assertEquals(19968L, f.getSize());
        assertEquals("rwinston", f.getUser());
        assertTrue("File flag is not set!", f.isFile());

        assertTrue(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
        assertFalse(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    }
View Full Code Here

        String[] badsamples = getBadListing();
        for (int i = 0; i < badsamples.length; i++)
        {

            String test = badsamples[i];
            FTPFile f = parser.parseFTPEntry(test);
            assertNull("Should have Failed to parse " + test,
                       nullFileOrNullDate(f));

            doAdditionalBadTests(test, f);
        }
View Full Code Here

        String[] goodsamples = getGoodListing();
        for (int i = 0; i < goodsamples.length; i++)
        {

            String test = goodsamples[i];
            FTPFile f = parser.parseFTPEntry(test);
            assertNotNull("Failed to parse " + test,
                          f);

            doAdditionalGoodTests(test, f);
        }
View Full Code Here

     * @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 f = new FTPFile();
        if (matches(entry)) {
            String dirString = group(1);
            String attrib = group(2);
            String user = group(3);
            String size = group(4);
            String datestr = group(5);
            String name = group(9);

            try {
                f.setTimestamp(super.parseTimestamp(datestr));
            } catch (ParseException e) {
                 // intentionally do nothing
            }

            //is it a DIR or a file
            if (dirString.trim().equals("d")) {
                f.setType(FTPFile.DIRECTORY_TYPE);
            } else // Should be "-"
            {
                f.setType(FTPFile.FILE_TYPE);
            }

            f.setUser(user);

            //set the name
            f.setName(name.trim());

            //set the size
            f.setSize(Long.parseLong(size.trim()));

            // Now set the permissions (or at least a subset thereof - full permissions would probably require
            // subclassing FTPFile and adding extra metainformation there)
            if (attrib.indexOf("R") != -1) {
                f.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION,
                        true);
            }
            if (attrib.indexOf("W") != -1) {
                f.setPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION,
                        true);
            }

            return (f);
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.net.ftp.FTPFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.