List of usage examples for org.apache.commons.net.ftp FTPClient disconnect
@Override public void disconnect() throws IOException
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. ja v a 2 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);//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 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 test00StoreFile() { FTPClient ftp = setupFTPClient(); final String name1 = "file1"; final String name2 = "file2"; try (final Tx tx = app.tx()) { FTPFile[] files = ftp.listFiles(); assertNotNull(files);//from w w w .ja va2 s . co m assertEquals(0, files.length); ftp.setFileType(FTP.ASCII_FILE_TYPE); ftp.setAutodetectUTF8(true); // Store a file InputStream in = IOUtils.toInputStream("Test Content"); ftp.storeFile(name1, in); in.close(); tx.success(); } catch (IOException | FrameworkException ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } String[] fileNames = null; try (final Tx tx = app.tx()) { fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(1, fileNames.length); assertEquals(name1, fileNames[0]); // Create second file in / createFTPFile(null, name2); tx.success(); } catch (IOException | FrameworkException 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(name1, fileNames[0]); assertEquals(name2, fileNames[1]); 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 test01ListFiles() { FTPClient ftp = setupFTPClient(); final String name1 = "file1"; final String name2 = "file2"; try (final Tx tx = app.tx()) { FTPFile[] files = ftp.listFiles(); assertNotNull(files);//ww w .j av a 2 s. c o m assertEquals(0, files.length); // Create files by API methods createFTPFile(null, name1); tx.success(); } catch (IOException | FrameworkException ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } String[] fileNames = null; try (final Tx tx = app.tx()) { fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(1, fileNames.length); assertEquals(name1, fileNames[0]); // Create second file in / createFTPFile(null, name2); tx.success(); } catch (IOException | FrameworkException 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(name1, fileNames[0]); assertEquals(name2, fileNames[1]); 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 test02RenameFile() { FTPClient ftp = setupFTPClient(); final String name2 = "file2"; final String name1 = "file1"; try (final Tx tx = StructrApp.getInstance(securityContext).tx()) { FTPFile[] files = ftp.listFiles(); assertNotNull(files);//w w w . ja va2 s . co m assertEquals(0, files.length); // Create files by API methods createFTPFile(null, name1); tx.success(); } catch (IOException | FrameworkException ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { ftp.rename(name1, name2); tx.success(); } catch (IOException | FrameworkException ex) { logger.log(Level.WARNING, "", ex); fail("Unexpected exception: " + ex.getMessage()); } try (final Tx tx = app.tx()) { String[] fileNames = ftp.listNames(); assertNotNull(fileNames); assertEquals(1, fileNames.length); assertEquals(name2, fileNames[0]); 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 ww w . j av 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()); } 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 ww w . jav a 2s. 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()); } }
From source file:org.structr.web.common.FtpTest.java
protected void disconnect(final FTPClient ftp) { try {/* w w w .j a v a 2s . c om*/ ftp.disconnect(); } catch (IOException ex) { logger.log(Level.SEVERE, "Error while disconnecting from FTP server", ex); fail("Unexpected exception: " + ex.getMessage()); } }
From source file:org.structr.web.common.SSHTest.java
protected void disconnect(final FTPClient ftp) { try {/*from w ww. j a v a 2 s .com*/ ftp.disconnect(); } catch (IOException ex) { logger.error("Error while disconnecting from FTP server", 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);/*www.j a v a 2 s .co m*/ 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; }