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

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

Introduction

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

Prototype

public boolean makeDirectory(String pathname) throws IOException 

Source Link

Document

Creates a new subdirectory on the FTP server in the current directory (if a relative pathname is given) or where specified (if an absolute pathname is given).

Usage

From source file:org.structr.files.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 w  w.j a v a 2s .c om
        assertEquals(0, dirs.length);

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

        tx.success();

    } catch (IOException | FrameworkException ex) {
        ex.printStackTrace();
        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) {
        ex.printStackTrace();
        fail("Unexpected exception: " + ex.getMessage());
    }
}

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

public void test04MkdirCdMkdirCd() {

    FTPClient ftp = setupFTPClient();

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

        assertEmptyDirectory(ftp);/*from  ww  w. ja v a  2s.  c  o  m*/

        String name1 = "/FTPdir1";

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

        ftp.changeWorkingDirectory(name1);

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

        assertEmptyDirectory(ftp);

        String name2 = name1.concat("/").concat("FTPdir2");

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

        ftp.changeWorkingDirectory(name2);

        newWorkingDirectory = ftp.printWorkingDirectory();
        assertEquals(name2, newWorkingDirectory);

        assertEmptyDirectory(ftp);

        ftp.disconnect();

        tx.success();

    } catch (IOException | FrameworkException ex) {
        ex.printStackTrace();
        fail("Unexpected exception: " + ex.getMessage());
    }
}

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

public void test05CdUp() {

    FTPClient ftp = setupFTPClient();

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

        assertEmptyDirectory(ftp);/*from w ww  .j  a  v  a 2s. c om*/

        String name1 = "/FTPdir1";

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

        ftp.changeWorkingDirectory(name1);

        String name2 = name1.concat("/").concat("FTPdir2");

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

        boolean success = ftp.changeToParentDirectory();
        assertTrue(success);

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

        ftp.disconnect();

        tx.success();

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

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

public void test06CdTwoUp() {

    FTPClient ftp = setupFTPClient();

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

        assertEmptyDirectory(ftp);/*www. j  a  va 2  s .c  om*/

        String name1 = "/FTPdir1";

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

        ftp.changeWorkingDirectory(name1);

        String name2 = name1.concat("/").concat("FTPdir2");

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

        ftp.changeWorkingDirectory(name2);

        String name3 = name2.concat("/").concat("FTPdir3");

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

        ftp.changeWorkingDirectory(name3);

        ftp.changeToParentDirectory();
        ftp.changeToParentDirectory();

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

        ftp.disconnect();

        tx.success();

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

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

public void test07CdToSiblingDirectory() {

    FTPClient ftp = setupFTPClient();

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

        FTPFile[] dirs = ftp.listDirectories();

        assertNotNull(dirs);/*w  w w. j ava2s.c  om*/
        assertEquals(0, dirs.length);

        String name1 = "/FTPdir1";
        String name2 = "/FTPdir2";

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

        ftp.changeWorkingDirectory(name1);

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

        ftp.changeWorkingDirectory("../" + name2);

        newWorkingDirectory = ftp.printWorkingDirectory();
        assertEquals(name2, newWorkingDirectory);

        ftp.disconnect();

        tx.success();

    } catch (IOException | FrameworkException ex) {
        logger.log(Level.SEVERE, "Error while changing FTP directories", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }
}

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

public void test08CdRoot() {

    FTPClient ftp = setupFTPClient();

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

        FTPFile[] dirs = ftp.listDirectories();

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

        String name1 = "/FTPdir1";

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

        ftp.changeWorkingDirectory(name1);

        assertEmptyDirectory(ftp);

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

        ftp.changeWorkingDirectory("/");

        newWorkingDirectory = ftp.printWorkingDirectory();
        assertEquals("/", newWorkingDirectory);

        ftp.disconnect();

        tx.success();

    } catch (IOException | FrameworkException ex) {
        logger.log(Level.SEVERE, "Error while changing FTP directories", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }
}

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

public void test02MkDir() {

    FTPClient ftp = setupFTPClient();

    FTPFile[] dirs = null;//w w  w .ja  v  a  2  s.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  w w .ja v  a2 s.  c o 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.ftp.FtpDirectoriesTest.java

public void test04MkdirCdMkdirCd() {

    FTPClient ftp = setupFTPClient();

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

        assertEmptyDirectory(ftp);/*ww  w  .  j a  v a2 s.c  o  m*/

        String name1 = "/FTPdir1";

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

        ftp.changeWorkingDirectory(name1);

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

        assertEmptyDirectory(ftp);

        String name2 = name1.concat("/").concat("FTPdir2");

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

        ftp.changeWorkingDirectory(name2);

        newWorkingDirectory = ftp.printWorkingDirectory();
        assertEquals(name2, newWorkingDirectory);

        assertEmptyDirectory(ftp);

        ftp.disconnect();

        tx.success();

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

From source file:org.syncany.tests.connection.plugins.ftp.EmbeddedTestFtpServer.java

public static void mkdir(String path, String user) throws SocketException, IOException {
    FTPClient ftp = new FTPClient();
    ftp.setConnectTimeout(3000);/*  w  w  w .  j  a  va2s.com*/
    ftp.setDataTimeout(3000);
    ftp.setDefaultTimeout(3000);

    ftp.connect(HOST, PORT);
    ftp.login(user, PASSWORD1);
    ftp.enterLocalPassiveMode();
    ftp.setFileType(FTPClient.BINARY_FILE_TYPE); // Important !!!
    ftp.makeDirectory(path);

    ftp.disconnect();
    ftp = null;
}