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

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

Introduction

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

Prototype

public void addProtocolCommandListener(ProtocolCommandListener listener) 

Source Link

Document

Adds a ProtocolCommandListener.

Usage

From source file:uk.ac.manchester.cs.datadesc.validator.utils.UrlReader.java

private FTPClient connect() throws VoidValidatorException {
    FTPClient ftp = new FTPClient();

    //CB consider replacing with logger
    // suppress login details
    ftp.addProtocolCommandListener(new FtpListener(logger));

    try {/*ww w  . j a va  2s. co m*/
        int reply;
        if (uri.getPort() > 0) {
            ftp.connect(uri.getHost(), uri.getPort());
        } else {
            ftp.connect(uri.getHost());
        }
        logger.info("Connected to " + uri.getHost() + " on port "
                + (uri.getPort() > 0 ? uri.getPort() : ftp.getDefaultPort()));

        // After connection attempt, you should check the reply code to verify
        // success.
        reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            throw new VoidValidatorException("Unable to connect to FTP server " + uri);
        }
        return ftp;
    } catch (IOException ex) {
        disconnect(ftp);
        throw new VoidValidatorException("Error to connect to FTP server " + uri, ex);
    }
}