Search in sources :

Example 21 with FTPClient

use of org.apache.commons.net.ftp.FTPClient in project cubrid-manager by CUBRID.

the class FtpUtil method connectServer.

/**
	 * Connect the server
	 *
	 * @param server String
	 * @param userName String
	 * @param userPassword String
	 * @param driverPath String
	 * @throws IOException The exception
	 */
public void connectServer(String server, String userName, String userPassword, String driverPath) throws IOException {
    ftpClient = new FTPClient();
    ftpClient.connect(server);
    ftpClient.login(userName, userPassword);
    ftpClient.changeWorkingDirectory(driverPath);
    ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
    ftpClient.enterLocalPassiveMode();
}
Also used : FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 22 with FTPClient

use of org.apache.commons.net.ftp.FTPClient in project azure-tools-for-java by Microsoft.

the class AppServiceChangeSettingsDialog method editAppService.

protected WebApp editAppService(WebApp webApp, IProgressIndicator progressIndicator) throws Exception {
    if (model.jdkDownloadUrl != null) {
        progressIndicator.setText("Turning App Service into .Net based...");
    //webApp.update().withNetFrameworkVersion(NetFrameworkVersion.V4_6).apply();
    //progressIndicator.setText("Deploying custom jdk...");
    //WebAppUtils.deployCustomJdk(webApp, model.jdkDownloadUrl, model.webContainer, progressIndicator);
    } else {
        FTPClient ftpClient = WebAppUtils.getFtpConnection(webApp.getPublishingProfile());
        progressIndicator.setText("Deleting custom jdk artifacts, if any (takes a while)...");
        WebAppUtils.removeCustomJdkArtifacts(ftpClient, progressIndicator);
        // TODO: make cancelable
        WebAppUtils.removeCustomJdkArtifacts(WebAppUtils.getFtpConnection(webApp.getPublishingProfile()), progressIndicator);
        progressIndicator.setText("Applying changes...");
        webApp.update().withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(model.webContainer).apply();
    }
    return webApp;
}
Also used : FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 23 with FTPClient

use of org.apache.commons.net.ftp.FTPClient in project azure-tools-for-java by Microsoft.

the class WebAppUtils method getFtpConnection.

public static FTPClient getFtpConnection(PublishingProfile pp) throws IOException {
    FTPClient ftp = new FTPClient();
    System.out.println("\t\t" + pp.ftpUrl());
    System.out.println("\t\t" + pp.ftpUsername());
    System.out.println("\t\t" + pp.ftpPassword());
    URI uri = URI.create("ftp://" + pp.ftpUrl());
    ftp.connect(uri.getHost(), 21);
    final int replyCode = ftp.getReplyCode();
    if (!FTPReply.isPositiveCompletion(replyCode)) {
        ftp.disconnect();
        throw new ConnectException("Unable to connect to FTP server");
    }
    if (!ftp.login(pp.ftpUsername(), pp.ftpPassword())) {
        throw new ConnectException("Unable to login to FTP server");
    }
    ftp.setControlKeepAliveTimeout(Constants.connection_read_timeout_ms);
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
    //Switch to passive mode
    ftp.enterLocalPassiveMode();
    return ftp;
}
Also used : URI(java.net.URI) FTPClient(org.apache.commons.net.ftp.FTPClient) ConnectException(java.net.ConnectException)

Example 24 with FTPClient

use of org.apache.commons.net.ftp.FTPClient 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();
        }
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) FTPFile(org.apache.commons.net.ftp.FTPFile) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 25 with FTPClient

use of org.apache.commons.net.ftp.FTPClient in project azure-tools-for-java by Microsoft.

the class WebAppUtils method uploadWebConfig.

public static void uploadWebConfig(WebApp webApp, InputStream fileStream, IProgressIndicator indicator) throws IOException {
    FTPClient ftp = null;
    try {
        PublishingProfile pp = webApp.getPublishingProfile();
        ftp = getFtpConnection(pp);
        if (indicator != null)
            indicator.setText("Stopping the service...");
        webApp.stop();
        if (indicator != null)
            indicator.setText("Uploading " + webConfigFilename + "...");
        ftp.storeFile(ftpRootPath + webConfigFilename, fileStream);
        if (indicator != null)
            indicator.setText("Starting the service...");
        webApp.start();
    } finally {
        if (ftp != null && ftp.isConnected()) {
            ftp.disconnect();
        }
    }
}
Also used : FTPClient(org.apache.commons.net.ftp.FTPClient)

Aggregations

FTPClient (org.apache.commons.net.ftp.FTPClient)27 IOException (java.io.IOException)12 InputStream (java.io.InputStream)3 Path (org.apache.hadoop.fs.Path)3 DataXException (com.alibaba.datax.common.exception.DataXException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ConnectException (java.net.ConnectException)2 MalformedURLException (java.net.MalformedURLException)2 UnknownHostException (java.net.UnknownHostException)2 FTPFile (org.apache.commons.net.ftp.FTPFile)2 Configuration (org.apache.hadoop.conf.Configuration)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 ConnectionString (com.microsoft.azure.management.appservice.ConnectionString)1 TrafficManagerAzureEndpoint (com.microsoft.azure.management.trafficmanager.TrafficManagerAzureEndpoint)1 TrafficManagerExternalEndpoint (com.microsoft.azure.management.trafficmanager.TrafficManagerExternalEndpoint)1