Example usage for org.apache.commons.net.ftp FTPClient listDirectories

List of usage examples for org.apache.commons.net.ftp FTPClient listDirectories

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPClient listDirectories.

Prototype

public FTPFile[] listDirectories() throws IOException 

Source Link

Document

Using the default system autodetect mechanism, obtain a list of directories contained in the current working directory.

Usage

From source file:org.structr.ftp.FtpDirectoriesTest.java

public void test02MkDir() {

    FTPClient ftp = setupFTPClient();

    FTPFile[] dirs = null;//from ww  w  . ja  va 2s . c o m

    final String name1 = "FTPdir1";
    final String name2 = "FTPdir2";
    boolean success = false;

    try (final Tx tx = StructrApp.getInstance(securityContext).tx()) {

        assertEmptyDirectory(ftp);

        // Create folder by mkdir FTP command
        success = ftp.makeDirectory(name1);
        assertTrue(success);

        tx.success();

    } catch (IOException | FrameworkException ex) {
        logger.log(Level.WARNING, "", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }

    try (final Tx tx = app.tx()) {

        dirs = ftp.listDirectories();

        assertNotNull(dirs);
        assertEquals(1, dirs.length);
        assertEquals(name1, dirs[0].getName());

        // Create second folder in /
        success = ftp.makeDirectory(name2);
        assertTrue(success);

        tx.success();

    } catch (IOException | FrameworkException ex) {
        logger.log(Level.WARNING, "", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }

    try (final Tx tx = app.tx()) {

        dirs = ftp.listDirectories();

        assertNotNull(dirs);
        assertEquals(2, dirs.length);
        assertEquals(name1, dirs[0].getName());
        assertEquals(name2, dirs[1].getName());

        ftp.disconnect();

        tx.success();

    } catch (IOException | FrameworkException ex) {
        logger.log(Level.WARNING, "", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }
}

From source file:org.structr.ftp.FtpDirectoriesTest.java

public void test03MkdirCd() {

    FTPClient ftp = setupFTPClient();
    final String name1 = "/FTPdir1";

    try (final Tx tx = app.tx()) {

        FTPFile[] dirs = ftp.listDirectories();

        assertNotNull(dirs);//from   w  ww  . j av  a  2  s  .co  m
        assertEquals(0, dirs.length);

        // Create folder by mkdir FTP command
        ftp.makeDirectory(name1);

        tx.success();

    } catch (IOException | FrameworkException ex) {
        logger.log(Level.WARNING, "", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }

    try (final Tx tx = app.tx()) {

        ftp.changeWorkingDirectory(name1);

        assertEmptyDirectory(ftp);

        String newWorkingDirectory = ftp.printWorkingDirectory();
        assertEquals(name1, newWorkingDirectory);

        ftp.disconnect();

        tx.success();

    } catch (IOException | FrameworkException ex) {
        logger.log(Level.WARNING, "", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }
}

From source file:org.structr.web.common.FtpTest.java

protected void assertEmptyDirectory(final FTPClient ftp) {

    FTPFile[] dirs = null;/* w  w  w .j  av  a 2 s .c  o  m*/

    try {

        dirs = ftp.listDirectories();

    } catch (IOException ex) {

        logger.log(Level.SEVERE, "Error in FTP test", ex);
        fail("Unexpected exception: " + ex.getMessage());

    }

    assertNotNull(dirs);
    assertEquals(0, dirs.length);

}

From source file:org.structr.web.common.SSHTest.java

protected void assertEmptyDirectory(final FTPClient ftp) {

    FTPFile[] dirs = null;//from  www. j  av a 2s.c  o m

    try {

        dirs = ftp.listDirectories();

    } catch (IOException ex) {

        logger.error("Error in FTP test", ex);
        fail("Unexpected exception: " + ex.getMessage());

    }

    assertNotNull(dirs);
    assertEquals(0, dirs.length);

}