Package org.apache.commons.net.ftp

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


        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());
    }
View Full Code Here


        FTPFile[] files = client.listFiles();

        assertEquals(1, files.length);

        FTPFile file = getFile(files, TEST_DIR1.getName());
        assertEquals(TEST_DIR1.getName(), file.getName());
        assertEquals(0, file.getSize());
        assertEquals("group", file.getGroup());
        assertEquals("user", file.getUser());
        assertFalse(file.isFile());
        assertTrue(file.isDirectory());
    }
View Full Code Here

        TestUtil.writeDataToFile(TEST_FILE1, testData);

        FTPFile[] files = client.listFiles();

        assertEquals(4, files.length);
        FTPFile file = getFile(files, TEST_FILE1.getName());
        assertEquals(TEST_FILE1.getName(), file.getName());
        assertEquals(testData.length, file.getSize());
        assertEquals("group", file.getGroup());
        assertEquals("user", file.getUser());
        assertTrue(file.isFile());
        assertFalse(file.isDirectory());

        file = getFile(files, TEST_FILE2.getName());
        assertEquals(TEST_FILE2.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_DIR1.getName());
        assertEquals(TEST_DIR1.getName(), file.getName());
        assertEquals(0, file.getSize());
        assertEquals("group", file.getGroup());
        assertEquals("user", file.getUser());
        assertFalse(file.isFile());
        assertTrue(file.isDirectory());

        file = getFile(files, TEST_DIR2.getName());
        assertEquals(TEST_DIR2.getName(), file.getName());
        assertEquals(0, file.getSize());
        assertEquals("group", file.getGroup());
        assertEquals("user", file.getUser());
        assertFalse(file.isFile());
        assertTrue(file.isDirectory());
    }
View Full Code Here

    }

   
    private FTPFile getFile(FTPFile[] files, String name) {
        for (int i = 0; i < files.length; i++) {
            FTPFile file = files[i];

            if (name.equals(file.getName())) {
                return file;
            }
        }

        return null;
View Full Code Here

        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());

    }
View Full Code Here

        // List the children of this file
        doGetChildren();

        // Look for the requested child
        FTPFile ftpFile = (FTPFile) children.get(name);
        return ftpFile;
    }
View Full Code Here

                children = new TreeMap();

                // Remove '.' and '..' elements
                for (int i = 0; i < tmpChildren.length; i++)
                {
                    final FTPFile child = tmpChildren[i];
                    if (child == null)
                    {
                        if (log.isDebugEnabled())
                        {
                            log.debug(Messages.getString("vfs.provider.ftp/invalid-directory-entry.debug",
                                new Object[]
                                    {
                                        new Integer(i), relPath
                                    }));
                        }
                        continue;
                    }
                    if (!".".equals(child.getName())
                        && !"..".equals(child.getName()))
                    {
                        children.put(child.getName(), child);
                    }
                }
            }
        }
        finally
View Full Code Here

     * Fetches the info for this file.
     */
    private void getInfo(boolean flush) throws IOException
    {
        final FtpFileObject parent = (FtpFileObject) getParent();
        FTPFile newFileInfo;
        if (parent != null)
        {
            newFileInfo = parent.getChildFile(UriParser.decode(getName().getBaseName()), flush);
        }
        else
        {
            // Assume the root is a directory and exists
            newFileInfo = new FTPFile();
            newFileInfo.setType(FTPFile.DIRECTORY_TYPE);
        }

        this.fileInfo = newFileInfo;
    }
View Full Code Here

        int childNum = -1;
        Iterator iterChildren = children.values().iterator();
        while (iterChildren.hasNext())
        {
            childNum++;
            final FTPFile child = (FTPFile) iterChildren.next();
            childNames[childNum] = child.getName();
        }

        return UriParser.encode(childNames);
    }
View Full Code Here

        System.err.println("System: " + client.getSystemName());

        FTPFile[] files = client.listFiles();
        for (int i = 0; i < files.length; i++)
        {
            FTPFile file = files[i];
            if (file == null)
            {
                System.err.println("#" + i + ": " + null);
            }
            else
            {
                System.err.println("#" + i + ": " + file.toString());
                System.err.println("\t name:" + file.getName());
            }
        }
        client.disconnect();
    }
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.