List of usage examples for org.apache.commons.net.io CopyStreamException printStackTrace
public void printStackTrace()
From source file:edu.cmu.cs.in.hoop.hoops.load.HoopFTPReader.java
/** * /*ww w .j a v a 2 s . c om*/ */ private String retrieveFTP(String aURL) { debug("retrieveFTP (" + aURL + ")"); URL urlObject = null; try { urlObject = new URL(aURL); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } String downloadPath = this.projectToFullPath("<PROJECTPATH>/tmp/download/"); HoopLink.fManager.createDirectory(downloadPath); File translator = new File(urlObject.getFile()); String localFileName = "<PROJECTPATH>/tmp/download/" + translator.getName(); OutputStream fileStream = null; if (HoopLink.fManager.openStreamBinary(this.projectToFullPath(localFileName)) == false) { this.setErrorString("Error opening temporary output file"); return (null); } fileStream = HoopLink.fManager.getOutputStreamBinary(); if (fileStream == null) { this.setErrorString("Error opening temporary output file"); return (null); } debug("Starting FTP client ..."); FTPClient ftp = new FTPClient(); try { int reply; debug("Connecting ..."); ftp.connect(urlObject.getHost()); debug("Connected to " + urlObject.getHost() + "."); debug(ftp.getReplyString()); // After connection attempt, you should check the reply code to verify // success. reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); debug("FTP server refused connection."); return (null); } else { ftp.login("anonymous", "hoop-dev@gmail.com"); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); debug("Unable to login to FTP server"); return (null); } debug("Logged in"); boolean rep = true; String pathFixed = translator.getParent().replace("\\", "/"); rep = ftp.changeWorkingDirectory(pathFixed); if (rep == false) { debug("Unable to change working directory to: " + pathFixed); return (null); } else { debug("Current working directory: " + pathFixed); debug("Retrieving file " + urlObject.getFile() + " ..."); try { rep = ftp.retrieveFile(urlObject.getFile(), fileStream); } catch (FTPConnectionClosedException connEx) { debug("Caught: FTPConnectionClosedException"); connEx.printStackTrace(); return (null); } catch (CopyStreamException strEx) { debug("Caught: CopyStreamException"); strEx.printStackTrace(); return (null); } catch (IOException ioEx) { debug("Caught: IOException"); ioEx.printStackTrace(); return (null); } debug("File retrieved"); } ftp.logout(); } } catch (IOException e) { debug("Error retrieving FTP file"); e.printStackTrace(); return (null); } finally { if (ftp.isConnected()) { debug("Closing ftp connection ..."); try { ftp.disconnect(); } catch (IOException ioe) { debug("Exception closing ftp connection"); } } } debug("Closing local file stream ..."); try { fileStream.close(); } catch (IOException e) { e.printStackTrace(); } String result = HoopLink.fManager.loadContents(this.projectToFullPath(localFileName)); return (result); }