Search in sources :

Example 71 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)

Example 72 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 73 with FTPClient

use of org.apache.commons.net.ftp.FTPClient in project camel by apache.

the class FtpBadLoginMockNoopConnectionLeakTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    FtpEndpoint<?> endpoint = context.getEndpoint(getFtpUrl(), FtpEndpoint.class);
    endpoint.setFtpClient(new FTPClient() {

        @Override
        public boolean sendNoOp() throws IOException {
            // return true as long as connection is established
            return this.isConnected();
        }
    });
}
Also used : IOException(java.io.IOException) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 74 with FTPClient

use of org.apache.commons.net.ftp.FTPClient in project ddf by codice.

the class TestFtp method createInsecureClient.

private FTPClient createInsecureClient() throws Exception {
    FTPClient ftp = new FTPClient();
    int attempts = 0;
    while (true) {
        try {
            ftp.connect(FTP_SERVER, Integer.parseInt(FTP_PORT.getPort()));
            break;
        } catch (SocketException e) {
            //a socket exception can be thrown if the ftp server is still in the process of coming up or down
            Thread.sleep(1000);
            if (attempts++ > 30) {
                throw e;
            }
        }
    }
    showServerReply(ftp);
    int connectionReply = ftp.getReplyCode();
    if (!FTPReply.isPositiveCompletion(connectionReply)) {
        fail("FTP server refused connection: " + connectionReply);
    }
    boolean success = ftp.login(USERNAME, PASSWORD);
    showServerReply(ftp);
    if (!success) {
        fail("Could not log in to the FTP server.");
    }
    ftp.enterLocalPassiveMode();
    ftp.setControlKeepAliveTimeout(300);
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
    return ftp;
}
Also used : SocketException(java.net.SocketException) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 75 with FTPClient

use of org.apache.commons.net.ftp.FTPClient in project nifi by apache.

the class FTPTransfer method getInputStream.

@Override
public InputStream getInputStream(final String remoteFileName, final FlowFile flowFile) throws IOException {
    final FTPClient client = getClient(flowFile);
    InputStream in = client.retrieveFileStream(remoteFileName);
    if (in == null) {
        throw new IOException(client.getReplyString());
    }
    return in;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) FTPClient(org.apache.commons.net.ftp.FTPClient)

Aggregations

FTPClient (org.apache.commons.net.ftp.FTPClient)128 IOException (java.io.IOException)78 FTPFile (org.apache.commons.net.ftp.FTPFile)36 Test (org.junit.Test)25 InputStream (java.io.InputStream)20 FrameworkException (org.structr.common.error.FrameworkException)20 Tx (org.structr.core.graph.Tx)20 FtpTest (org.structr.web.files.FtpTest)20 File (java.io.File)13 ByteArrayInputStream (java.io.ByteArrayInputStream)10 FileInputStream (java.io.FileInputStream)10 FileOutputStream (java.io.FileOutputStream)8 OutputStream (java.io.OutputStream)5 UnknownHostException (java.net.UnknownHostException)5 ConnectException (java.net.ConnectException)4 PrintCommandListener (org.apache.commons.net.PrintCommandListener)4 FTPSClient (org.apache.commons.net.ftp.FTPSClient)4 FTPUtils (com.cas.sim.tis.util.FTPUtils)3 FileNotFoundException (java.io.FileNotFoundException)3 MalformedURLException (java.net.MalformedURLException)3