com.Prominic.jFTPd
Class PassiveConnection

java.lang.Object
  extended by java.lang.Thread
      extended by com.Prominic.jFTPd.PassiveConnection
All Implemented Interfaces:
java.lang.Runnable

public class PassiveConnection
extends java.lang.Thread

This thread takes care of opening a passive connection when the FTP client requests this using the PASV command. jFTPd needs to open a local socket which will be reported to the client, and the client needs to be informed about the new data socket as a response to the PASV command.
It knows to only open a socket using a predefined range of ports (for firewall friendly behaviour - when you can open tunnels from the firewall back to jFTPd on the specified range of ports).
By default, it waits for 60 seconds for the client to connect back, otherwise it will drop the socket and notify the client (timeouts always happen due to a misconfigured firewall - mostly on the server side )


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
(package private)  boolean DEBUG
           
(package private) static int highPort
           
(package private) static int lowPort
           
(package private) static int maxTries
           
(package private) static int nextPort
           
(package private)  int port
           
(package private) static boolean[] portsUsed
           
(package private)  java.net.Socket sock
           
(package private)  java.net.ServerSocket ss
           
(package private)  int stage
           
(package private) static int timeout
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
PassiveConnection()
          Creates a passive connection.
 
Method Summary
 int getPort()
          Gets the port chosen by the passive connection (to report it back to the user)
 java.net.Socket getSocket()
          Gets the socket opened by the passive connection (to use it to exchange data with the client).
 int getStage()
          Gets the stage of the passive connection.
static int getTimeout()
          Gets the timeout value.
 void run()
          Starts the passive connection which awaits a connection from the client for the specified timeout.
static void setPortRange(int low, int high)
          This sets the ports range from which the PassiveConnection can select ports.
static void setTimeout(int newTimeout)
          Sets new timeout value for which the PassiveConnection will wait for a connection from the client.
protected  void setupListener()
          This method will try to find an empty port (either guessing or picking one from the range of allowed ports).
 void terminate()
          Terminates the passive connection and closes the sockets.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

final boolean DEBUG
See Also:
Constant Field Values

sock

java.net.Socket sock

port

int port

ss

java.net.ServerSocket ss

stage

int stage

lowPort

static int lowPort

highPort

static int highPort

portsUsed

static boolean[] portsUsed

nextPort

static int nextPort

maxTries

static final int maxTries
See Also:
Constant Field Values

timeout

static int timeout
Constructor Detail

PassiveConnection

public PassiveConnection()
Creates a passive connection. Creation date: (10/17/2001 6:01:27 PM)

Method Detail

getPort

public int getPort()
Gets the port chosen by the passive connection (to report it back to the user)

Returns:
int chosen port.

getSocket

public java.net.Socket getSocket()
Gets the socket opened by the passive connection (to use it to exchange data with the client).

Returns:
Socket passive socket.

getStage

public int getStage()
Gets the stage of the passive connection. Stages are:
0 - not (or finished) running, not listening
1 - running, listening
2 - running, finished listening

Returns:
int stage.

getTimeout

public static int getTimeout()
Gets the timeout value.

Returns:
int the time out value.

run

public void run()
Starts the passive connection which awaits a connection from the client for the specified timeout. It closes the server socket it opens once a socket has been obtained from the client. Creation date: (10/17/2001 6:01:27 PM)

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setPortRange

public static void setPortRange(int low,
                                int high)
This sets the ports range from which the PassiveConnection can select ports. Usefull for firewalls when you need to create a bunch of tunnels from the firewall range of ports to jFTPd.
Assuming this only gets called once before any objects are constructed.

Parameters:
low - - low index
high - - high index.

setTimeout

public static void setTimeout(int newTimeout)
Sets new timeout value for which the PassiveConnection will wait for a connection from the client. Needed as due to firewalls, client cannot reach the server on the advertised address and port.


setupListener

protected void setupListener()
This method will try to find an empty port (either guessing or picking one from the range of allowed ports). Care must be used to make sure there are more ports available, in the range than connections available, otherwise this will loop through all the ports for maxtries value (10) before giving up.


terminate

public void terminate()
Terminates the passive connection and closes the sockets.