org.apache.ftpserver
Class FtpConnection

java.lang.Object
  extended byorg.apache.ftpserver.BaseFtpConnection
      extended byorg.apache.ftpserver.FtpConnection
All Implemented Interfaces:
org.apache.avalon.cornerstone.services.connection.ConnectionHandler, StreamConnectorObserver

public class FtpConnection
extends BaseFtpConnection

This class handles each ftp connection. Here all the ftp command methods take two arguments - a ftp request and a writer object. This is the main backbone of the ftp server.
The ftp command method signature is: public void doXYZ(FtpRequest request, FtpWriter out) throws IOException.
Here XYZ is the capitalized ftp command.

Author:
Rana Bhattacharyya

Field Summary
 
Fields inherited from class org.apache.ftpserver.BaseFtpConnection
mbStopRequest, mConfig, mControlSocket, mDataConnection, METHOD_INPUT_SIG, mFtpStatus, mObserver, mSpy, mUser, mWriter
 
Constructor Summary
FtpConnection(FtpConfig cfg)
          Set configuration file and the control socket.
 
Method Summary
 void doABOR(FtpRequest request, FtpWriter out)
          ABOR <CRLF>
This command tells the server to abort the previous FTP service command and any associated transfer of data.
 void doAPPE(FtpRequest request, FtpWriter out)
          APPE <SP> <pathname> <CRLF>
This command causes the server-DTP to accept the data transferred via the data connection and to store the data in a file at the server site.
 void doCDUP(FtpRequest request, FtpWriter out)
          CDUP <CRLF>
This command is a special case of CWD, and is included to simplify the implementation of programs for transferring directory trees between operating systems having different syntaxes for naming the parent directory.
 void doCWD(FtpRequest request, FtpWriter out)
          CWD <SP> <pathname> <CRLF>
This command allows the user to work with a different directory for file storage or retrieval without altering his login or accounting information.
 void doDELE(FtpRequest request, FtpWriter out)
          DELE <SP> <pathname> <CRLF>
This command causes the file specified in the pathname to be deleted at the server site.
 void doHELP(FtpRequest request, FtpWriter out)
          HELP [<SP> ] <CRLF>
This command shall cause the server to send helpful information regarding its implementation status over the control connection to the user.
 void doLIST(FtpRequest request, FtpWriter out)
          LIST [<SP> <pathname>] <CRLF>
This command causes a list to be sent from the server to the passive DTP.
 void doMDTM(FtpRequest request, FtpWriter out)
          MDTM <SP> <pathname> <CRLF>
Returns the date and time of when a file was modified.
 void doMKD(FtpRequest request, FtpWriter out)
          MKD <SP> <pathname> <CRLF>
This command causes the directory specified in the pathname to be created as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).
 void doMODE(FtpRequest request, FtpWriter out)
          MODE <SP> <CRLF>
The argument is a single Telnet character code specifying the data transfer modes described in the Section on Transmission Modes.
 void doNLST(FtpRequest request, FtpWriter out)
          NLST [<SP> <pathname>] <CRLF>
This command causes a directory listing to be sent from server to user site.
 void doNOOP(FtpRequest request, FtpWriter out)
          NOOP <CRLF>
This command does not affect any parameters or previously entered commands.
 void doPASS(FtpRequest request, FtpWriter out)
          PASS <SP> <CRLF>
The argument field is a Telnet string specifying the user's password.
 void doPASV(FtpRequest request, FtpWriter out)
          PASV <CRLF>
This command requests the server-DTP to "listen" on a data port (which is not its default data port) and to wait for a connection rather than initiate one upon receipt of a transfer command.
 void doPORT(FtpRequest request, FtpWriter out)
          PORT <SP> <CRLF>
The argument is a HOST-PORT specification for the data port to be used in data connection.
 void doPWD(FtpRequest request, FtpWriter out)
          PWD <CRLF>
This command causes the name of the current working directory to be returned in the reply.
 void doQUIT(FtpRequest request, FtpWriter out)
          QUIT <CRLF>
This command terminates a USER and if file transfer is not in progress, the server closes the control connection.
 void doREST(FtpRequest request, FtpWriter out)
          REST <SP> <CRLF>
The argument field represents the server marker at which file transfer is to be restarted.
 void doRETR(FtpRequest request, FtpWriter out)
          RETR <SP> <pathname> <CRLF>
This command causes the server-DTP to transfer a copy of the file, specified in the pathname, to the server- or user-DTP at the other end of the data connection.
 void doRMD(FtpRequest request, FtpWriter out)
          RMD <SP> <pathname> <CRLF>
This command causes the directory specified in the pathname to be removed as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).
 void doRNFR(FtpRequest request, FtpWriter out)
          RNFR <SP> <pathname> <CRLF>
This command specifies the old pathname of the file which is to be renamed.
 void doRNTO(FtpRequest request, FtpWriter out)
          RNTO <SP> <pathname> <CRLF>
This command specifies the new pathname of the file specified in the immediately preceding "rename from" command.
 void doSITE(FtpRequest request, FtpWriter out)
          SITE <SP> <CRLF>
This command is used by the server to provide services specific to his system that are essential to file transfer but not sufficiently universal to be included as commands in the protocol.
 void doSIZE(FtpRequest request, FtpWriter out)
          SIZE <SP> <pathname> <CRLF>
Returns the size of the file in bytes.
 void doSTAT(FtpRequest request, FtpWriter out)
          STAT [<SP> <pathname>] <CRLF>
This command shall cause a status response to be sent over the control connection in the form of a reply.
 void doSTOR(FtpRequest request, FtpWriter out)
          STOR <SP> <pathname> <CRLF>
This command causes the server-DTP to accept the data transferred via the data connection and to store the data as a file at the server site.
 void doSTOU(FtpRequest request, FtpWriter out)
          STOU <CRLF>
This command behaves like STOR except that the resultant file is to be created in the current directory under a name unique to that directory.
 void doSTRU(FtpRequest request, FtpWriter out)
          STRU <SP> <structure-code> <CRLF>
The argument is a single Telnet character code specifying file structure.
 void doSYST(FtpRequest request, FtpWriter out)
          SYST <CRLF>
This command is used to find out the type of operating system at the server.
 void doTYPE(FtpRequest request, FtpWriter out)
          TYPE <SP> <type-code> <CRLF>
The argument specifies the representation type.
 void doUSER(FtpRequest request, FtpWriter out)
          USER <SP> <username> <CRLF>
The argument field is a Telnet string identifying the user.
protected  boolean hasPermission(FtpRequest request)
          Check the user permission to execute this command.
 
Methods inherited from class org.apache.ftpserver.BaseFtpConnection
dataTransferred, getConfig, getObserver, getSpyObject, getStatus, getUser, handleConnection, isClosed, notifyObserver, service, setObserver, setSpyObject, spyRequest, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FtpConnection

public FtpConnection(FtpConfig cfg)
Set configuration file and the control socket.

Method Detail

hasPermission

protected boolean hasPermission(FtpRequest request)
Check the user permission to execute this command.

Overrides:
hasPermission in class BaseFtpConnection

doABOR

public void doABOR(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
ABOR <CRLF>
This command tells the server to abort the previous FTP service command and any associated transfer of data. No action is to be taken if the previous command has been completed (including data transfer). The control connection is not to be closed by the server, but the data connection must be closed. Current implementation does not do anything. As here data transfers are not multi-threaded.

Throws:
java.io.IOException

doAPPE

public void doAPPE(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
APPE <SP> <pathname> <CRLF>
This command causes the server-DTP to accept the data transferred via the data connection and to store the data in a file at the server site. If the file specified in the pathname exists at the server site, then the data shall be appended to that file; otherwise the file specified in the pathname shall be created at the server site.

Throws:
java.io.IOException

doCDUP

public void doCDUP(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
CDUP <CRLF>
This command is a special case of CWD, and is included to simplify the implementation of programs for transferring directory trees between operating systems having different syntaxes for naming the parent directory. The reply codes shall be identical to the reply codes of CWD.

Throws:
java.io.IOException

doCWD

public void doCWD(FtpRequest request,
                  FtpWriter out)
           throws java.io.IOException
CWD <SP> <pathname> <CRLF>
This command allows the user to work with a different directory for file storage or retrieval without altering his login or accounting information. Transfer parameters are similarly unchanged. The argument is a pathname specifying a directory.

Throws:
java.io.IOException

doDELE

public void doDELE(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
DELE <SP> <pathname> <CRLF>
This command causes the file specified in the pathname to be deleted at the server site.

Throws:
java.io.IOException

doHELP

public void doHELP(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
HELP [<SP> ] <CRLF>
This command shall cause the server to send helpful information regarding its implementation status over the control connection to the user. The command may take an argument (e.g., any command name) and return more specific information as a response.

Throws:
java.io.IOException

doLIST

public void doLIST(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
LIST [<SP> <pathname>] <CRLF>
This command causes a list to be sent from the server to the passive DTP. If the pathname specifies a directory or other group of files, the server should transfer a list of files in the specified directory. If the pathname specifies a file then the server should send current information on the file. A null argument implies the user's current working or default directory. The data transfer is over the data connection

Throws:
java.io.IOException

doMDTM

public void doMDTM(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
MDTM <SP> <pathname> <CRLF>
Returns the date and time of when a file was modified.

Throws:
java.io.IOException

doMKD

public void doMKD(FtpRequest request,
                  FtpWriter out)
           throws java.io.IOException
MKD <SP> <pathname> <CRLF>
This command causes the directory specified in the pathname to be created as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).

Throws:
java.io.IOException

doMODE

public void doMODE(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
MODE <SP> <CRLF>
The argument is a single Telnet character code specifying the data transfer modes described in the Section on Transmission Modes.

Throws:
java.io.IOException

doNLST

public void doNLST(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
NLST [<SP> <pathname>] <CRLF>
This command causes a directory listing to be sent from server to user site. The pathname should specify a directory or other system-specific file group descriptor; a null argument implies the current directory. The server will return a stream of names of files and no other information.

Throws:
java.io.IOException

doNOOP

public void doNOOP(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
NOOP <CRLF>
This command does not affect any parameters or previously entered commands. It specifies no action other than that the server send an OK reply.

Throws:
java.io.IOException

doPASS

public void doPASS(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
PASS <SP> <CRLF>
The argument field is a Telnet string specifying the user's password. This command must be immediately preceded by the user name command.

Throws:
java.io.IOException

doPASV

public void doPASV(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
PASV <CRLF>
This command requests the server-DTP to "listen" on a data port (which is not its default data port) and to wait for a connection rather than initiate one upon receipt of a transfer command. The response to this command includes the host and port address this server is listening on.

Throws:
java.io.IOException

doPORT

public void doPORT(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
PORT <SP> <CRLF>
The argument is a HOST-PORT specification for the data port to be used in data connection. There are defaults for both the user and server data ports, and under normal circumstances this command and its reply are not needed. If this command is used, the argument is the concatenation of a 32-bit internet host address and a 16-bit TCP port address. This address information is broken into 8-bit fields and the value of each field is transmitted as a decimal number (in character string representation). The fields are separated by commas. A port command would be: PORT h1,h2,h3,h4,p1,p2 where h1 is the high order 8 bits of the internet host address.

Throws:
java.io.IOException

doPWD

public void doPWD(FtpRequest request,
                  FtpWriter out)
           throws java.io.IOException
PWD <CRLF>
This command causes the name of the current working directory to be returned in the reply.

Throws:
java.io.IOException

doQUIT

public void doQUIT(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
QUIT <CRLF>
This command terminates a USER and if file transfer is not in progress, the server closes the control connection.

Throws:
java.io.IOException

doREST

public void doREST(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
REST <SP> <CRLF>
The argument field represents the server marker at which file transfer is to be restarted. This command does not cause file transfer but skips over the file to the specified data checkpoint. This command shall be immediately followed by the appropriate FTP service command which shall cause file transfer to resume.

Throws:
java.io.IOException

doRETR

public void doRETR(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
RETR <SP> <pathname> <CRLF>
This command causes the server-DTP to transfer a copy of the file, specified in the pathname, to the server- or user-DTP at the other end of the data connection. The status and contents of the file at the server site shall be unaffected.

Throws:
java.io.IOException

doRMD

public void doRMD(FtpRequest request,
                  FtpWriter out)
           throws java.io.IOException
RMD <SP> <pathname> <CRLF>
This command causes the directory specified in the pathname to be removed as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).

Throws:
java.io.IOException

doRNFR

public void doRNFR(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
RNFR <SP> <pathname> <CRLF>
This command specifies the old pathname of the file which is to be renamed. This command must be immediately followed by a "rename to" command specifying the new file pathname.

Throws:
java.io.IOException

doRNTO

public void doRNTO(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
RNTO <SP> <pathname> <CRLF>
This command specifies the new pathname of the file specified in the immediately preceding "rename from" command. Together the two commands cause a file to be renamed.

Throws:
java.io.IOException

doSITE

public void doSITE(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
SITE <SP> <CRLF>
This command is used by the server to provide services specific to his system that are essential to file transfer but not sufficiently universal to be included as commands in the protocol.

Throws:
java.io.IOException

doSIZE

public void doSIZE(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
SIZE <SP> <pathname> <CRLF>
Returns the size of the file in bytes.

Throws:
java.io.IOException

doSTAT

public void doSTAT(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
STAT [<SP> <pathname>] <CRLF>
This command shall cause a status response to be sent over the control connection in the form of a reply.

Throws:
java.io.IOException

doSTOR

public void doSTOR(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
STOR <SP> <pathname> <CRLF>
This command causes the server-DTP to accept the data transferred via the data connection and to store the data as a file at the server site. If the file specified in the pathname exists at the server site, then its contents shall be replaced by the data being transferred. A new file is created at the server site if the file specified in the pathname does not already exist.

Throws:
java.io.IOException

doSTOU

public void doSTOU(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
STOU <CRLF>
This command behaves like STOR except that the resultant file is to be created in the current directory under a name unique to that directory. The 250 Transfer Started response must include the name generated.

Throws:
java.io.IOException

doSTRU

public void doSTRU(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
STRU <SP> <structure-code> <CRLF>
The argument is a single Telnet character code specifying file structure.

Throws:
java.io.IOException

doSYST

public void doSYST(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
SYST <CRLF>
This command is used to find out the type of operating system at the server.

Throws:
java.io.IOException

doTYPE

public void doTYPE(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
TYPE <SP> <type-code> <CRLF>
The argument specifies the representation type.

Throws:
java.io.IOException

doUSER

public void doUSER(FtpRequest request,
                   FtpWriter out)
            throws java.io.IOException
USER <SP> <username> <CRLF>
The argument field is a Telnet string identifying the user. The user identification is that which is required by the server for access to its file system. This command will normally be the first command transmitted by the user after the control connections are made.

Throws:
java.io.IOException


Copyright © -2005 . All Rights Reserved.