Example usage for org.apache.commons.net.ftp FTPClient FTPClient

List of usage examples for org.apache.commons.net.ftp FTPClient FTPClient

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPClient FTPClient.

Prototype

public FTPClient() 

Source Link

Document

Default FTPClient constructor.

Usage

From source file:nz.govt.natlib.ndha.wctdpsdepositor.filemover.FtpClientFactoryImpl.java

public FTPClient createInstance() {
    return new FTPClient();
}

From source file:onl.area51.filesystem.ftp.client.DefaultFTPClient.java

DefaultFTPClient(FTPClientBuilder builder) {
    this.useEpsvWithIPv4 = builder.useEpsvWithIPv4;
    this.localActive = builder.localActive;
    this.binaryTransfer = builder.binaryTransfer;

    this.debuggingEnabled = builder.debuggingEnabled && builder.consumer != null;

    if (builder.proxy == null) {
        ftp = new FTPClient();
    } else {/*  w w w .j a va2  s . c  o  m*/
        if (builder.proxyUser == null) {
            ftp = new FTPHTTPClient(builder.proxy, builder.proxyPort);
        } else {
            ftp = new FTPHTTPClient(builder.proxy, builder.proxyPort, builder.proxyUser, builder.proxyPass);
        }
    }

    if (builder.keepAliveTimeout >= 0) {
        ftp.setControlKeepAliveTimeout(builder.keepAliveTimeout);
    }

    if (builder.controlKeepAliveReplyTimeout >= 0) {
        ftp.setControlKeepAliveReplyTimeout(builder.controlKeepAliveReplyTimeout);
    }

    ftp.setListHiddenFiles(builder.listHiddenFiles);

    if (builder.consumer != null) {
        // Don't log blank lines
        writer = new WriterConsumer(builder.consumer, true);

        if (builder.printCommands) {
            // suppress login details
            ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(writer), true));
        }
    }
}

From source file:org.abstracthorizon.proximity.storage.remote.CommonsNetFtpRemotePeer.java

/**
 * Gets the FTP client.//from  www  .j av a  2  s.co m
 * 
 * @return the FTP client
 */
public FTPClient getFTPClient() {
    try {
        logger.info("Creating CommonsNetFTPClient instance");
        FTPClient ftpc = new FTPClient();
        ftpc.configure(ftpClientConfig);
        ftpc.connect(getRemoteUrl().getHost());
        ftpc.login(getFtpUsername(), getFtpPassword());
        ftpc.setFileType(FTPClient.BINARY_FILE_TYPE);
        return ftpc;
    } catch (SocketException ex) {
        throw new StorageException("Got SocketException while creating FTPClient", ex);
    } catch (IOException ex) {
        throw new StorageException("Got IOException while creating FTPClient", ex);
    }
}

From source file:org.alfresco.bm.file.FtpTestFileService.java

/**
 * Provides a safe (connected) FTP client
 *//*from   www .jav  a 2 s  .com*/
private FTPClient getFTPClient() throws IOException {
    // Connect to the FTP server
    FTPClient ftp = new FTPClient();

    // Connect and login 
    ftp.connect(ftpHost, ftpPort);
    if (!ftp.login(ftpUsername, ftpPassword)) {
        throw new IOException("FTP credentials rejected.");
    }

    if (ftpLocalPassiveMode) {
        ftp.enterLocalPassiveMode();
    }

    // Settings for the FTP channel
    ftp.setControlKeepAliveTimeout(300);
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
    ftp.setAutodetectUTF8(false);
    int reply = ftp.getReplyCode();

    if (!FTPReply.isPositiveCompletion(reply)) {
        throw new IOException("FTP server refused connection.");
    }

    // Done
    return ftp;
}

From source file:org.alfresco.filesys.FTPServerTest.java

private FTPClient connectClient() throws IOException {
    FTPClient ftp = new FTPClient();

    if (logger.isDebugEnabled()) {
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
    }//from  w  ww .  java 2s.c  om
    ftp.connect(HOSTNAME, ftpConfigSection.getFTPPort());
    return ftp;
}

From source file:org.amanzi.neo.geoptima.loader.ui.page.impl.SelectFtpDataPage.java

/**
 *
 *///from w w w .j  a va2 s . com
private void connectToFtp() {
    try {
        if (getConfiguration().getFtpClient() != null) {
            getConfiguration().getFtpClient().disconnect();
        }
        FTPClient client = new FTPClient();
        FTPClientConfig config = new FTPClientConfig();
        client.configure(config);

        client.connect(getUrl());
        client.login(userNameWidget.getText(), passwordWidget.getText());
        viewer.initialize(client);
        getConfiguration().setFtpClient(client);
    } catch (IOException e) {
        LOGGER.error("can't connect to server", e);
    }
}

From source file:org.apache.activemq.blob.FTPStrategy.java

protected FTPClient createFTP() throws IOException, JMSException {
    String connectUrl = url.getHost();
    setUserInformation(url.getUserInfo());
    int port = url.getPort() < 1 ? 21 : url.getPort();

    FTPClient ftp = new FTPClient();
    try {/*w  w w  . j av  a  2  s  .co  m*/
        ftp.connect(connectUrl, port);
    } catch (ConnectException e) {
        throw new JMSException("Problem connecting the FTP-server");
    }
    if (!ftp.login(ftpUser, ftpPass)) {
        ftp.quit();
        ftp.disconnect();
        throw new JMSException("Cant Authentificate to FTP-Server");
    }
    return ftp;
}

From source file:org.apache.camel.component.file.remote.FtpConsumerDisconnectTest.java

@Override
public void setUp() throws Exception {
    super.setUp();

    // ask the singleton FtpEndpoint to make use of a custom FTPClient
    // so that we can hold a reference on it inside the test below
    FtpEndpoint<?> endpoint = context.getEndpoint(getFtpUrl(), FtpEndpoint.class);
    endpoint.setFtpClient(new FTPClient());

    sendFile(getFtpUrl(), "Hello World", "claus.txt");
}

From source file:org.apache.camel.component.file.remote.FtpEndpoint.java

protected FTPClient createFtpClient() throws Exception {
    return new FTPClient();
}

From source file:org.apache.camel.component.file.remote.FtpProducerDisconnectTest.java

@Override
public void setUp() throws Exception {
    super.setUp();

    // ask the singleton FtpEndpoint to make use of a custom FTPClient
    // so that we can hold a reference on it inside the test below
    FtpEndpoint<?> endpoint = context.getEndpoint(getFtpUrl(), FtpEndpoint.class);
    endpoint.setFtpClient(new FTPClient());
}