List of usage examples for org.apache.commons.net.ftp FTPClient completePendingCommand
public boolean completePendingCommand() throws IOException
From source file:org.ramadda.repository.type.FtpTypeHandler.java
/** * _more_/*from w w w . j a v a 2 s . c o m*/ * * @param request _more_ * @param mainEntry _more_ * @param parentEntry _more_ * @param synthId _more_ * * @return _more_ * * @throws Exception _more_ */ public List<String> getSynthIds(Request request, Entry mainEntry, Entry parentEntry, String synthId) throws Exception { long t0 = System.currentTimeMillis(); List<String> ids = new ArrayList<String>(); Object[] values = mainEntry.getValues(); String baseDir = (String) values[COL_BASEDIR]; String path = getPathFromId(synthId, baseDir); /* boolean descending = !request.get(ARG_ASCENDING, false); if (request.getString(ARG_ORDERBY, "").equals("name")) { files = IOUtil.sortFilesOnName(files, descending); } else { files = IOUtil.sortFilesOnAge(files, descending); }*/ long t1 = System.currentTimeMillis(); FTPClient ftpClient = getFtpClient(mainEntry); if (ftpClient == null) { return ids; } long t2 = System.currentTimeMillis(); // System.err.println ("getFtpClient:" + (t2-t1)); try { String pattern = (String) values[COL_FILE_PATTERN]; if ((pattern != null) && (pattern.trim().length() == 0)) { pattern = null; } boolean isDir = ftpClient.changeWorkingDirectory(path); if (isDir) { boolean checkReadme = parentEntry.getDescription().length() == 0; checkReadme = false; long t3 = System.currentTimeMillis(); FTPFile[] files = ftpClient.listFiles(path); long t4 = System.currentTimeMillis(); // System.err.println ("listFiles:" + (t4-t3)); for (int i = 0; i < files.length; i++) { String name = files[i].getName().toLowerCase(); if ((pattern != null) && !name.matches(pattern)) { continue; } if (checkReadme) { if (name.equals("readme") || name.equals("readme.txt")) { try { InputStream fis = ftpClient.retrieveFileStream(path + "/" + files[i].getName()); if (fis != null) { String desc = HtmlUtils.entityEncode(IOUtil.readInputStream(fis)); parentEntry.setDescription(HtmlUtils.pre(desc)); fis.close(); ftpClient.completePendingCommand(); } } catch (Exception exc) { // exc.printStackTrace(); } } } putCache(mainEntry, path + "/" + files[i].getName(), files[i]); ids.add(getSynthId(mainEntry, baseDir, path, files[i])); } } } finally { closeConnection(ftpClient); } long t5 = System.currentTimeMillis(); // System.err.println ("getSynthIds:" + (t5-t0)); return ids; }
From source file:org.ut.biolab.medsavant.shared.util.SeekableFTPStream.java
private int readFromStream(byte[] bytes, int offset, int len) throws IOException { FTPClient client = getFTPClient(); if (position != 0) { client.setRestartOffset(position); }//from w w w. j a v a 2s . co m InputStream is = client.retrieveFileStream(fileName); long oldPos = position; if (is != null) { int n = 0; while (n < len) { int bytesRead = is.read(bytes, offset + n, len - n); if (bytesRead < 0) { if (n == 0) return -1; else break; } n += bytesRead; } is.close(); LOG.info(String.format("FTP read %d bytes at %d: %02x %02x %02x %02x %02x %02x %02x %02x...", len, oldPos, bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4], bytes[offset + 5], bytes[offset + 6], bytes[offset + 7])); try { client.completePendingCommand(); } catch (FTPConnectionClosedException suppressed) { } catch (SocketTimeoutException stx) { // Accessing 1000 Genomes, we sometimes get a timeout for no apparent reason. LOG.info("Timed out during read. Disconnecting."); disconnect(); } position += n; return n; } else { String msg = String.format("Unable to retrieve input stream for file (reply code %d).", client.getReplyCode()); LOG.error(msg); throw new IOException(msg); } }
From source file:se.sll.reimbursementadapter.mule.NonDeletingFtpMessageReceiver.java
@Override protected void postProcess(FTPClient client, FTPFile file, MuleMessage message) throws Exception { if (connector.isStreaming()) { if (!client.completePendingCommand()) { throw new IOException(MessageFormat.format( "Failed to complete a pending command. Retrieveing file {0}. Ftp error: {1}", file.getName(), client.getReplyCode())); }// w w w .j a va 2 s .co m } }
From source file:simplehttpdb.net.FTPHelper.java
private boolean writeFile(FTPClient ftpClient, byte[] content, String path) throws IOException { Logger.getLogger(getClass().getName()).log(Level.INFO, "writing local file: " + path + " content length=" + content.length); OutputStream os = ftpClient.storeFileStream(path); if (os == null) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "cannot open remote file " + path); return false; }//from w w w .j a v a2s .c o m os.write(content); os.close(); ftpClient.completePendingCommand(); return true; }