Example usage for org.apache.commons.net.ftp FTP BLOCK_TRANSFER_MODE

List of usage examples for org.apache.commons.net.ftp FTP BLOCK_TRANSFER_MODE

Introduction

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

Prototype

int BLOCK_TRANSFER_MODE

To view the source code for org.apache.commons.net.ftp FTP BLOCK_TRANSFER_MODE.

Click Source Link

Document

A constant used to indicate a file is to be transfered as a series of blocks.

Usage

From source file:org.apache.hadoop.fs.ftp.FTPFileSystem.java

/**
 * Connect to the FTP server using configuration parameters *
 * //www .  java  2s  .  c o m
 * @return An FTPClient instance
 * @throws IOException
 */
private FTPClient connect() throws IOException {
    FTPClient client = null;
    Configuration conf = getConf();
    String host = conf.get("fs.ftp.host");
    int port = conf.getInt("fs.ftp.host.port", FTP.DEFAULT_PORT);
    String user = conf.get("fs.ftp.user." + host);
    String password = conf.get("fs.ftp.password." + host);
    client = new FTPClient();
    client.connect(host, port);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        throw new IOException("Server - " + host + " refused connection on port - " + port);
    } else if (client.login(user, password)) {
        client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
        client.setFileType(FTP.BINARY_FILE_TYPE);
        client.setBufferSize(DEFAULT_BUFFER_SIZE);
    } else {
        throw new IOException("Login failed on server - " + host + ", port - " + port);
    }

    return client;
}