List of usage examples for org.apache.commons.net.ftp FTPClient dele
public int dele(String pathname) throws IOException
From source file:org.alfresco.filesys.FTPServerTest.java
/** * Create a user other than "admin" who has access to a set of files. * /*from ww w .j av a 2s. c om*/ * Create a folder containing test.docx as user one * Update that file as user two. * Check user one can see user two's changes. * * @throws Exception */ public void testTwoUserUpdate() throws Exception { logger.debug("Start testFTPConnect"); final String TEST_DIR = "/Alfresco/User Homes/" + USER_ONE; FTPClient ftpOne = connectClient(); FTPClient ftpTwo = connectClient(); try { int reply = ftpOne.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { fail("FTP server refused connection."); } reply = ftpTwo.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { fail("FTP server refused connection."); } boolean login = ftpOne.login(USER_ONE, PASSWORD_ONE); assertTrue("user one login not successful", login); login = ftpTwo.login(USER_TWO, PASSWORD_TWO); assertTrue("user two login not successful", login); boolean success = ftpOne.changeWorkingDirectory("Alfresco"); assertTrue("user one unable to cd to Alfreco", success); success = ftpOne.changeWorkingDirectory("User*Homes"); assertTrue("user one unable to cd to User*Homes", success); success = ftpOne.changeWorkingDirectory(USER_ONE); assertTrue("user one unable to cd to " + USER_ONE, success); success = ftpTwo.changeWorkingDirectory("Alfresco"); assertTrue("user two unable to cd to Alfreco", success); success = ftpTwo.changeWorkingDirectory("User*Homes"); assertTrue("user two unable to cd to User*Homes", success); success = ftpTwo.changeWorkingDirectory(USER_ONE); assertTrue("user two unable to cd " + USER_ONE, success); // Create a file as user one String FILE1_CONTENT_1 = "test file 1 content"; String FILE1_NAME = "test.docx"; success = ftpOne.appendFile(FILE1_NAME, new ByteArrayInputStream(FILE1_CONTENT_1.getBytes("UTF-8"))); assertTrue("user one unable to append file", success); // Update the file as user two String FILE1_CONTENT_2 = "test file content updated"; success = ftpTwo.storeFile(FILE1_NAME, new ByteArrayInputStream(FILE1_CONTENT_2.getBytes("UTF-8"))); assertTrue("user two unable to append file", success); // User one should read user2's content InputStream is1 = ftpOne.retrieveFileStream(FILE1_NAME); assertNotNull("is1 is null", is1); String content1 = inputStreamToString(is1); assertEquals("Content is not as expected", FILE1_CONTENT_2, content1); ftpOne.completePendingCommand(); // User two should read user2's content InputStream is2 = ftpTwo.retrieveFileStream(FILE1_NAME); assertNotNull("is2 is null", is2); String content2 = inputStreamToString(is2); assertEquals("Content is not as expected", FILE1_CONTENT_2, content2); ftpTwo.completePendingCommand(); logger.debug("Test finished"); } finally { ftpOne.dele(TEST_DIR); if (ftpOne != null) { ftpOne.disconnect(); } if (ftpTwo != null) { ftpTwo.disconnect(); } } }
From source file:org.alfresco.filesys.FTPServerTest.java
/** * Test a quota failue exception over FTP. * A file should not exist after a create and quota exception. *//*from w ww . j a v a 2s . c o m*/ public void testFtpQuotaAndFtp() throws Exception { // Enable usages ContentUsageImpl contentUsage = (ContentUsageImpl) applicationContext.getBean("contentUsageImpl"); contentUsage.setEnabled(true); contentUsage.init(); UserUsageTrackingComponent userUsageTrackingComponent = (UserUsageTrackingComponent) applicationContext .getBean("userUsageTrackingComponent"); userUsageTrackingComponent.setEnabled(true); userUsageTrackingComponent.bootstrapInternal(); final String TEST_DIR = "/Alfresco/User Homes/" + USER_THREE; FTPClient ftpOne = connectClient(); try { int reply = ftpOne.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { fail("FTP server refused connection."); } boolean login = ftpOne.login(USER_THREE, PASSWORD_THREE); assertTrue("user three login not successful", login); boolean success = ftpOne.changeWorkingDirectory("Alfresco"); assertTrue("user three unable to cd to Alfreco", success); success = ftpOne.changeWorkingDirectory("User*Homes"); assertTrue("user one unable to cd to User*Homes", success); success = ftpOne.changeWorkingDirectory(USER_THREE); assertTrue("user one unable to cd to " + USER_THREE, success); /** * Create a file as user three which is bigger than the quota */ String FILE3_CONTENT_3 = "test file 3 content that needs to be greater than 100 bytes to result in a quota exception being thrown"; String FILE1_NAME = "test.docx"; // Should not be success success = ftpOne.appendFile(FILE1_NAME, new ByteArrayInputStream(FILE3_CONTENT_3.getBytes("UTF-8"))); assertFalse("user one can ignore quota", success); boolean deleted = ftpOne.deleteFile(FILE1_NAME); assertFalse("quota exception expected", deleted); logger.debug("test done"); } finally { // Disable usages contentUsage.setEnabled(false); contentUsage.init(); userUsageTrackingComponent.setEnabled(false); userUsageTrackingComponent.bootstrapInternal(); ftpOne.dele(TEST_DIR); if (ftpOne != null) { ftpOne.disconnect(); } } }