Example usage for org.apache.commons.net.ftp FTPCmd EPRT

List of usage examples for org.apache.commons.net.ftp FTPCmd EPRT

Introduction

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

Prototype

FTPCmd EPRT

To view the source code for org.apache.commons.net.ftp FTPCmd EPRT.

Click Source Link

Usage

From source file:com.atomicleopard.thundr.ftp.commons.FTP.java

/***
 * A convenience method to send the FTP EPRT command to the server,
 * receive the reply, and return the reply code.
 *
 * Examples://from www. j a  va  2 s  .c  o  m
 * <code>
 * <ul>
 * <li>EPRT |1|132.235.1.2|6275|</li>
 * <li>EPRT |2|1080::8:800:200C:417A|5282|</li>
 * </ul>
 * </code>
 * <p>
 * @see "http://www.faqs.org/rfcs/rfc2428.html"
 *
 * @param host  The host owning the port.
 * @param port  The new port.
 * @return The reply code received from the server.
 * @exception FTPConnectionClosedException
 *      If the FTP server prematurely closes the connection as a result
 *      of the client being idle or some other reason causing the server
 *      to send FTP reply code 421.  This exception may be caught either
 *      as an IOException or independently as itself.
 * @exception IOException  If an I/O error occurs while either sending the
 *      command or receiving the server reply.
 * @since 2.2
 ***/
public int eprt(InetAddress host, int port) throws IOException {
    int num;
    StringBuilder info = new StringBuilder();
    String h;

    // If IPv6, trim the zone index
    h = host.getHostAddress();
    num = h.indexOf("%");
    if (num > 0) {
        h = h.substring(0, num);
    }

    info.append("|");

    if (host instanceof Inet4Address) {
        info.append("1");
    } else if (host instanceof Inet6Address) {
        info.append("2");
    }
    info.append("|");
    info.append(h);
    info.append("|");
    info.append(port);
    info.append("|");

    return sendCommand(FTPCmd.EPRT, info.toString());
}