List of usage examples for org.apache.commons.net.ftp FTPClient listDirectories
public FTPFile[] listDirectories(String parent) throws IOException
From source file:com.microsoft.azuretools.utils.WebAppUtils.java
public static void deployCustomJdk(WebApp webApp, String jdkDownloadUrl, WebContainer webContainer, IProgressIndicator indicator) throws IOException, InterruptedException, WebAppException { FTPClient ftp = null; String customJdkFolderName = null; try {// w ww .j av a2 s .c o m PublishingProfile pp = webApp.getPublishingProfile(); ftp = getFtpConnection(pp); // stop and restart web app // if (indicator != null) indicator.setText("Stopping the service..."); // webApp.stop(); if (indicator != null) indicator.setText("Deleting custom jdk artifacts, if any (takes a while)..."); removeCustomJdkArtifacts(ftp, indicator); if (indicator != null) indicator.setText("Uploading scripts..."); uploadJdkDownloadScript(ftp, jdkDownloadUrl); // if (indicator != null) indicator.setText("Starting the service..."); // webApp.start(); final String siteUrl = "https://" + webApp.defaultHostName(); // send get to activate the script sendGet(siteUrl); // Polling report.txt... if (indicator != null) indicator.setText("Checking the JDK gets downloaded and unpacked..."); //int step = 0; while (!doesRemoteFileExist(ftp, ftpRootPath, reportFilename)) { if (indicator != null && indicator.isCanceled()) throw new CancellationException("Canceled by user."); //if (step++ > 3) checkFreeSpaceAvailability(ftp); Thread.sleep(5000); sendGet(siteUrl); } if (indicator != null) indicator.setText("Checking status..."); OutputStream reportFileStream = new ByteArrayOutputStream(); ftp.retrieveFile("report.txt", reportFileStream); String reportFileString = reportFileStream.toString(); if (reportFileString.startsWith("FAIL")) { String err = reportFileString.substring(reportFileString.indexOf(":" + 1)); throw new WebAppException(err); } // get top level jdk folder name (under jdk folder) FTPFile[] ftpDirs = ftp.listDirectories(ftpJdkPath); if (ftpDirs.length != 1) { String err = "Bad JDK archive. Please make sure the JDK archive contains a single JDK folder. For example, 'my-jdk1.7.0_79.zip' archive should contain 'jdk1.7.0_79' folder only"; throw new WebAppException(err); } customJdkFolderName = ftpDirs[0].getName(); uploadWebConfigForCustomJdk(ftp, webApp, customJdkFolderName, webContainer, indicator); } catch (IOException | WebAppException | InterruptedException ex) { if (doesRemoteFolderExist(ftp, ftpRootPath, jdkFolderName)) { indicator.setText("Error happened. Cleaning up..."); removeFtpDirectory(ftp, ftpJdkPath, indicator); } throw ex; } finally { indicator.setText("Removing working data from server..."); cleanupWorkerData(ftp); if (ftp != null && ftp.isConnected()) { ftp.disconnect(); } } }