|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Observable com.Prominic.jFTPd.FTPConnection
public class FTPConnection
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.
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 |
---|
final boolean DEBUG
private FTPConnection.ConnectionState state
private java.net.InetAddress inetAddr
private java.lang.SecurityManager securityManager
private FTPEvent lastEvent
private ConnectionHandler parent
private FTPSecuritySource securitySource
private boolean done
private java.lang.String userName
private FTPUser theUser
private java.util.Vector dirPath
private java.lang.String basePath
private java.util.Hashtable basePaths
private java.lang.String dataAddr
private int dataPort
static java.lang.String loginFirstMessage
static java.lang.String permissionDeniedMessage
java.lang.String lineEnding
java.lang.String lastCommand
java.util.Date lastCommandTime
boolean isBusy
java.io.File renameTargetFile
long restartPos
boolean binaryMode
PassiveConnection passiveConn
boolean isPassive
int[] localAddrQuad
java.util.Hashtable userParams
long timeCorrection
boolean computeDates
boolean useDirectoryCount
java.lang.String defaultDateString
java.lang.String welcomeMessage
java.lang.String goodbyeMessage
java.io.File tempDirectory
java.util.Date logonDate
int filesUploaded
boolean isWindows
int filesDownloaded
long totalBytesUploaded
long totalBytesDownloaded
java.util.Vector activity
static int globalIDCounter
int connectionID
private static long SIX_MONTHS
char fileSeparator
public static java.lang.String root
java.lang.String CRLF
java.util.Hashtable directoryOwners
java.lang.String group
java.lang.String owner
java.lang.String mask
java.lang.String readAcc
Constructor Detail |
---|
public FTPConnection()
Method Detail |
---|
protected void broadcastEvent(int action, java.lang.Object[] args)
action
- - the action code.args
- - arguments of the event (such as mesasges).FTPEvent
protected boolean canOnlyWriteTo(java.util.Vector directoryPath)
directoryPath
- - directory path
protected boolean canWriteTo(java.lang.String directoryPath)
directoryPath
- - the directory to be checked.
public void cleanup()
protected static int createConnectionID()
public void doCommand(java.lang.String line)
line
- - the command sent by the client on the control channel.public boolean doFeatCommand(java.lang.String line)
line
- - command from the client
public boolean doCccCommand(java.lang.String line)
line
- - command from the client.
public boolean doProtCommand(java.lang.String line)
line
- - command from the client.
public boolean doPbszCommand(java.lang.String line)
line
- - command from the client.
public boolean doAuthCommand(java.lang.String line)
line
- - command from the client.
public boolean doCwdCommand(java.lang.String line)
line
- - command from the client.
public boolean doDeleCommand(java.lang.String line)
line
- - command from the client.
public boolean doHelpCommand(java.lang.String line)
line
- - command from client.
public boolean doListCommand(java.lang.String line)
line
- - command from client
public boolean doMdtmCommand(java.lang.String line)
line
- - command line from client
public boolean doMkdCommand(java.lang.String line)
line
- - command from client.
public boolean doNoopCommand(java.lang.String line)
line
- - command from client
protected boolean doPassCommand(java.lang.String line)
public boolean doPasvCommand(java.lang.String line)
line
- - command from client.
public boolean doPortCommand(java.lang.String line)
line
- - command from client containing the address and port where jFTPd will connect.
public boolean doPwdCommand(java.lang.String line)
line
- - command from client.
public boolean doRestCommand(java.lang.String line)
line
- - command from client.
public boolean doRetrCommand(java.lang.String line)
line
- - command from client.
public boolean doRmdCommand(java.lang.String line)
line
- - command from client.
public boolean doRnfrCommand(java.lang.String line)
line
- - command from client
public boolean doRntoCommand(java.lang.String line)
line
- - command from client
public boolean doSizeCommand(java.lang.String line)
line
- - command from client containing the address and port where jFTPd will connect.
public boolean doStatCommand(java.lang.String line)
line
- - command from client
public boolean doStorCommand(java.lang.String line, boolean append)
line
- - command from client
public boolean doSystCommand(java.lang.String line)
line
- - command from client
public boolean doTypeCommand(java.lang.String line)
line
- - command from client
protected boolean doUserCommand(java.lang.String line)
line
- - command from client
public static void execCommand(java.lang.String[] commandToBeRunned)
commandToBeRunned
- - array of strings containing the command and its arguments.public java.util.Vector getActivity()
public int getConnectionID()
public int getDownloadCount()
public long getDownloadedBytes()
protected java.lang.String getGroup(java.lang.String virtualPath)
virtualPath
- - virtual path to be checked
public java.net.InetAddress getInetAddress()
getInetAddress
in interface Connection
public java.util.Date getLastCommandTime()
getLastCommandTime
in interface Connection
public FTPEvent getLastEvent()
public java.util.Date getLogonDate()
protected java.lang.String getMask(java.lang.String virtualPath)
virtualPath
- - virtual path to be checked
protected java.lang.String getOwner(java.lang.String virtualPath)
virtualPath
- - virtual path to be checked
protected java.lang.String getReadAccess(java.lang.String virtualPath)
virtualPath
- - virtual path to be checked
public java.net.Socket getSocket()
getSocket
in interface Connection
public int getUploadCount()
public long getUploadedBytes()
public FTPUser getUser()
public boolean inHomeDirectory(java.lang.String path)
path
- - virtual directory path
public boolean isBusy()
isBusy
in interface Connection
protected java.lang.String makeAbsolutePath(java.lang.String str)
str
- - relative path
public java.util.Vector makeDirPathVector(java.lang.String str)
str
- - path
protected java.lang.String makeFilePath(java.util.Vector dirs)
dirs
- - vector containg the directories on the path.
protected java.util.Vector makeSubDirsVector(java.lang.Object[] array)
array
- - array of String elements.
protected java.lang.String[] parseDir(java.lang.String dir)
dir
- - path
protected void printDenied()
protected void printNoHomeDirectory()
protected void printWelcome()
public void recordDownload(long bytes)
bytes
- - number of bytes the client downloaded.public void recordUpload(long bytes)
bytes
- - number of bytes the client downloaded.public void run()
run
in interface java.lang.Runnable
public void setBasePaths(java.util.Hashtable virtualDirs)
public void setBusy(boolean q)
q
- - new busy flag valuepublic void setLastCommandTime(java.util.Date d)
d
- - date of last command sent by the client.public void setParent(ConnectionHandler mom)
mom
- - the parent of the connectionpublic void setSecuritySource(FTPSecuritySource source)
source
- - FTP security source.public void initState(java.net.Socket s) throws java.io.IOException
s
- - initial plain text socket, after the client connects to port 21.
java.io.IOException
public void setUserParams(java.util.Hashtable params)
params
- - hashtable with the key=value pairs holding the values for the properties. It can hold only a subset of the properties.public void terminate()
terminate
in interface Connection
public void update(java.util.Observable o, java.lang.Object arg)
update
in interface java.util.Observer
o
- - Observable (entity which logs the event)arg
- - FTPEvent which needs to be logged.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |