com.Prominic.jFTPd
Class FTPConnection

java.lang.Object
  extended by java.util.Observable
      extended by com.Prominic.jFTPd.FTPConnection
All Implemented Interfaces:
Connection, java.lang.Runnable, java.util.Observer

public class FTPConnection
extends java.util.Observable
implements java.lang.Runnable, Connection, java.util.Observer

This class represents and FTP Connection created when an user connects to the FTP server. It embeds the command channel and takes care of the communication between the FTP client and the server. Each connection to the FTP server will have an FTPConnection attached, and this class implements all the methods to handle the commands supported by the FTP server.

Author:
VIulian

Nested Class Summary
(package private)  class FTPConnection.ConnectionState
          This class represents the current state of the connection - whether the control connection is secured or not - whether the data connection is secured or not It embeds the socket and also handles the communication with the server because it knows to use a SSL or a plain text socket.
 
Field Summary
(package private)  java.util.Vector activity
           
private  java.lang.String basePath
           
private  java.util.Hashtable basePaths
           
(package private)  boolean binaryMode
           
(package private)  boolean computeDates
           
(package private)  int connectionID
           
(package private)  java.lang.String CRLF
           
private  java.lang.String dataAddr
           
private  int dataPort
           
(package private)  boolean DEBUG
           
(package private)  java.lang.String defaultDateString
           
(package private)  java.util.Hashtable directoryOwners
           
private  java.util.Vector dirPath
           
private  boolean done
           
(package private)  int filesDownloaded
           
(package private)  char fileSeparator
           
(package private)  int filesUploaded
           
(package private) static int globalIDCounter
           
(package private)  java.lang.String goodbyeMessage
           
(package private)  java.lang.String group
           
private  java.net.InetAddress inetAddr
           
(package private)  boolean isBusy
           
(package private)  boolean isPassive
           
(package private)  boolean isWindows
           
(package private)  java.lang.String lastCommand
           
(package private)  java.util.Date lastCommandTime
           
private  FTPEvent lastEvent
           
(package private)  java.lang.String lineEnding
           
(package private)  int[] localAddrQuad
           
(package private) static java.lang.String loginFirstMessage
           
(package private)  java.util.Date logonDate
           
(package private)  java.lang.String mask
           
(package private)  java.lang.String owner
           
private  ConnectionHandler parent
           
(package private)  PassiveConnection passiveConn
           
(package private) static java.lang.String permissionDeniedMessage
           
(package private)  java.lang.String readAcc
           
(package private)  java.io.File renameTargetFile
           
(package private)  long restartPos
           
static java.lang.String root
           
private  java.lang.SecurityManager securityManager
           
private  FTPSecuritySource securitySource
           
private static long SIX_MONTHS
           
private  FTPConnection.ConnectionState state
           
(package private)  java.io.File tempDirectory
           
private  FTPUser theUser
           
(package private)  long timeCorrection
           
(package private)  long totalBytesDownloaded
           
(package private)  long totalBytesUploaded
           
(package private)  boolean useDirectoryCount
           
private  java.lang.String userName
           
(package private)  java.util.Hashtable userParams
           
(package private)  java.lang.String welcomeMessage
           
 
Constructor Summary
FTPConnection()
          Constructor for an FTP Conenction.
 
Method Summary
protected  void broadcastEvent(int action, java.lang.Object[] args)
          Sends out an FTPEvent to the listerners.
protected  boolean canOnlyWriteTo(java.util.Vector directoryPath)
          Returns true if the given directory can be written but not read.
protected  boolean canWriteTo(java.lang.String directoryPath)
          This method returns true if the the given directory can be written.
 void cleanup()
          Terminates the connection and closes all ongoing transfers.
protected static int createConnectionID()
          Creates an unique ID but for ease of implementation just uses a static which is globally defined , increments it and returns the value.
 boolean doAuthCommand(java.lang.String line)
          Handles the AUTH command.
 boolean doCccCommand(java.lang.String line)
          Handles the CCC command (Clear Command Channel)
 void doCommand(java.lang.String line)
          This method is the central part.
 boolean doCwdCommand(java.lang.String line)
          Handles the CWD (change working directory) command.
 boolean doDeleCommand(java.lang.String line)
          Handles the DELE (delete) command.
 boolean doFeatCommand(java.lang.String line)
          Handles the FEAT command.
 boolean doHelpCommand(java.lang.String line)
          This should actually give command-specific help, but is generic now.
 boolean doListCommand(java.lang.String line)
          Handles LIST or NLST commands, treats arguments (only -al).
 boolean doMdtmCommand(java.lang.String line)
          Handles Modification Time (MDTM) command.
 boolean doMkdCommand(java.lang.String line)
          Make directory (MKD).
 boolean doNoopCommand(java.lang.String line)
          Handle for the NOOP command.
protected  boolean doPassCommand(java.lang.String line)
          Handles the PASS command, which should be proceeded by a previous USER command.
 boolean doPasvCommand(java.lang.String line)
          Handles the PASV command.
 boolean doPbszCommand(java.lang.String line)
          Handles the PBSZ (Protect Buffer size) command.
 boolean doPortCommand(java.lang.String line)
          Handles the PORT command.
 boolean doProtCommand(java.lang.String line)
          Handles the PROT command.
 boolean doPwdCommand(java.lang.String line)
          Prints the current working directory.
 boolean doRestCommand(java.lang.String line)
          Processes the REST command.
 boolean doRetrCommand(java.lang.String line)
          Processes the RETR command.
 boolean doRmdCommand(java.lang.String line)
          Processes the RMD (remove directory) command.
 boolean doRnfrCommand(java.lang.String line)
          Processes the RNFR (Rename From) command.
 boolean doRntoCommand(java.lang.String line)
          Processes the RNTO (Rename To) command.
 boolean doSizeCommand(java.lang.String line)
          Processes the SIZE (Rename To) command.
 boolean doStatCommand(java.lang.String line)
          Processes the RNFR (Rename From) command.
 boolean doStorCommand(java.lang.String line, boolean append)
          Processes the STOR (store file) command.
 boolean doSystCommand(java.lang.String line)
          Processes the SYST (System Informations) command.
 boolean doTypeCommand(java.lang.String line)
          Processes the TYPE command.
protected  boolean doUserCommand(java.lang.String line)
          Processes the USER command.
static void execCommand(java.lang.String[] commandToBeRunned)
          Executes a command using Java Runtime interface.
 java.util.Vector getActivity()
          Returns the activity vector ( FTP commands handled in the current connection).
 int getConnectionID()
          Returns the connection id.
 int getDownloadCount()
          Returns number of files downloaded this session.
 long getDownloadedBytes()
          Returns number of bytes downloaded this session.
protected  java.lang.String getGroup(java.lang.String virtualPath)
          Returns the group to which the given virtualPath must be chown-ed.
 java.net.InetAddress getInetAddress()
          Gets the current InetAddress of this connection.
 java.util.Date getLastCommandTime()
          Gets the time when last command from the client was received.
 FTPEvent getLastEvent()
          Returns the last FTP event that occured for this connection.
 java.util.Date getLogonDate()
          Returns the time when the user connected.
protected  java.lang.String getMask(java.lang.String virtualPath)
          Returns the mask to which the given virtualPath must be chmod-ed.
protected  java.lang.String getOwner(java.lang.String virtualPath)
          Returns the owner to which the given virtualPath must be chown-ed.
protected  java.lang.String getReadAccess(java.lang.String virtualPath)
          Returns the read/write access to which the given virtualPath must be checked.
 java.net.Socket getSocket()
          Returns the current socket.
 int getUploadCount()
          Gets total number of files uploaded via this connection.
 long getUploadedBytes()
          Gets total number of bytes uploaded via this connection.
 FTPUser getUser()
          Gets the current user using this connection.
 boolean inHomeDirectory(java.lang.String path)
          Checks is a virtual path is inside the home directory of the user.
 void initState(java.net.Socket s)
          Initialises the internal state which tracks the [plain text] vs SSL connection.
 boolean isBusy()
          Checks if this connection is busy (data transfers in progress).
protected  java.lang.String makeAbsolutePath(java.lang.String str)
          Converts a relative path into the absolute path (this is used to check if the path the user attempts to use is under his/her home directory)
 java.util.Vector makeDirPathVector(java.lang.String str)
          Splits a path into its directory components.
protected  java.lang.String makeFilePath(java.util.Vector dirs)
          Composes a path given a Vector where each element represents a directory on the path.
protected  java.util.Vector makeSubDirsVector(java.lang.Object[] array)
          Array to Vector - basically an array of directories forming a path is transformed into a Vector.
protected  java.lang.String[] parseDir(java.lang.String dir)
          Splits a path into its directory components.
protected  void printDenied()
          Sends a default user login failed back to the client.
protected  void printNoHomeDirectory()
          Sends a default home directory not found back to the client.
protected  void printWelcome()
          Prints the default welcome message to the client (after he logged in).
 void recordDownload(long bytes)
          Increments the number of files downloaded by one and also increases the number of bytes transfered with the given amount.
 void recordUpload(long bytes)
          Increments the number of files uploaaded by one and also increases the number of bytes transfered with the given amount.
 void run()
          Runs the connection's thread.
 void setBasePaths(java.util.Hashtable virtualDirs)
          Sets the home directories for the user using this connection.
 void setBusy(boolean q)
          Sets the busy flag - when handling a command for example, it will be set to true.
 void setLastCommandTime(java.util.Date d)
          Sets the last date of the command (helpfull when checking for idle connections).
 void setParent(ConnectionHandler mom)
          Sets the connection handler - the parent - of this connection.
 void setSecuritySource(FTPSecuritySource source)
          Sets the security source of the connection.
 void setUserParams(java.util.Hashtable params)
          Sets parameters for this connection, based on the configuration read from the configuration file.
 void terminate()
          Terminates a connection by sending a 500 message to the client.
 void update(java.util.Observable o, java.lang.Object arg)
          Updates the logs with the given FTPEvent.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

final boolean DEBUG
See Also:
Constant Field Values

state

private FTPConnection.ConnectionState state

inetAddr

private java.net.InetAddress inetAddr

securityManager

private java.lang.SecurityManager securityManager

lastEvent

private FTPEvent lastEvent

parent

private ConnectionHandler parent

securitySource

private FTPSecuritySource securitySource

done

private boolean done

userName

private java.lang.String userName

theUser

private FTPUser theUser

dirPath

private java.util.Vector dirPath

basePath

private java.lang.String basePath

basePaths

private java.util.Hashtable basePaths

dataAddr

private java.lang.String dataAddr

dataPort

private int dataPort

loginFirstMessage

static java.lang.String loginFirstMessage

permissionDeniedMessage

static java.lang.String permissionDeniedMessage

lineEnding

java.lang.String lineEnding

lastCommand

java.lang.String lastCommand

lastCommandTime

java.util.Date lastCommandTime

isBusy

boolean isBusy

renameTargetFile

java.io.File renameTargetFile

restartPos

long restartPos

binaryMode

boolean binaryMode

passiveConn

PassiveConnection passiveConn

isPassive

boolean isPassive

localAddrQuad

int[] localAddrQuad

userParams

java.util.Hashtable userParams

timeCorrection

long timeCorrection

computeDates

boolean computeDates

useDirectoryCount

boolean useDirectoryCount

defaultDateString

java.lang.String defaultDateString

welcomeMessage

java.lang.String welcomeMessage

goodbyeMessage

java.lang.String goodbyeMessage

tempDirectory

java.io.File tempDirectory

logonDate

java.util.Date logonDate

filesUploaded

int filesUploaded

isWindows

boolean isWindows

filesDownloaded

int filesDownloaded

totalBytesUploaded

long totalBytesUploaded

totalBytesDownloaded

long totalBytesDownloaded

activity

java.util.Vector activity

globalIDCounter

static int globalIDCounter

connectionID

int connectionID

SIX_MONTHS

private static long SIX_MONTHS

fileSeparator

char fileSeparator

root

public static java.lang.String root

CRLF

java.lang.String CRLF

directoryOwners

java.util.Hashtable directoryOwners

group

java.lang.String group

owner

java.lang.String owner

mask

java.lang.String mask

readAcc

java.lang.String readAcc
Constructor Detail

FTPConnection

public FTPConnection()
Constructor for an FTP Conenction. This also adds the current FTP Connection list handler..

Method Detail

broadcastEvent

protected void broadcastEvent(int action,
                              java.lang.Object[] args)
Sends out an FTPEvent to the listerners.

Parameters:
action - - the action code.
args - - arguments of the event (such as mesasges).
See Also:
FTPEvent

canOnlyWriteTo

protected boolean canOnlyWriteTo(java.util.Vector directoryPath)
Returns true if the given directory can be written but not read.

Parameters:
directoryPath - - directory path
Returns:
- true if the directory can be written but not read.

canWriteTo

protected boolean canWriteTo(java.lang.String directoryPath)
This method returns true if the the given directory can be written. Not phisically, but if the rights are ok. Creation date: (23-Apr-02 18:06:37)

Parameters:
directoryPath - - the directory to be checked.
Returns:
- true if the directory can be written.

cleanup

public void cleanup()
Terminates the connection and closes all ongoing transfers. Also sends an event to the parent (the server) that the connection is stopped (so further connections can be accepted - if a limit is imposed for example) by the parent (the server itself).


createConnectionID

protected static int createConnectionID()
Creates an unique ID but for ease of implementation just uses a static which is globally defined , increments it and returns the value.

Returns:
- an unique ID for the connection.

doCommand

public void doCommand(java.lang.String line)
This method is the central part. Handles all possible commands which are sent via an FTP connection. It does security checking, opens up passive mode connections, etc. The implemented commands are the minimum set required by the RFC and then improved to handle various other programs such as Macromedia (which needed MDTM command) or SSL needed for strong security while the authentication is done. This method calls one of the doXXXXXCommand for each command supported by the FTP server. If a command is not understood, a 221 reply is sent back to the client.

Parameters:
line - - the command sent by the client on the control channel.

doFeatCommand

public boolean doFeatCommand(java.lang.String line)
Handles the FEAT command. So far it avertises the AUTH commands.

Parameters:
line - - command from the client
Returns:
- always returns true (FEAT command is handled).

doCccCommand

public boolean doCccCommand(java.lang.String line)
Handles the CCC command (Clear Command Channel)

Parameters:
line - - command from the client.
Returns:
- always true if line is "CCC", false otherwise.

doProtCommand

public boolean doProtCommand(java.lang.String line)
Handles the PROT command. PROT command needs to have PBSZ before it; this method checks for that too.

Parameters:
line - - command from the client.
Returns:
- false when command is not understood (such as not a PROT P or PROT C); true otherwise.

doPbszCommand

public boolean doPbszCommand(java.lang.String line)
Handles the PBSZ (Protect Buffer size) command. Makes sure that the command channel is secure, before accepting to execute the command. The command needs an argument, in TSL case that must be 0.

Parameters:
line - - command from the client.
Returns:
- true if the command channel was secured before this method.

doAuthCommand

public boolean doAuthCommand(java.lang.String line)
Handles the AUTH command. It upgrades the clear channel to SSL channel.

Parameters:
line - - command from the client.
Returns:
false if there's no parameter specified (needs to be TSL or SSL).

doCwdCommand

public boolean doCwdCommand(java.lang.String line)
Handles the CWD (change working directory) command. It does all the necessary checking regarding the rights the user has. Also there's the Security Manager in place which makes sure the user never gets out of its designated home directories. Checks are done for read access too, if a user is not allowed in a directory found in his home directory, then access is forbidden.

Parameters:
line - - command from the client.
Returns:
- false when command was not understood or did not have the directory parameter; true otherwise.

doDeleCommand

public boolean doDeleCommand(java.lang.String line)
Handles the DELE (delete) command. It does all the necessary checking regarding the rights the user has. Also there's the Security Manager in place which makes sure the user never deletes what he is not allowed to. Checks are done for read access too, if a user is not allowed in a directory found in his home directory, then access is forbidden.

Parameters:
line - - command from the client.
Returns:
- false when command was not understood or did not have the path parameter; true otherwise.

doHelpCommand

public boolean doHelpCommand(java.lang.String line)
This should actually give command-specific help, but is generic now.

Parameters:
line - - command from client.
Returns:
always true.

doListCommand

public boolean doListCommand(java.lang.String line)
Handles LIST or NLST commands, treats arguments (only -al). LIST will return the short list of the current working directory. LIST -al will return the equivalent of a 'dir' command.

Parameters:
line - - command from client
Returns:
- false if command was not understood; true otherwise (even if errors appear, if command was understood, then return is false).

doMdtmCommand

public boolean doMdtmCommand(java.lang.String line)
Handles Modification Time (MDTM) command. This can only read the timestamp of the given file - it cannot update that. There are no checks to see if the user has read access to the given file - but the security manager will forbid the users to access something outside their directories.

Parameters:
line - - command line from client
Returns:
- false if command was not understood (the file was not specified). True otherwise

doMkdCommand

public boolean doMkdCommand(java.lang.String line)
Make directory (MKD). Standard checks for access / nonexistence / etc. Also changes directory rights based on the

Parameters:
line - - command from client.
Returns:
false if command was not understood (file argument missing). True otherwise.

doNoopCommand

public boolean doNoopCommand(java.lang.String line)
Handle for the NOOP command. This is used to keep connection active as jFTPd has a timeout which, if it passes without a client to send a command it will drop the connection.

Parameters:
line - - command from client
Returns:
always true.

doPassCommand

protected boolean doPassCommand(java.lang.String line)
Handles the PASS command, which should be proceeded by a previous USER command. If one of the home directories is missing, an error is sent back to the client - and login is denied. The PASS command send expects the password to be unecrypted, so to protect the communication a SSL Explicit session must be established ahead of exchanging the username and password.


doPasvCommand

public boolean doPasvCommand(java.lang.String line)
Handles the PASV command. Output with the IP and Port where the server is listening for the data connection is sent back to the client. The IP used is the local one, however jFTPd can advertise another IP (for example when it has a firewall in front of it) and that is specified in the configuration file using the ipaddress= entry.

Parameters:
line - - command from client.
Returns:
always returns true.

doPortCommand

public boolean doPortCommand(java.lang.String line)
Handles the PORT command.

Parameters:
line - - command from client containing the address and port where jFTPd will connect.
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doPwdCommand

public boolean doPwdCommand(java.lang.String line)
Prints the current working directory. Output is sent (as RFC asks) via the control connection.

Parameters:
line - - command from client.
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doRestCommand

public boolean doRestCommand(java.lang.String line)
Processes the REST command. Must be followed by a RETR or STOR command.

Parameters:
line - - command from client.
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doRetrCommand

public boolean doRetrCommand(java.lang.String line)
Processes the RETR command. If a REST command was issued previously, then the file will be retrieved starting from the specified offset.

Parameters:
line - - command from client.
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doRmdCommand

public boolean doRmdCommand(java.lang.String line)
Processes the RMD (remove directory) command. The directory must exist, be in the users's home dir and the user must have write access on it.

Parameters:
line - - command from client.
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doRnfrCommand

public boolean doRnfrCommand(java.lang.String line)
Processes the RNFR (Rename From) command. Must be followed by a RNTO command. Access to the file is checked.

Parameters:
line - - command from client
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doRntoCommand

public boolean doRntoCommand(java.lang.String line)
Processes the RNTO (Rename To) command. A RNFR must have been issued so far... The destination path must be in the user's home directory.

Parameters:
line - - command from client
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doSizeCommand

public boolean doSizeCommand(java.lang.String line)
Processes the SIZE (Rename To) command.

Parameters:
line - - command from client containing the address and port where jFTPd will connect.
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doStatCommand

public boolean doStatCommand(java.lang.String line)
Processes the RNFR (Rename From) command. Must be followed by a RNTO command. Access to the file is checked.

Parameters:
line - - command from client
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doStorCommand

public boolean doStorCommand(java.lang.String line,
                             boolean append)
Processes the STOR (store file) command. All security and access checks are done, and at the end the file is changed mod to proper rights and mode.

Parameters:
line - - command from client
Returns:
false - if command was not understood (not formatted correctly); true otherwise.

doSystCommand

public boolean doSystCommand(java.lang.String line)
Processes the SYST (System Informations) command.

Parameters:
line - - command from client
Returns:
always returns true

doTypeCommand

public boolean doTypeCommand(java.lang.String line)
Processes the TYPE command. Changes the type of future transfers to ASCII and BINARY.

Parameters:
line - - command from client
Returns:
true if the argument of TYPE is A (Ascii) or I (binary). False otherwise.

doUserCommand

protected boolean doUserCommand(java.lang.String line)
Processes the USER command.

Parameters:
line - - command from client
Returns:
true if the argument of TYPE is A (Ascii) or I (binary). False otherwise.

execCommand

public static void execCommand(java.lang.String[] commandToBeRunned)
Executes a command using Java Runtime interface. It does not run on Windows.

Parameters:
commandToBeRunned - - array of strings containing the command and its arguments.

getActivity

public java.util.Vector getActivity()
Returns the activity vector ( FTP commands handled in the current connection).

Returns:
the activity vector ( FTP commands handled in the current connection).

getConnectionID

public int getConnectionID()
Returns the connection id.

Returns:
the connection.

getDownloadCount

public int getDownloadCount()
Returns number of files downloaded this session.

Returns:
- the number of files downloaded this session.

getDownloadedBytes

public long getDownloadedBytes()
Returns number of bytes downloaded this session.

Returns:
- the number of bytes downloaded this session.

getGroup

protected java.lang.String getGroup(java.lang.String virtualPath)
Returns the group to which the given virtualPath must be chown-ed.

Parameters:
virtualPath - - virtual path to be checked
Returns:
- group name or null if virtualPath is null or in case of other errors.

getInetAddress

public java.net.InetAddress getInetAddress()
Gets the current InetAddress of this connection.

Specified by:
getInetAddress in interface Connection
Returns:
Inet Address where the connection is bound.

getLastCommandTime

public java.util.Date getLastCommandTime()
Gets the time when last command from the client was received.

Specified by:
getLastCommandTime in interface Connection
Returns:
Date - time of the last command.

getLastEvent

public FTPEvent getLastEvent()
Returns the last FTP event that occured for this connection.

Returns:
- last event.s

getLogonDate

public java.util.Date getLogonDate()
Returns the time when the user connected.

Returns:
the time when user conencted.

getMask

protected java.lang.String getMask(java.lang.String virtualPath)
Returns the mask to which the given virtualPath must be chmod-ed.

Parameters:
virtualPath - - virtual path to be checked
Returns:
- mask or null if virtualPath is null or in case of other errors.

getOwner

protected java.lang.String getOwner(java.lang.String virtualPath)
Returns the owner to which the given virtualPath must be chown-ed.

Parameters:
virtualPath - - virtual path to be checked
Returns:
- owner or null if virtualPath is null or in case of other errors.

getReadAccess

protected java.lang.String getReadAccess(java.lang.String virtualPath)
Returns the read/write access to which the given virtualPath must be checked.

Parameters:
virtualPath - - virtual path to be checked
Returns:
- read/write or null if virtualPath is null or in case of other errors.

getSocket

public java.net.Socket getSocket()
Returns the current socket.

Specified by:
getSocket in interface Connection
Returns:
Socket - the current socket of the control channel for the current connection.

getUploadCount

public int getUploadCount()
Gets total number of files uploaded via this connection.

Returns:
total number of files uploaded via this connection.

getUploadedBytes

public long getUploadedBytes()
Gets total number of bytes uploaded via this connection.

Returns:
total number of bytes uploaded via this connection.

getUser

public FTPUser getUser()
Gets the current user using this connection.

Returns:
current FTPUser or null if anonymous.

inHomeDirectory

public boolean inHomeDirectory(java.lang.String path)
Checks is a virtual path is inside the home directory of the user. This method is havily used internally to make sure the user does not get outside its designated dirs.

Parameters:
path - - virtual directory path
Returns:
true - if the virtual path is mapped to a directory inside the user home dir, false otherwise.

isBusy

public boolean isBusy()
Checks if this connection is busy (data transfers in progress). Used so the connection won't be closed if there is data still being sent/received by the client.

Specified by:
isBusy in interface Connection
Returns:
true if there are data transfers in progress, false otherwise.

makeAbsolutePath

protected java.lang.String makeAbsolutePath(java.lang.String str)
Converts a relative path into the absolute path (this is used to check if the path the user attempts to use is under his/her home directory)

Parameters:
str - - relative path
Returns:
- absolute path.

makeDirPathVector

public java.util.Vector makeDirPathVector(java.lang.String str)
Splits a path into its directory components.

Parameters:
str - - path
Returns:
- vector where each element is a directory in the path.

makeFilePath

protected java.lang.String makeFilePath(java.util.Vector dirs)
Composes a path given a Vector where each element represents a directory on the path.

Parameters:
dirs - - vector containg the directories on the path.
Returns:
- file path with vector.elemetAt(0)/vector.elementAt(1)/...

makeSubDirsVector

protected java.util.Vector makeSubDirsVector(java.lang.Object[] array)
Array to Vector - basically an array of directories forming a path is transformed into a Vector.

Parameters:
array - - array of String elements.
Returns:
- Vector with each element containing the respective array element.

parseDir

protected java.lang.String[] parseDir(java.lang.String dir)
Splits a path into its directory components.

Parameters:
dir - - path
Returns:
- array where each element is a directory in the path.

printDenied

protected void printDenied()
Sends a default user login failed back to the client.


printNoHomeDirectory

protected void printNoHomeDirectory()
Sends a default home directory not found back to the client.


printWelcome

protected void printWelcome()
Prints the default welcome message to the client (after he logged in).


recordDownload

public void recordDownload(long bytes)
Increments the number of files downloaded by one and also increases the number of bytes transfered with the given amount.

Parameters:
bytes - - number of bytes the client downloaded.

recordUpload

public void recordUpload(long bytes)
Increments the number of files uploaaded by one and also increases the number of bytes transfered with the given amount.

Parameters:
bytes - - number of bytes the client downloaded.

run

public void run()
Runs the connection's thread. It sends the welcome message back to the client and then processes each line it receives vi the command channel, using the doCommand() method. When the connection ends, it calls cleanup() so it would free the resources attached to the connection.

Specified by:
run in interface java.lang.Runnable

setBasePaths

public void setBasePaths(java.util.Hashtable virtualDirs)
Sets the home directories for the user using this connection. These will be checked for access - the user is only allowed to stay in these directories.


setBusy

public void setBusy(boolean q)
Sets the busy flag - when handling a command for example, it will be set to true.

Parameters:
q - - new busy flag value

setLastCommandTime

public void setLastCommandTime(java.util.Date d)
Sets the last date of the command (helpfull when checking for idle connections).

Parameters:
d - - date of last command sent by the client.

setParent

public void setParent(ConnectionHandler mom)
Sets the connection handler - the parent - of this connection.

Parameters:
mom - - the parent of the connection

setSecuritySource

public void setSecuritySource(FTPSecuritySource source)
Sets the security source of the connection. This security source will tell if a user has read/write access.

Parameters:
source - - FTP security source.

initState

public void initState(java.net.Socket s)
               throws java.io.IOException
Initialises the internal state which tracks the [plain text] vs SSL connection. This state contains the sockets (either plain text or encrypted) on which the dialog between jFTPd and the server takes place. The connection swiches between the two implementations based on commands received from the ftp client.

Parameters:
s - - initial plain text socket, after the client connects to port 21.
Throws:
java.io.IOException

setUserParams

public void setUserParams(java.util.Hashtable params)
Sets parameters for this connection, based on the configuration read from the configuration file. These settings are the timecorrection, computedates, directorycount, welcomemessage, goodbyemessage, tempdirectory and ipaddress.

Parameters:
params - - hashtable with the key=value pairs holding the values for the properties. It can hold only a subset of the properties.

terminate

public void terminate()
Terminates a connection by sending a 500 message to the client. Sockets are closed and cleanup() is called.

Specified by:
terminate in interface Connection

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Updates the logs with the given FTPEvent.

Specified by:
update in interface java.util.Observer
Parameters:
o - - Observable (entity which logs the event)
arg - - FTPEvent which needs to be logged.