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

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

Introduction

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

Prototype

FTPCmd PORT

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

Click Source Link

Usage

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

/***
 * A convenience method to send the FTP PORT command to the server,
 * receive the reply, and return the reply code.
 * <p>/*w  w  w.  ja  v  a  2  s . c  o m*/
 * @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.
 ***/
public int port(InetAddress host, int port) throws IOException {
    int num;
    StringBuilder info = new StringBuilder(24);

    info.append(host.getHostAddress().replace('.', ','));
    num = port >>> 8;
    info.append(',');
    info.append(num);
    info.append(',');
    num = port & 0xff;
    info.append(num);

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