List of usage examples for java.net SocketException getStackTrace
public StackTraceElement[] getStackTrace()
From source file:rems.Global.java
public static String[] GetFileList(InetAddress ftpServerAddrs, String serverAppDirectory, String dirName, String userName, String password) { String[] downloadFiles = new String[1]; StringBuilder result = new StringBuilder(); FTPClient ftpClient = new FTPClient(); try {//from w ww .j a va2 s . co m // pass directory path on server to connect ftpClient.connect(ftpServerAddrs); // pass username and password, returned true if authentication is // successful boolean login = ftpClient.login(userName, password); if (login) { //System.out.println("Connection established..."); // get all files from server and store them in an array of // FTPFiles FTPFile[] files = ftpClient.listFiles(); for (FTPFile file : files) { if (file.getType() == FTPFile.FILE_TYPE) { result.append(file.getName()); result.append("\n"); } } result.replace(result.toString().lastIndexOf("\n"), result.toString().length(), ""); // logout the user, returned true if logout successfully boolean logout = ftpClient.logout(); if (logout) { System.out.println("Connection close..."); } } else { System.out.println("Connection fail..."); } return result.toString().split("\\\n"); } catch (SocketException e) { Global.errorLog += Arrays.toString(e.getStackTrace()); Global.writeToLog(); } catch (IOException e) { Global.errorLog += Arrays.toString(e.getStackTrace()); Global.writeToLog(); } finally { try { ftpClient.disconnect(); } catch (IOException e) { Global.errorLog += Arrays.toString(e.getStackTrace()); Global.writeToLog(); } } return downloadFiles; }
From source file:rems.Global.java
public static String DownloadFile(InetAddress ftpserverurl, String serverAppDirectory, String PureFileName, String fullLocFileUrl, String userName, String password) { File f = new File(fullLocFileUrl); // get an ftpClient object FTPClient ftpClient = new FTPClient(); String responsTxt = ""; try {/*from www.java2 s .c o m*/ // pass directory path on server to connect ftpClient.connect(ftpserverurl, 21); // pass username and password, returned true if authentication is // successful boolean login = ftpClient.login(userName, password); if (login) { ftpClient.enterLocalPassiveMode(); //ftpClient.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(f)); boolean download = ftpClient.retrieveFile(serverAppDirectory + PureFileName, outputStream1); outputStream1.close(); //fos = new FileOutputStream(fullLocFileUrl); //boolean download = ftpClient.retrieveFile(serverAppDirectory + PureFileName, fos); responsTxt = ftpClient.getReplyString(); if (download) { responsTxt += "File downloaded successfully !"; } else { responsTxt += "Error in downloading file !::" + serverAppDirectory + PureFileName; } Global.updateLogMsg(Global.logMsgID, "\r\n\r\nDownload Response ==>\r\n" + responsTxt, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); // logout the user, returned true if logout successfully boolean logout = ftpClient.logout(); if (logout) { //System.out.println("Connection close..."); } } else { Global.errorLog += "Connection Failed..." + responsTxt; Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); } return responsTxt; } catch (SocketException e) { Global.errorLog += Arrays.toString(e.getStackTrace()); Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); } catch (IOException e) { Global.errorLog += Arrays.toString(e.getStackTrace()); Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); } finally { try { ftpClient.disconnect(); } catch (IOException e) { Global.errorLog += Arrays.toString(e.getStackTrace()); Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); } finally { } } Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + responsTxt, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); return responsTxt; }
From source file:rems.Global.java
public static String UploadFile(InetAddress ftpserverurl, String serverAppDirectory, String PureFileName, String fullLocFileUrl, String userName, String password) { // get an ftpClient object FTPClient ftpClient = new FTPClient(); FileInputStream inputStream = null; String responsTxt = ""; try {//ww w. j a va 2s . co m // pass directory path on server to connect // pass username and password, returned true if authentication is // successful ftpClient.connect(ftpserverurl, 21); boolean login = ftpClient.login(userName, password); ftpClient.setKeepAlive(false); ftpClient.setPassiveNatWorkaround(true); if (login) { ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); File firstLocalFile = new File(fullLocFileUrl); inputStream = new FileInputStream(firstLocalFile); //inputStream.reset(); boolean uploaded = ftpClient.storeFile(serverAppDirectory + PureFileName, inputStream); inputStream.close(); responsTxt = ftpClient.getReplyString(); if (uploaded) { responsTxt += "File uploaded successfully !"; } else { responsTxt += "Error in uploading file !::" + serverAppDirectory + PureFileName; } Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nUpload Response ==>\r\n" + responsTxt, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); // logout the user, returned true if logout successfully boolean logout = ftpClient.logout(); if (logout) { //System.out.println("Connection close..."); } } else { Global.errorLog += "Connection Failed..." + responsTxt; Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); } return responsTxt; } catch (SocketException e) { Global.errorLog += e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()); Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); } catch (IOException e) { Global.errorLog += e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()); Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); } finally { try { ftpClient.disconnect(); } catch (IOException e) { Global.errorLog += e.getMessage() + "\r\n" + Arrays.toString(e.getStackTrace()); Global.updateLogMsg(Global.logMsgID, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.writeToLog(); } finally { } } return ""; }