List of usage examples for org.apache.commons.net.ftp FTPClient retrieveFileStream
public InputStream retrieveFileStream(String remote) throws IOException
From source file:com.jaeksoft.searchlib.crawler.file.process.fileInstances.FtpFileInstance.java
@Override public InputStream getInputStream() throws IOException { FTPClient f = null; try {/*w w w . ja va 2 s . co m*/ f = ftpConnect(); f.setFileType(FTP.BINARY_FILE_TYPE); return f.retrieveFileStream(getPath()); } catch (NoSuchAlgorithmException e) { throw new IOException(e); } finally { ftpQuietDisconnect(f); } }
From source file:heigit.ors.routing.traffic.providers.FtpDataSource.java
@Override public String getMessage() throws IOException { String message = null;//from www .j av a 2 s .co m try { FTPClient ftpClient = new FTPClient(); ftpClient.connect(server, port); ftpClient.login(user, password); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(2); String remoteFile1 = "/" + file; InputStream inputStream = ftpClient.retrieveFileStream(remoteFile1); message = StreamUtility.readStream(inputStream, "iso-8859-1"); Boolean success = ftpClient.completePendingCommand(); if (success) { System.out.println("File has been downloaded successfully."); } inputStream.close(); } catch (IOException e) { /* SendMail mail = new SendMail(); try { mail.postMail(this.properties.getProperty("mail"), "TMC-Fehler", e.getStackTrace().toString(), "TMC@Fehlermeldung.de", this.properties .getProperty("smtpHost"), this.properties .getProperty("smtpUser"), this.properties .getProperty("smtpPort")); } catch (MessagingException e1) { e1.printStackTrace(); } this.logger.debug("Error with FTP connection " + e.getLocalizedMessage(), e); throw new DownloadException( "Error while downloading file from FTP " + e.getLocalizedMessage(), e); */ } return message; }
From source file:net.audumla.climate.bom.BOMDataLoader.java
private boolean storeFTPFile(String host, String location, OutputStream os) { FTPClient ftp = getFTPClient(host); try {/* w w w. jav a2 s . c om*/ if (getFTPFile(host, location) != null) { synchronized (ftp) { IOUtils.copy(ftp.retrieveFileStream(location), os); } } else { return false; } } catch (IOException ex) { LOG.warn("Unable to load file " + location + " FTP Reply -> " + ftp.getReplyCode(), ex); return false; } finally { try { os.close(); } catch (Exception ex) { LOG.error("Unknown error encountered storing file " + location, ex); } } LOG.info("Retrieved remote FTP content - " + "ftp://" + host + location); try { if (!ftp.completePendingCommand()) { ftp.logout(); ftp.disconnect(); } } catch (Exception ex) { LOG.error("Unknown error encountered storing file " + location, ex); } return true; }
From source file:com.unicomer.opos.inhouse.gface.ejb.impl.GfaceGuatefacturasControlFtpEjbLocalImpl.java
public List<String> getFilesExists(List<String> fileNames) { List<String> ret = new ArrayList<String>(); try {/*w w w. j a v a 2 s . c om*/ HashMap<String, String> params = getFtpParams(); FTPClient ftpClient = getFtpClient(params); BufferedInputStream buffIn; ftpClient.enterLocalPassiveMode(); for (String nombre : fileNames) { buffIn = new BufferedInputStream(ftpClient .retrieveFileStream(params.get("remoteRetreiveFiles") + REMOTE_SEPARATOR + nombre));//Ruta completa de alojamiento en el FTP if (ftpClient.getReplyCode() == 150) { System.out.println("Archivo obtenido exitosamente"); buffIn.close(); ret.add(nombre); } else { System.out.println( "No se pudo obtener el archivo: " + nombre + ", codigo:" + ftpClient.getReplyCode()); } } ftpClient.logout(); //Cerrar sesin ftpClient.disconnect();//Desconectarse del servidor } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } return ret; }
From source file:com.unicomer.opos.inhouse.gface.ejb.impl.GfaceGuatefacturasControlFtpEjbLocalImpl.java
public void receive(List<String> fileNames) { try {//from w w w .jav a2s .co m HashMap<String, String> params = getFtpParams(); FTPClient ftpClient = getFtpClient(params); BufferedInputStream buffIn; ftpClient.enterLocalPassiveMode(); for (String nombre : fileNames) { buffIn = new BufferedInputStream(ftpClient .retrieveFileStream(params.get("remoteRetreiveFiles") + REMOTE_SEPARATOR + nombre));//Ruta completa de alojamiento en el FTP if (ftpClient.getReplyCode() == 150) { System.out.println("Archivo obtenido exitosamente"); // write the inputStream to a FileOutputStream OutputStream outputStream = new FileOutputStream( new File(params.get("localStoreFiles") + File.separator + nombre)); int read = 0; byte[] bytes = new byte[1024]; while ((read = buffIn.read(bytes)) != -1) { outputStream.write(bytes, 0, read); } buffIn.close(); //Cerrar envio de arcivos al FTP outputStream.close(); } else { System.out.println( "No se pudo obtener el archivo: " + nombre + ", codigo:" + ftpClient.getReplyCode()); } } ftpClient.logout(); //Cerrar sesin ftpClient.disconnect();//Desconectarse del servidor } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:com.globalsight.smartbox.util.FtpHelper.java
public InputStream ftpDownloadFile(String p_remoteFileName) { InputStream is = null;/*from www . jav a 2s .c o m*/ FTPClient ftpClient = getFtpClient(); if (ftpClient != null && ftpClient.isConnected()) { try { is = ftpClient.retrieveFileStream(p_remoteFileName); } catch (IOException e) { String message = "Failed to download file from InBox(in FTP), fileName: " + p_remoteFileName + "."; LogUtil.FAILEDLOG.error(message); } finally { closeFtpClient(ftpClient); } } return is; }
From source file:com.buzz.buzzdata.MongoBuzz.java
private InputStream getFTPInputStream(String ftp_location) { InputStream retval = null;//w ww .j a v a 2 s. c om String server = "162.219.245.61"; int port = 21; String user = "jelastic-ftp"; String pass = "HeZCHxeefB"; FTPClient ftpClient = new FTPClient(); try { ftpClient.connect(server, port); ftpClient.login(user, pass); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE); retval = ftpClient.retrieveFileStream(ftp_location); } catch (IOException ex) { Logger.getLogger(MongoBuzz.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (ftpClient.isConnected()) { ftpClient.disconnect(); } } catch (IOException ex) { Logger.getLogger(MongoBuzz.class.getName()).log(Level.SEVERE, null, ex); } } return retval; }
From source file:com.bdaum.zoom.net.ui.internal.NetActivator.java
public InputStream retrieveFile(Object ticket, URL url) throws IOException { FTPClient client = getClient(ticket, url); String path = url.getPath();// w w w . j a v a 2s . co m int p = path.lastIndexOf('/'); if (p >= 0) { String dir = path.substring(0, p); if (!client.changeWorkingDirectory(dir)) throw new FileNotFoundException(dir); path = path.substring(p + 1); } return client.retrieveFileStream(path); }
From source file:com.clickha.nifi.processors.util.FTPTransferV2.java
@Override public InputStream getInputStream(final String remoteFileName, final FlowFile flowFile) throws IOException { final FTPClient client = getClient(null); InputStream in = client.retrieveFileStream(remoteFileName); if (in == null) { throw new IOException(client.getReplyString()); }//from ww w . ja v a2 s . c om return in; }
From source file:com.nostra13.universalimageloader.core.download.BaseImageDownloader.java
protected InputStream getStreamFromFTPNetwork(String imageUri, Object extra) throws IOException { int indexUrl = imageUri.indexOf("//") + 1; int indexUrlFinal = imageUri.lastIndexOf(":"); int slash = imageUri.lastIndexOf("/"); String ip = imageUri.substring(indexUrl + 1, indexUrlFinal); FTPClient client = new FTPClient(); client.connect(ip, 20000);// w w w . j a v a 2 s . c om client.login("anonymous", ""); client.setFileType(FTP.BINARY_FILE_TYPE); client.enterLocalPassiveMode(); InputStream imageStream = null; FTPFile[] directories = client.listFiles(); long fileLength = (int) getFile(directories, imageUri.substring(slash + 1)).getSize(); try { imageStream = client.retrieveFileStream(imageUri.substring(slash + 1)); } catch (IOException e) { // Read all data to allow reuse connection (http://bit.ly/1ad35PY) IoUtils.readAndCloseStream(imageStream); throw e; } return new ContentLengthInputStream(new BufferedInputStream(imageStream, BUFFER_SIZE), fileLength); }