List of usage examples for org.apache.commons.net.ftp FTPClient retrieveFileStream
public InputStream retrieveFileStream(String remote) throws IOException
From source file:uk.ac.manchester.cs.datadesc.validator.utils.UrlReader.java
private InputStream getInputStream(FTPClient ftp) throws VoidValidatorException { try {/*from ww w. j a v a 2s . co m*/ // in theory this should not be necessary as servers should default to ASCII // but they don't all do so - see NET-500 ftp.setFileType(FTP.ASCII_FILE_TYPE); ftp.enterLocalPassiveMode(); ftp.setUseEPSVwithIPv4(useEpsvWithIPv4); String path = uri.getPath(); return ftp.retrieveFileStream(path); } catch (FTPConnectionClosedException ex) { disconnect(ftp); throw new VoidValidatorException("Server closed connection.", ex); } catch (IOException ex) { disconnect(ftp); throw new VoidValidatorException("IOEXception with Server ", ex); } }
From source file:websync2.SyncDesign.java
public void copyFileFTP(File temp, File servF) { InputStream inputStream = null; try {//from w w w . j a v a 2 s . com FTPClient ftpclient = ftp.getFtpClient(); ftpclient.changeToParentDirectory(); String firstRemoteFile = servF.getAbsolutePath(); String[] pathA = firstRemoteFile.split("/"); if (pathA != null) { for (int i = 0; i < pathA.length - 1; i++) { if ("".equals(pathA[i])) { continue; } InputStream is = ftpclient.retrieveFileStream(pathA[i]); int retCode = ftpclient.getReplyCode(); if (retCode == 550) { ftpclient.makeDirectory(pathA[i]); } ftpclient.changeWorkingDirectory(pathA[i]); } inputStream = new FileInputStream(temp); boolean done = ftpclient.storeFile(pathA[pathA.length - 1], inputStream); if (done) { System.out.println("The first file is uploaded successfully."); } } } catch (FileNotFoundException ex) { Logger.getLogger(SyncDesign.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(SyncDesign.class.getName()).log(Level.SEVERE, null, ex); } finally { try { inputStream.close(); } catch (IOException ex) { Logger.getLogger(SyncDesign.class.getName()).log(Level.SEVERE, null, ex); } } }