List of usage examples for org.apache.commons.net.ftp FTPClient deleteFile
public boolean deleteFile(String pathname) throws IOException
From source file:com.jaeksoft.searchlib.scheduler.task.TaskFtpXmlFeed.java
@Override public void execute(Client client, TaskProperties properties, Variables variables, TaskLog taskLog) throws SearchLibException { String server = properties.getValue(propServer); String path = properties.getValue(propPath); String login = properties.getValue(propLogin); String password = properties.getValue(propPassword); String fileNamePattern = properties.getValue(propFileNamePattern); boolean deleteAfterLoad = Boolean.TRUE.toString().equals(properties.getValue(propDeleteAfterLoad)); boolean truncateWhenFilesFound = Boolean.TRUE.toString() .equals(properties.getValue(propTruncateIndexWhenFilesFound)); Pattern pattern = null;/* www . j av a 2 s . c o m*/ if (fileNamePattern != null && fileNamePattern.length() > 0) pattern = Pattern.compile(fileNamePattern); String p = properties.getValue(propBuffersize); String xsl = properties.getValue(propXsl); File xmlTempResult = null; int bufferSize = 50; if (p != null && p.length() > 0) bufferSize = Integer.parseInt(p); HttpDownloader httpDownloader = client.getWebCrawlMaster().getNewHttpDownloader(true); FTPClient ftp = null; InputStream inputStream = null; try { // FTP Connection ftp = new FTPClient(); checkConnect(ftp, server, login, password); FTPFile[] files = ftp.listFiles(path, new FtpFileInstance.FtpInstanceFileFilter(true, false, null)); if (files == null) return; // Sort by ascendant filename String[] fileNames = new String[files.length]; int i = 0; for (FTPFile file : files) fileNames[i++] = file.getName(); Arrays.sort(fileNames); int ignored = 0; int loaded = 0; boolean bAlreadyTruncated = false; for (String fileName : fileNames) { String filePathName = FilenameUtils.concat(path, fileName); if (pattern != null) if (!pattern.matcher(fileName).find()) { ignored++; continue; } if (truncateWhenFilesFound && !bAlreadyTruncated) { client.deleteAll(); bAlreadyTruncated = true; } taskLog.setInfo("Working on: " + filePathName); inputStream = ftp.retrieveFileStream(filePathName); Node xmlDoc = null; if (xsl != null && xsl.length() > 0) { xmlTempResult = File.createTempFile("ossftpfeed", ".xml"); DomUtils.xslt(new StreamSource(inputStream), xsl, xmlTempResult); xmlDoc = DomUtils.readXml(new StreamSource(xmlTempResult), false); } else xmlDoc = DomUtils.readXml(new StreamSource(inputStream), false); client.updateXmlDocuments(xmlDoc, bufferSize, null, httpDownloader, taskLog); client.deleteXmlDocuments(xmlDoc, bufferSize, taskLog); inputStream.close(); inputStream = null; if (!ftp.completePendingCommand()) throw new SearchLibException("FTP Error"); if (xmlTempResult != null) { xmlTempResult.delete(); xmlTempResult = null; } checkConnect(ftp, server, login, password); if (deleteAfterLoad) ftp.deleteFile(filePathName); loaded++; } taskLog.setInfo(loaded + " file(s) loaded - " + ignored + " file(s) ignored"); } catch (XPathExpressionException e) { throw new SearchLibException(e); } catch (NoSuchAlgorithmException e) { throw new SearchLibException(e); } catch (ParserConfigurationException e) { throw new SearchLibException(e); } catch (SAXException e) { throw new SearchLibException(e); } catch (IOException e) { throw new SearchLibException(e); } catch (URISyntaxException e) { throw new SearchLibException(e); } catch (InstantiationException e) { throw new SearchLibException(e); } catch (IllegalAccessException e) { throw new SearchLibException(e); } catch (ClassNotFoundException e) { throw new SearchLibException(e); } catch (TransformerException e) { throw new SearchLibException(e); } finally { if (xmlTempResult != null) xmlTempResult.delete(); IOUtils.close(inputStream); try { if (ftp != null) if (ftp.isConnected()) ftp.disconnect(); } catch (IOException e) { Logging.warn(e); } if (httpDownloader != null) httpDownloader.release(); } }
From source file:com.github.carlosrubio.org.apache.tools.ant.taskdefs.optional.net.FTP.java
/** * Delete a file from the remote host./*from w w w . ja va 2 s . c o m*/ * @param ftp ftp client * @param filename file to delete * @throws IOException in unknown circumstances * @throws BuildException if skipFailedTransfers is set to false * and the deletion could not be done */ protected void delFile(FTPClient ftp, String filename) throws IOException, BuildException { if (verbose) { log("deleting " + filename); } if (!ftp.deleteFile(resolveFile(filename))) { String s = "could not delete file: " + ftp.getReplyString(); if (skipFailedTransfers) { log(s, Project.MSG_WARN); skipped++; } else { throw new BuildException(s); } } else { log("File " + filename + " deleted from " + server, Project.MSG_VERBOSE); transferred++; } }
From source file:com.github.carlosrubio.org.apache.tools.ant.taskdefs.optional.net.FTP.java
/** * auto find the time difference between local and remote * @param ftp handle to ftp client//from w w w .j a v a 2 s . c om * @return number of millis to add to remote time to make it comparable to local time * @since ant 1.6 */ private long getTimeDiff(FTPClient ftp) { long returnValue = 0; File tempFile = findFileName(ftp); try { // create a local temporary file FILE_UTILS.createNewFile(tempFile); long localTimeStamp = tempFile.lastModified(); BufferedInputStream instream = new BufferedInputStream(new FileInputStream(tempFile)); ftp.storeFile(tempFile.getName(), instream); instream.close(); boolean success = FTPReply.isPositiveCompletion(ftp.getReplyCode()); if (success) { FTPFile[] ftpFiles = ftp.listFiles(tempFile.getName()); if (ftpFiles.length == 1) { long remoteTimeStamp = ftpFiles[0].getTimestamp().getTime().getTime(); returnValue = localTimeStamp - remoteTimeStamp; } ftp.deleteFile(ftpFiles[0].getName()); } // delegate the deletion of the local temp file to the delete task // because of race conditions occuring on Windows Delete mydelete = new Delete(); mydelete.bindToOwner(this); mydelete.setFile(tempFile.getCanonicalFile()); mydelete.execute(); } catch (Exception e) { throw new BuildException(e, getLocation()); } return returnValue; }
From source file:com.clickha.nifi.processors.util.FTPTransferV2.java
@Override public String put(final FlowFile flowFile, final String path, final String filename, final InputStream content) throws IOException { final FTPClient client = getClient(flowFile); final String fullPath; if (path == null) { fullPath = filename;/* w w w.j av a 2 s . c o m*/ } else { final String workingDir = setAndGetWorkingDirectory(path); fullPath = workingDir.endsWith("/") ? workingDir + filename : workingDir + "/" + filename; } String tempFilename = ctx.getProperty(TEMP_FILENAME).evaluateAttributeExpressions(flowFile).getValue(); if (tempFilename == null) { final boolean dotRename = ctx.getProperty(DOT_RENAME).asBoolean(); tempFilename = dotRename ? "." + filename : filename; } final boolean storeSuccessful = client.storeFile(tempFilename, content); if (!storeSuccessful) { throw new IOException("Failed to store file " + tempFilename + " to " + fullPath + " due to: " + client.getReplyString()); } final String lastModifiedTime = ctx.getProperty(LAST_MODIFIED_TIME).evaluateAttributeExpressions(flowFile) .getValue(); if (lastModifiedTime != null && !lastModifiedTime.trim().isEmpty()) { try { final DateFormat informat = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); final Date fileModifyTime = informat.parse(lastModifiedTime); final DateFormat outformat = new SimpleDateFormat(FTP_TIMEVAL_FORMAT, Locale.US); final String time = outformat.format(fileModifyTime); if (!client.setModificationTime(tempFilename, time)) { // FTP server probably doesn't support MFMT command logger.warn("Could not set lastModifiedTime on {} to {}", new Object[] { flowFile, lastModifiedTime }); } } catch (final Exception e) { logger.error("Failed to set lastModifiedTime on {} to {} due to {}", new Object[] { flowFile, lastModifiedTime, e }); } } final String permissions = ctx.getProperty(PERMISSIONS).evaluateAttributeExpressions(flowFile).getValue(); if (permissions != null && !permissions.trim().isEmpty()) { try { int perms = numberPermissions(permissions); if (perms >= 0) { if (!client.sendSiteCommand("chmod " + Integer.toOctalString(perms) + " " + tempFilename)) { logger.warn("Could not set permission on {} to {}", new Object[] { flowFile, permissions }); } } } catch (final Exception e) { logger.error("Failed to set permission on {} to {} due to {}", new Object[] { flowFile, permissions, e }); } } if (!filename.equals(tempFilename)) { try { logger.debug("Renaming remote path from {} to {} for {}", new Object[] { tempFilename, filename, flowFile }); final boolean renameSuccessful = client.rename(tempFilename, filename); if (!renameSuccessful) { throw new IOException("Failed to rename temporary file " + tempFilename + " to " + fullPath + " due to: " + client.getReplyString()); } } catch (final IOException e) { try { client.deleteFile(tempFilename); throw e; } catch (final IOException e1) { throw new IOException("Failed to rename temporary file " + tempFilename + " to " + fullPath + " and failed to delete it when attempting to clean up", e1); } } } return fullPath; }
From source file:com.bdaum.zoom.net.core.ftp.FtpAccount.java
@SuppressWarnings("fallthrough") private int transferFiles(FTPClient ftp, File[] files, IProgressMonitor monitor, IAdaptable adaptable, boolean deleteTransferred) throws IOException { if (monitor.isCanceled()) return -1; FTPFile[] oldfiles = ftp.listFiles(); if (monitor.isCanceled()) return -1; Map<String, FTPFile> names = new HashMap<String, FTPFile>(); for (FTPFile file : oldfiles) names.put(file.getName(), file); int n = 0;/*www .j a v a2 s . c o m*/ for (File file : files) { final String filename = file.getName(); FTPFile ftpFile = names.get(filename); if (file.isDirectory()) { if (ftpFile != null) { if (!ftpFile.isDirectory()) throw new IOException( NLS.bind(Messages.FtpAccount_cannot_replace_file_with_subdir, filename)); boolean result = ftp.changeWorkingDirectory(Core.encodeUrlSegment(filename)); if (!result) throw new IOException(NLS.bind(Messages.FtpAccount_cannot_change_to_working_dir, filename)); // System.out.println(filename + " is new directory"); //$NON-NLS-1$ } else { ftp.makeDirectory(filename); boolean result = ftp.changeWorkingDirectory(Core.encodeUrlSegment(filename)); if (!result) throw new IOException(Messages.FtpAccount_creation_of_subdir_failed); // System.out.println(filename + " is new directory"); //$NON-NLS-1$ } if (monitor.isCanceled()) return -1; int c = transferFiles(ftp, file.listFiles(), monitor, adaptable, deleteTransferred); if (c < 0) return -1; n += c; ftp.changeToParentDirectory(); // System.out.println("Returned to parent directory"); //$NON-NLS-1$ } else { if (ftpFile != null) { if (ftpFile.isDirectory()) throw new IOException( NLS.bind(Messages.FtpAccount_cannot_replace_subdir_with_file, filename)); if (skipAll) { if (deleteTransferred) file.delete(); continue; } if (!replaceAll) { if (monitor.isCanceled()) return -1; int ret = 4; IDbErrorHandler errorHandler = Core.getCore().getErrorHandler(); if (errorHandler != null) { String[] buttons = (filecount > 1) ? new String[] { Messages.FtpAccount_overwrite, Messages.FtpAccount_overwrite_all, IDialogConstants.SKIP_LABEL, Messages.FtpAccount_skip_all, IDialogConstants.CANCEL_LABEL } : new String[] { Messages.FtpAccount_overwrite, IDialogConstants.SKIP_LABEL, IDialogConstants.CANCEL_LABEL }; ret = errorHandler.showMessageDialog(Messages.FtpAccount_file_already_exists, null, NLS.bind(Messages.FtpAccount_file_exists_overwrite, filename), MessageDialog.QUESTION, buttons, 0, adaptable); } if (filecount > 1) { switch (ret) { case 0: break; case 1: replaceAll = true; break; case 3: skipAll = true; /* FALL-THROUGH */ case 2: if (deleteTransferred) file.delete(); continue; default: return -1; } } else { switch (ret) { case 0: break; case 1: if (deleteTransferred) file.delete(); continue; default: return -1; } } } ftp.deleteFile(Core.encodeUrlSegment(filename)); // System.out.println(filename + " deleted"); //$NON-NLS-1$ } try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) { ftp.storeFile(Core.encodeUrlSegment(filename), in); // System.out.println(filename + " stored"); //$NON-NLS-1$ n++; } finally { if (deleteTransferred) file.delete(); monitor.worked(1); } } } return n; }
From source file:net.yacy.grid.io.assets.FTPStorageFactory.java
public FTPStorageFactory(String server, int port, String username, String password, boolean deleteafterread) throws IOException { this.server = server; this.username = username == null ? "" : username; this.password = password == null ? "" : password; this.port = port; this.deleteafterread = deleteafterread; this.ftpClient = new Storage<byte[]>() { @Override//from w w w . j a v a2 s .c o m public void checkConnection() throws IOException { return; } private FTPClient initConnection() throws IOException { FTPClient ftp = new FTPClient(); ftp.setDataTimeout(3000); ftp.setConnectTimeout(20000); if (FTPStorageFactory.this.port < 0 || FTPStorageFactory.this.port == DEFAULT_PORT) { ftp.connect(FTPStorageFactory.this.server); } else { ftp.connect(FTPStorageFactory.this.server, FTPStorageFactory.this.port); } ftp.enterLocalPassiveMode(); // the server opens a data port to which the client conducts data transfers int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { if (ftp != null) try { ftp.disconnect(); } catch (Throwable ee) { } throw new IOException("bad connection to ftp server: " + reply); } if (!ftp.login(FTPStorageFactory.this.username, FTPStorageFactory.this.password)) { if (ftp != null) try { ftp.disconnect(); } catch (Throwable ee) { } throw new IOException("login failure"); } ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.setBufferSize(8192); return ftp; } @Override public StorageFactory<byte[]> store(String path, byte[] asset) throws IOException { long t0 = System.currentTimeMillis(); FTPClient ftp = initConnection(); try { long t1 = System.currentTimeMillis(); String file = cdPath(ftp, path); long t2 = System.currentTimeMillis(); ftp.enterLocalPassiveMode(); boolean success = ftp.storeFile(file, new ByteArrayInputStream(asset)); long t3 = System.currentTimeMillis(); if (!success) throw new IOException("storage to path " + path + " was not successful (storeFile=false)"); Data.logger.debug("FTPStorageFactory.store ftp store successfull: check connection = " + (t1 - t0) + ", cdPath = " + (t2 - t1) + ", store = " + (t3 - t2)); } catch (IOException e) { throw e; } finally { if (ftp != null) try { ftp.disconnect(); } catch (Throwable ee) { } } return FTPStorageFactory.this; } @Override public Asset<byte[]> load(String path) throws IOException { FTPClient ftp = initConnection(); ByteArrayOutputStream baos = null; byte[] b = null; try { String file = cdPath(ftp, path); baos = new ByteArrayOutputStream(); ftp.retrieveFile(file, baos); b = baos.toByteArray(); if (FTPStorageFactory.this.deleteafterread) try { boolean deleted = ftp.deleteFile(file); FTPFile[] remaining = ftp.listFiles(); if (remaining.length == 0) { ftp.cwd("/"); if (path.startsWith("/")) path = path.substring(1); int p = path.indexOf('/'); if (p > 0) path = path.substring(0, p); ftp.removeDirectory(path); } } catch (Throwable e) { Data.logger.warn("FTPStorageFactory.load failed to remove asset " + path, e); } } catch (IOException e) { throw e; } finally { if (ftp != null) try { ftp.disconnect(); } catch (Throwable ee) { } } return new Asset<byte[]>(FTPStorageFactory.this, b); } @Override public void close() { } private String cdPath(FTPClient ftp, String path) throws IOException { int success_code = ftp.cwd("/"); if (success_code >= 300) throw new IOException("cannot cd into " + path + ": " + success_code); if (path.length() == 0 || path.equals("/")) return ""; if (path.charAt(0) == '/') path = path.substring(1); // we consider that all paths are absolute to / (home) int p; while ((p = path.indexOf('/')) > 0) { String dir = path.substring(0, p); int code = ftp.cwd(dir); if (code >= 300) { // path may not exist, try to create the path boolean success = ftp.makeDirectory(dir); if (!success) throw new IOException("unable to create directory " + dir + " for path " + path); code = ftp.cwd(dir); if (code >= 300) throw new IOException("unable to cwd into directory " + dir + " for path " + path); } path = path.substring(p + 1); } return path; } }; }
From source file:nz.govt.natlib.ndha.common.FileUtils.java
public static void removeFTPDirectory(FTPClient ftpClient, String directoryName) { try {/* w w w.j av a 2 s .c om*/ ftpClient.changeWorkingDirectory(directoryName); for (FTPFile file : ftpClient.listFiles()) { if (file.isDirectory()) { FileUtils.removeFTPDirectory(ftpClient, file.getName()); } else { log.debug("Deleting " + file.getName()); ftpClient.deleteFile(file.getName()); } } ftpClient.changeWorkingDirectory(directoryName); ftpClient.changeToParentDirectory(); log.debug("Deleting " + directoryName); ftpClient.removeDirectory(directoryName); } catch (Exception ex) { } }
From source file:org.alfresco.filesys.FTPServerTest.java
/** * Test CRUD for FTP server//from ww w . ja v a2 s .c om * * @throws Exception */ public void testCRUD() throws Exception { final String PATH1 = "FTPServerTest"; final String PATH2 = "Second part"; logger.debug("Start testFTPCRUD"); FTPClient ftp = connectClient(); try { int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { fail("FTP server refused connection."); } boolean login = ftp.login(USER_ADMIN, PASSWORD_ADMIN); assertTrue("admin login successful", login); reply = ftp.cwd("/Alfresco/User Homes"); assertTrue(FTPReply.isPositiveCompletion(reply)); // Delete the root directory in case it was left over from a previous test run try { ftp.removeDirectory(PATH1); } catch (IOException e) { // ignore this error } // make root directory ftp.makeDirectory(PATH1); ftp.cwd(PATH1); // make sub-directory in new directory ftp.makeDirectory(PATH2); ftp.cwd(PATH2); // List the files in the new directory FTPFile[] files = ftp.listFiles(); assertTrue("files not empty", files.length == 0); // Create a file String FILE1_CONTENT_1 = "test file 1 content"; String FILE1_NAME = "testFile1.txt"; ftp.appendFile(FILE1_NAME, new ByteArrayInputStream(FILE1_CONTENT_1.getBytes("UTF-8"))); // Get the new file FTPFile[] files2 = ftp.listFiles(); assertTrue("files not one", files2.length == 1); InputStream is = ftp.retrieveFileStream(FILE1_NAME); String content = inputStreamToString(is); assertEquals("Content is not as expected", content, FILE1_CONTENT_1); ftp.completePendingCommand(); // Update the file contents String FILE1_CONTENT_2 = "That's how it is says Pooh!"; ftp.storeFile(FILE1_NAME, new ByteArrayInputStream(FILE1_CONTENT_2.getBytes("UTF-8"))); InputStream is2 = ftp.retrieveFileStream(FILE1_NAME); String content2 = inputStreamToString(is2); assertEquals("Content is not as expected", FILE1_CONTENT_2, content2); ftp.completePendingCommand(); // now delete the file we have been using. assertTrue(ftp.deleteFile(FILE1_NAME)); // negative test - file should have gone now. assertFalse(ftp.deleteFile(FILE1_NAME)); } finally { // clean up tree if left over from previous run ftp.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. */// w ww.j av a2s .co 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(); } } }
From source file:org.alfresco.filesys.FTPServerTest.java
/** * Test Setting the modification time FTP server * * @throws Exception/*from www .jav a2 s .com*/ */ public void testModificationTime() throws Exception { final String PATH1 = "FTPServerTest"; final String PATH2 = "ModificationTime"; logger.debug("Start testModificationTime"); FTPClient ftp = connectClient(); try { int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { fail("FTP server refused connection."); } boolean login = ftp.login(USER_ADMIN, PASSWORD_ADMIN); assertTrue("admin login successful", login); reply = ftp.cwd("/Alfresco/User Homes"); assertTrue(FTPReply.isPositiveCompletion(reply)); // Delete the root directory in case it was left over from a previous test run try { ftp.removeDirectory(PATH1); } catch (IOException e) { // ignore this error } // make root directory ftp.makeDirectory(PATH1); ftp.cwd(PATH1); // make sub-directory in new directory ftp.makeDirectory(PATH2); ftp.cwd(PATH2); // List the files in the new directory FTPFile[] files = ftp.listFiles(); assertTrue("files not empty", files.length == 0); // Create a file String FILE1_CONTENT_1 = "test file 1 content"; String FILE1_NAME = "testFile1.txt"; ftp.appendFile(FILE1_NAME, new ByteArrayInputStream(FILE1_CONTENT_1.getBytes("UTF-8"))); String pathname = "/Alfresco/User Homes" + "/" + PATH1 + "/" + PATH2 + "/" + FILE1_NAME; logger.debug("set modification time"); // YYYYMMDDhhmmss Time set to 2012 August 30 12:39:05 String olympicTime = "20120830123905"; ftp.setModificationTime(pathname, olympicTime); String extractedTime = ftp.getModificationTime(pathname); // Feature of the commons ftp library ExtractedTime has a "status code" first and is followed by newline chars assertTrue("time not set correctly by explicit set time", extractedTime.contains(olympicTime)); // Get the new file FTPFile[] files2 = ftp.listFiles(); assertTrue("files not one", files2.length == 1); InputStream is = ftp.retrieveFileStream(FILE1_NAME); String content = inputStreamToString(is); assertEquals("Content is not as expected", content, FILE1_CONTENT_1); ftp.completePendingCommand(); // Update the file contents without setting time directly String FILE1_CONTENT_2 = "That's how it is says Pooh!"; ftp.storeFile(FILE1_NAME, new ByteArrayInputStream(FILE1_CONTENT_2.getBytes("UTF-8"))); InputStream is2 = ftp.retrieveFileStream(FILE1_NAME); String content2 = inputStreamToString(is2); assertEquals("Content is not as expected", FILE1_CONTENT_2, content2); ftp.completePendingCommand(); extractedTime = ftp.getModificationTime(pathname); assertFalse("time not moved on if time not explicitly set", extractedTime.contains(olympicTime)); // now delete the file we have been using. assertTrue(ftp.deleteFile(FILE1_NAME)); // negative test - file should have gone now. assertFalse(ftp.deleteFile(FILE1_NAME)); } finally { // clean up tree if left over from previous run ftp.disconnect(); } }