public static String loadFilesFromSFTP( String fileName, String localDirectory, String username, String password, String serverPath, int port) throws Exception { int i = 1; if (i == 1) throw new Exception(); try { String[] strArray = splitHostNameAndDirectory(serverPath); if (!((strArray[0].length() > 0) && (strArray[1].length() > 0))) { return "F+Invalid server path.+" + "Error Occurred in loadFilesFromSFTP(): " + errorMessage; } String strHost = strArray[0]; String strServerDirectory = strArray[1]; setProperties(strServerDirectory, localDirectory, username, password, strHost, port); boolean validConnection = getConnection(username, password, strHost, port); if (validConnection) { boolean isAccessible = goToServerDirectory(); if (isAccessible) { if (!isDirecotryExist(processedDirectory)) sftpChannel.mkdir(processedDirectory); getIVRSTrialList(); if (fileName.matches( "\\x2A\\x2E(([\\p{Alnum}]{3,4})|(\\x2A))")) // pattern for [*.txt] or [*.html] // // [*->42(Ox2A) and .->46(Ox2E)] { int dotPos = fileName.toLowerCase().lastIndexOf('.', fileName.length()); String fileType = fileName.toLowerCase().substring(dotPos, fileName.length()); downloadAllFiles(fileType); } else { totalFileCount = 1; downloadFileByName(fileName); } } disconnectFromSFTP(); errorMessageFurnishing(); if ((totalFileCount == 0) && (downloadedFileCount == 0)) { logMessage = "T+" + "Server has no files to download.+" + errorMessage; } else if (totalFileCount != downloadedFileCount) { logMessage = "T+" + downloadedFileCount + " file(s) downloaded out of " + totalFileCount + " files.+" + errorMessage; } else if (totalFileCount == downloadedFileCount) { logMessage = "T+Successfully " + downloadedFileCount + " file(s) downloaded.+" + errorMessage; } } else { logMessage = "F+Connection Error Occurred.+" + errorMessage; } return logMessage; } catch (Exception e) { disconnectFromSFTP(); System.out.println("Exception in loadFilesFromSFTP(): " + e.toString()); errorMessage += "Exception in loadFilesFromSFTP(): " + e.toString(); return "F+Error Occurred in loadFilesFromSFTP()+" + errorMessage; } }