List of usage examples for org.apache.commons.net.ftp FTPClient changeWorkingDirectory
public boolean changeWorkingDirectory(String pathname) throws IOException
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);// w w w .ja va 2 s .c o m 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);/*from w w w. 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);//from w w w .j a v a2 s .co m 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);// ww w.j a v a2 s.c o 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.files.ftp.FtpFilesTest.java
public void test03MoveFile() { FTPClient ftp = setupFTPClient(); final String name1 = "file1"; final String name2 = "dir1"; try (final Tx tx = app.tx()) { FTPFile[] files = ftp.listFiles(); assertNotNull(files);/*w ww.ja v a 2 s. com*/ assertEquals(0, files.length); // Create files by API methods createFTPFile(null, name1); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { // Create folder in / createFTPDirectory(null, name2); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { // Move file to dir ftp.rename("/" + name1, "/" + name2 + "/" + name1); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { ftp.changeWorkingDirectory("/" + name2); String[] fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(1, fileNames.length); assertEquals(name1, fileNames[0]); ftp.disconnect(); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } }
From source file:org.structr.files.ftp.FtpFilesTest.java
public void test04MoveFileToRoot() { FTPClient ftp = setupFTPClient(); final String name1 = "file1"; final String name2 = "dir1"; try (final Tx tx = app.tx()) { FTPFile[] files = ftp.listFiles(); assertNotNull(files);//from w w w . j a v a 2 s . c o m assertEquals(0, files.length); // Create files by API methods createFTPFile(null, name1); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { // Create folder in / createFTPDirectory(null, name2); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { // Move file to dir ftp.rename("/" + name1, "/" + name2 + "/" + name1); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } String[] fileNames = null; try (final Tx tx = app.tx()) { ftp.changeWorkingDirectory("/" + name2); fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(1, fileNames.length); assertEquals(name1, fileNames[0]); // Move file back to / ftp.rename("/" + name2 + "/" + name1, "/" + name1); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { ftp.changeWorkingDirectory("/"); tx.success(); } catch (Exception ex) { ex.printStackTrace(); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(2, fileNames.length); assertEquals(name2, fileNames[0]); assertEquals(name1, fileNames[1]); ftp.disconnect(); tx.success(); } catch (Exception ex) { ex.printStackTrace(); 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);/* w w w .jav 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);//from ww w .ja va 2s. co 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.structr.ftp.FtpFilesTest.java
public void test03MoveFile() { FTPClient ftp = setupFTPClient(); final String name1 = "file1"; final String name2 = "dir1"; try (final Tx tx = app.tx()) { FTPFile[] files = ftp.listFiles(); assertNotNull(files);/*from w w w . j av a2s. com*/ assertEquals(0, files.length); // Create files by API methods createFTPFile(null, name1); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { // Create folder in / createFTPDirectory(null, name2); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { // Move file to dir ftp.rename("/" + name1, "/" + name2 + "/" + name1); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { ftp.changeWorkingDirectory("/" + name2); String[] fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(1, fileNames.length); assertEquals(name1, fileNames[0]); ftp.disconnect(); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } }
From source file:org.structr.ftp.FtpFilesTest.java
public void test04MoveFileToRoot() { FTPClient ftp = setupFTPClient(); final String name1 = "file1"; final String name2 = "dir1"; try (final Tx tx = app.tx()) { FTPFile[] files = ftp.listFiles(); assertNotNull(files);//from w w w . jav a 2 s . c o m assertEquals(0, files.length); // Create files by API methods createFTPFile(null, name1); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { // Create folder in / createFTPDirectory(null, name2); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { // Move file to dir ftp.rename("/" + name1, "/" + name2 + "/" + name1); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } String[] fileNames = null; try (final Tx tx = app.tx()) { ftp.changeWorkingDirectory("/" + name2); fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(1, fileNames.length); assertEquals(name1, fileNames[0]); // Move file back to / ftp.rename("/" + name2 + "/" + name1, "/" + name1); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { ftp.changeWorkingDirectory("/"); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(2, fileNames.length); assertEquals(name2, fileNames[0]); assertEquals(name1, fileNames[1]); ftp.disconnect(); tx.success(); } catch (Exception ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } }