use of org.apache.commons.net.ftp.FTPFile in project camel by apache.
the class FtpOperations method listFiles.
public List<FTPFile> listFiles() throws GenericFileOperationFailedException {
log.trace("listFiles()");
try {
final List<FTPFile> list = new ArrayList<FTPFile>();
FTPFile[] files = client.listFiles();
// can return either null or an empty list depending on FTP servers
if (files != null) {
list.addAll(Arrays.asList(files));
}
return list;
} catch (IOException e) {
throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
}
}
use of org.apache.commons.net.ftp.FTPFile in project azure-tools-for-java by Microsoft.
the class WebAppUtils method removeFtpDirectory.
public static void removeFtpDirectory(FTPClient ftpClient, String path, IProgressIndicator pi) throws IOException {
String prefix = "Removing from FTP server: ";
FTPFile[] subFiles = ftpClient.listFiles(path);
if (subFiles.length > 0) {
for (FTPFile ftpFile : subFiles) {
if (pi != null && pi.isCanceled())
break;
String currentFileName = ftpFile.getName();
if (currentFileName.equals(".") || currentFileName.equals("..")) {
// skip
continue;
}
String path1 = path + "/" + currentFileName;
if (ftpFile.isDirectory()) {
// remove the sub directory
removeFtpDirectory(ftpClient, path1, pi);
} else {
// delete the file
if (pi != null)
pi.setText2(prefix + path1);
ftpClient.deleteFile(path1);
}
}
}
if (pi != null)
pi.setText2(prefix + path);
ftpClient.removeDirectory(path);
if (pi != null)
pi.setText2("");
}
use of org.apache.commons.net.ftp.FTPFile in project azure-tools-for-java by Microsoft.
the class WebAppUtils method deployCustomJdk.
public static void deployCustomJdk(WebApp webApp, String jdkDownloadUrl, WebContainer webContainer, IProgressIndicator indicator) throws IOException, InterruptedException, WebAppException {
FTPClient ftp = null;
String customJdkFolderName = null;
try {
PublishingProfile pp = webApp.getPublishingProfile();
ftp = getFtpConnection(pp);
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();
}
}
}
Aggregations