de.unkrig.commons.net.ftp
Class DataConnectionProxy

java.lang.Object
  extended by de.unkrig.commons.net.ftp.DataConnectionProxy

public class DataConnectionProxy
extends java.lang.Object

A proxy for the FTP data connection.


Constructor Summary
DataConnectionProxy()
           
 
Method Summary
static void setLocalPortRange(int first, int last)
          Defines the port that will be used for the server socket for all data connection proxies.
 java.net.InetSocketAddress start(java.net.InetAddress bindAddress, java.net.InetSocketAddress remoteAddress)
          Finds a free port on the given local interface and creates a server socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataConnectionProxy

public DataConnectionProxy()
Method Detail

setLocalPortRange

public static void setLocalPortRange(int first,
                                     int last)
Defines the port that will be used for the server socket for all data connection proxies.

If first and last are zero (which is the default), then an "ephemeral port" is picked for each data connection proxy (see InetSocketAddress.InetSocketAddress(int)).

Otherwise, if first and last are equal, then exactly that port is used for the server socket of each data connection proxy (this limits the number of data connections to one at any given time).

Otherwise, first is used for the server socket of the first data connection proxy, then first + 1 (or first - 1, if last < first), and so on up to and including last, then first again, and so on. If the port is already in use, then the next port is tried, until a "free" port is found, and a BindException is only thrown if all ports are already in use.

Must not be invoked after the first call to start(InetAddress, InetSocketAddress).


start

public java.net.InetSocketAddress start(java.net.InetAddress bindAddress,
                                        java.net.InetSocketAddress remoteAddress)
                                 throws java.io.IOException
Finds a free port on the given local interface and creates a server socket.

Parameters:
bindAddress - The local interface to bind this server to
remoteAddress - The remote address and port to connect to
Returns:
The actual address and port to which the data connection proxy was bound
Throws:
java.io.IOException
See Also:
setLocalPortRange(int, int)