avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver FtpConnection.java
Date Sun, 31 Mar 2002 16:40:47 GMT
rana_b      02/03/31 08:40:47

  Modified:    ftpserver/src/java/org/apache/avalon/ftpserver
                        FtpConnection.java
  Log:
  Moving towards ftplet
  
  Revision  Changes    Path
  1.10      +229 -456  jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpConnection.java
  
  Index: FtpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpConnection.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FtpConnection.java	10 Mar 2002 06:08:21 -0000	1.9
  +++ FtpConnection.java	31 Mar 2002 16:40:47 -0000	1.10
  @@ -9,37 +9,22 @@
   
   import java.io.File;
   import java.io.RandomAccessFile;
  -import java.io.Writer;
  -import java.io.IOException;
  -import java.io.BufferedReader;
  -import java.io.OutputStream;
   import java.io.InputStream;
   import java.io.FileInputStream;
  +import java.io.OutputStream;
   import java.io.FileOutputStream;
  -import java.io.InputStreamReader;
  +import java.io.Writer;
   import java.io.OutputStreamWriter;
  +import java.io.IOException;
   import java.net.Socket;
   import java.net.InetAddress;
   import java.net.UnknownHostException;
   import java.text.SimpleDateFormat;
   import java.util.Date;
  -import java.util.List;
  -import java.util.TimeZone;
  -import java.util.Random;
  -import java.util.ArrayList;
   import java.util.StringTokenizer;
  -import java.lang.reflect.Method;
  -import java.lang.reflect.InvocationTargetException;
   
  -import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
  -
  -import org.apache.avalon.ftpserver.util.StreamConnectorObserver;
   import org.apache.avalon.ftpserver.util.IoUtils;
   import org.apache.avalon.ftpserver.util.StreamConnector;
  -import org.apache.avalon.ftpserver.util.Message;
  -import org.apache.avalon.ftpserver.interfaces.SpyConnectionInterface;
  -import org.apache.avalon.ftpserver.interfaces.FtpConnectionObserver;
  -
   
   /**
    * This class handles each ftp connection. Here all the ftp command
  @@ -47,31 +32,16 @@
    * This is the main backbone of the ftp server.
    * <br>
    * The ftp command method signature is:
  - * <code>protected void doXYZ(FtpRequest request, Writer out)
  - *     throws FtpException, IOException</code>.
  + * <code>public void doXYZ(FtpRequest request, FtpWriter out) throws IOException</code>.
    * <br>
    * Here <code>XYZ</code> is the capitalized ftp command.
    *
    * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
    */
   public
  -class FtpConnection implements ConnectionHandler, StreamConnectorObserver {
  +class FtpConnection extends BaseFtpConnection {
   
       private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("yyyyMMddHHmmss.SSS"); 
  -    private final static String CRLF = "\r\n";
  -    
  -    private final static Class[] METHOD_INPUT_SIG = new Class[] {FtpRequest.class, Writer.class};
  -    
  -    
  -    private FtpConfig mCfg                  = null;
  -    private FtpStatus mFtpStatus            = null;
  -    private FtpDataConnection mDataCon      = null;
  -    public Socket mControlSoc              = null;
  -    private FtpUser mUser                   = null;
  -    private SpyConnectionInterface mSpy     = null;
  -    private FtpConnectionObserver mObserver = null;
  -
  -    private boolean mbStopRequest       = false;
   
       // command state specific temporary variables
       private boolean mbReset   = false;
  @@ -86,173 +56,10 @@
       /**
        * Set configuration file and the control socket.
        */
  -    public FtpConnection(FtpConfig ftpConfig) {
  -      mCfg = ftpConfig;
  -      mFtpStatus = mCfg.getStatus();
  -      mUser = new FtpUser();  
  -    }
  -
  -
  -    /**
  -     * Server one FTP connection.
  -     */
  -    public void handleConnection(final Socket socket) {
  -        
  -        InetAddress clientAddress = socket.getInetAddress();
  -        mCfg.getLogger().info("Handling new request from " + clientAddress.getHostAddress());
  -        mControlSoc = socket;
  -        mDataCon = new FtpDataConnection(mCfg);
  -        mUser.setClientAddress(clientAddress);
  -        mCfg.getConnectionService().newConnection(this);
  -        
  -        BufferedReader in = null;
  -        Writer out = null;        
  -        
  -        try {
  -            in = new BufferedReader(new InputStreamReader(mControlSoc.getInputStream()));              
  -            out = new OutputStreamWriter(mControlSoc.getOutputStream());                    
  -        
  -            // permission check
  -            if( !mCfg.getIpRestrictor().hasPermission(mControlSoc.getInetAddress()) ) {
  -                write(out, mFtpStatus.getResponse(530, null, mUser, null));
  -                return;
  -            }
  -            write(out, mFtpStatus.getResponse(220, null, mUser, null));
  -        
  -            do {
  -                notifyObserver();
  -                String commandLine = in.readLine();
  -            
  -                // test command line
  -                if(commandLine == null) {
  -                    break;
  -                }
  -            
  -                commandLine = commandLine.trim();
  -                spyPrint(commandLine);
  -                spyPrint("\n");
  -            
  -                if(commandLine.equals("")) {
  -                    continue;
  -                }
  -            
  -                FtpRequest request = null;
  -                try {
  -                
  -                    // parse input command
  -                    request = new FtpRequest(commandLine);
  -                    implementationCheck(request);
  -                
  -                    // check user permission
  -                    if(!hasPermission(request)) {
  -                        write(out, mFtpStatus.getResponse(530, request, mUser, null));
  -                        break;
  -                    }
  -                
  -                    // command execute
  -                    execute(request, out);
  -                }
  -                catch(FtpException ex) {
  -                     write(out, mFtpStatus.getResponse(ex.getErrorCode(), request, mUser, null)); 
  -                     if( (ex.getErrorCode() == 530) || (ex.getErrorCode() == 221)  ) {
  -                         break;
  -                     }
  -                }
  -            }
  -            while(!mbStopRequest);
  -        }
  -        catch(Exception ex) {
  -        }
  -        finally {
  -            IoUtils.close(in);
  -            IoUtils.close(out);
  -            mCfg.getConnectionService().closeConnection(mUser.getSessionId());
  -        }
  -    }
  -
  -
  -    /**
  -     * Execute the ftp command.
  -     */
  -    private void execute(FtpRequest request, Writer out) throws FtpException, IOException {
  -        try {
  -             String methodName = "do" + request.getCommand();
  -             Method actionMethod = getClass().getDeclaredMethod(methodName, METHOD_INPUT_SIG);
  -             actionMethod.invoke(this, new Object[] {request, out});
  -         }
  -         catch(NoSuchMethodException ex) {
  -             write(out, mFtpStatus.getResponse(502, request, mUser, null));
  -         }
  -         catch(InvocationTargetException ex) {
  -             Throwable th = ex.getTargetException();
  -             if(th instanceof org.apache.avalon.ftpserver.FtpException) {
  -                 throw (FtpException)th;
  -             }
  -             else {
  -                 write(out, mFtpStatus.getResponse(500, request, mUser, null));
  -             }
  -         }
  -         catch(IllegalAccessException ex) {
  -             write(out, mFtpStatus.getResponse(500, request, mUser, null));
  -         }
  -    }
  -
  -
  -    /**
  -     * Check this command implementation.
  -     */
  -    private void implementationCheck(FtpRequest request) throws FtpException { 
  -      String command = request.getCommand();
  -      if(!FtpRequest.isImplementedFtpCommand(command)) {
  -          if(FtpRequest.isNonImplementedFtpCommand(command)) {
  -              throw new FtpException(502);
  -          }
  -          else {
  -              throw new FtpException(500);
  -          }
  -      }
  +    public FtpConnection(FtpConfig cfg) {
  +        super(cfg);
       }
        
  -    
  -    /**
  -     * Write and flush the string.
  -     */
  -    protected void write(Writer wr, String str) throws IOException {
  -        spyPrint(str);
  -        wr.write(str);
  -        wr.flush();
  -    }
  -    
  -
  -    /**
  -     * User logout and stop this thread.
  -     */
  -    public void stop() {
  -        mbStopRequest = true;
  -        if (mDataCon != null) {
  -            mDataCon.reset();
  -            mDataCon = null;
  -        }
  -        if (mControlSoc != null) {
  -            try {
  -                mControlSoc.close();
  -            }
  -            catch(Exception ex) {
  -            }
  -            mControlSoc = null;
  -        }
  -        mUser.logout();        
  -        mObserver = null;
  -    }
  -     
  -    /**
  -     * Is the connection closed?
  -     */
  -    public boolean isClosed() {
  -        return mbStopRequest;
  -    }
  -    
  -    
       /**
        * Check the user permission to execute this command.
        */
  @@ -267,7 +74,7 @@
       /**
        * Reset temporary state variables.
        */
  -    protected void resetState() {
  +    private void resetState() {
           mbRenFr = false;
           mstRenFr = null;
               
  @@ -278,89 +85,6 @@
           mbPass = false;
       }
    
  -    
  -    /**
  -     * Monitor the user activity.
  -     */
  -    private void spyPrint(final String str) {
  -        final SpyConnectionInterface spy = mSpy;
  -        if (spy != null) {
  -            Message msg = new Message() {
  -                public void execute() {
  -                    try {
  -                        spy.write(str);
  -                    }
  -                    catch(Exception ex) {
  -                        mSpy = null;
  -                        mCfg.getLogger().error("FtpConnection.spyPrint()", ex);
  -                    }
  -                }
  -            };
  -            mCfg.getMessageQueue().add(msg);
  -        }
  -    }
  -    
  -    /**
  -     * Get user object
  -     */
  -    public FtpUser getUser() {
  -        return mUser;
  -    }
  -     
  -    /**
  -     * Get connection spy object
  -     */
  -    public SpyConnectionInterface getSpyObject() {
  -        return mSpy;
  -    }
  -    
  -    /**
  -     * Set spy object
  -     */
  -    public void setSpyObject(SpyConnectionInterface spy) {
  -        mSpy = spy;
  -    }
  -    
  -    /**
  -     * Get observer
  -     */
  -    public FtpConnectionObserver getObserver() {
  -        return mObserver;
  -    }
  -
  -    /**
  -     * Set observer
  -     */
  -    public void setObserver(FtpConnectionObserver obsr) {
  -        mObserver = obsr;
  -    }
  -
  -    /**
  -     * Notify observer.
  -     */
  -    public void notifyObserver() {
  -       mUser.hitUser();
  -       final FtpUser thisUser = mUser; 
  -       final FtpConnectionObserver obsr = mObserver;
  -
  -       if (obsr != null) {
  -            Message msg = new Message() {
  -                public void execute() {
  -                    obsr.updateConnection(thisUser);
  -                }
  -            };
  -            mCfg.getMessageQueue().add(msg);
  -       }
  -    }
  -    
  -    /**
  -     * This method tracks data transfer.
  -     */
  -    public void dataTransferred(int sz) {
  -         notifyObserver();
  -    }
  -         
  -
       ////////////////////////////////////////////////////////////
       /////////////////   all the FTP handlers   /////////////////
       ////////////////////////////////////////////////////////////
  @@ -376,12 +100,12 @@
        * Current implementation does not do anything. As here data 
        * transfers are not multi-threaded. 
        */
  -    protected void doABOR(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doABOR(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
  -        mDataCon.reset();
  -        write(out, mFtpStatus.getResponse(226, request, mUser, null));
  +        mDataConnection.reset();
  +        out.write(mFtpStatus.getResponse(226, request, mUser, null));
       }
       
       
  @@ -395,14 +119,14 @@
        * appended to that file; otherwise the file specified in the
        * pathname shall be created at the server site.
        */
  -    protected void doAPPE(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doAPPE(FtpRequest request, FtpWriter out) throws IOException {
          
           // reset state variables
           resetState();
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
           
  @@ -415,16 +139,21 @@
           
           // check permission
           if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  -            write(out, mFtpStatus.getResponse(450, request, mUser, args));
  +             out.write(mFtpStatus.getResponse(450, request, mUser, args));
               return;
           }
           
           // now transfer file data
  -        write(out, mFtpStatus.getResponse(150, request, mUser, args));
  +        out.write(mFtpStatus.getResponse(150, request, mUser, args));
           InputStream is = null;
           OutputStream os = null;
           try {
  -            Socket dataSoc = mDataCon.getDataSocket();
  +             Socket dataSoc = mDataConnection.getDataSocket();
  +             if (dataSoc == null) {
  +                  out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                  return;
  +             }
  +             
               is = dataSoc.getInputStream();
               RandomAccessFile raf = new RandomAccessFile(requestedFile, "rw");
               raf.seek(raf.length());
  @@ -437,21 +166,21 @@
               msc.connect();
               
               if(msc.hasException()) {
  -                write(out, mFtpStatus.getResponse(451, request, mUser, args));
  +                 out.write(mFtpStatus.getResponse(451, request, mUser, args));
               }
               else {
  -                mCfg.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
  +                 mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
               }
               
  -            write(out, mFtpStatus.getResponse(226, request, mUser, args));
  +             out.write(mFtpStatus.getResponse(226, request, mUser, args));
           }
           catch(IOException ex) {
  -            write(out, mFtpStatus.getResponse(425, request, mUser, args));
  +             out.write(mFtpStatus.getResponse(425, request, mUser, args));
           }
           finally {
              IoUtils.close(is);
              IoUtils.close(os);
  -           mDataCon.reset(); 
  +           mDataConnection.reset(); 
           }
       }
       
  @@ -465,7 +194,7 @@
        * syntaxes for naming the parent directory.  The reply codes
        * shall be identical to the reply codes of CWD.      
        */
  -    protected void doCDUP(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doCDUP(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
  @@ -473,10 +202,10 @@
           // change directory
           if (mUser.getVirtualDirectory().changeDirectory("..")) {
               String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
  -            write(out, mFtpStatus.getResponse(200, request, mUser, args));
  +            out.write(mFtpStatus.getResponse(200, request, mUser, args));
           }
           else {
  -        	write(out, mFtpStatus.getResponse(431, request, mUser, null));
  +         	out.write(mFtpStatus.getResponse(431, request, mUser, null));
           }
       }
       
  @@ -490,7 +219,7 @@
        * parameters are similarly unchanged.  The argument is a
        * pathname specifying a directory.
        */
  -    protected void doCWD(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doCWD(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
  @@ -504,11 +233,11 @@
           // change directory
           if (mUser.getVirtualDirectory().changeDirectory(dirName)) {
               String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
  -            write(out, mFtpStatus.getResponse(200, request, mUser, args));
  +            out.write(mFtpStatus.getResponse(200, request, mUser, args));
  +        }
  +        else {
  +         	out.write(mFtpStatus.getResponse(431, request, mUser, null));
           }
  -     else {
  -        	write(out, mFtpStatus.getResponse(431, request, mUser, null));
  -     }
       }
       
       
  @@ -518,15 +247,15 @@
        * This command causes the file specified in the pathname to be
        * deleted at the server site.
        */
  -    protected void doDELE(FtpRequest request, Writer out) throws IOException {
  +     public void doDELE(FtpRequest request, FtpWriter out) throws IOException {
          
          // reset state variables
          resetState();  
           
          // argument check
          if(!request.hasArgument()) {
  -          write(out, mFtpStatus.getResponse(501, request, mUser, null));
  -          return;  
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +           return;  
          }    
          
          // get filenames
  @@ -538,17 +267,17 @@
          
          // check permission
          if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  -           write(out, mFtpStatus.getResponse(450, request, mUser, args));
  +           out.write(mFtpStatus.getResponse(450, request, mUser, args));
              return;
          }
       
          // now delete
          if(requestedFile.delete()) {
  -          write(out, mFtpStatus.getResponse(250, request, mUser, args)); 
  -          mCfg.getStatistics().setDelete(requestedFile, mUser); 
  +           out.write(mFtpStatus.getResponse(250, request, mUser, args)); 
  +           mConfig.getStatistics().setDelete(requestedFile, mUser); 
          }
          else {
  -          write(out, mFtpStatus.getResponse(450, request, mUser, args));
  +           out.write(mFtpStatus.getResponse(450, request, mUser, args));
          }
       }
       
  @@ -562,23 +291,19 @@
        * argument (e.g., any command name) and return more specific
        * information as a response.
        */
  -    protected void doHELP(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doHELP(FtpRequest request, FtpWriter out) throws IOException {
           
           // print global help
           if(!request.hasArgument()) {
  -            write(out, mFtpStatus.getResponse(214, null, mUser, null));
  +            out.write(mFtpStatus.getResponse(214, null, mUser, null));
               return;
           }
           
           // print command specific help
           String ftpCmd = request.getArgument().toUpperCase();
           String args[] = null;
  -        if(!request.isFtpCommand(ftpCmd)) {
  -            args = new String[] {ftpCmd};
  -            ftpCmd = "UNKNOWN";
  -        }
           FtpRequest tempRequest = new FtpRequest(ftpCmd);
  -        write(out, mFtpStatus.getResponse(214, tempRequest, mUser, args));
  +        out.write(mFtpStatus.getResponse(214, tempRequest, mUser, args));
           return;
       } 
       
  @@ -595,31 +320,36 @@
        * default directory.  The data transfer is over the data
        * connection
        */
  -    protected void doLIST(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doLIST(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
           
  -        write(out, mFtpStatus.getResponse(150, request, mUser, null));
  +         out.write(mFtpStatus.getResponse(150, request, mUser, null));
           Writer os = null;
           try {
  -            Socket dataSoc = mDataCon.getDataSocket();
  +             Socket dataSoc = mDataConnection.getDataSocket();
  +             if (dataSoc == null) {
  +                  out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +                  return;
  +             }
  +             
               os = new OutputStreamWriter(dataSoc.getOutputStream());
               
               if (!mUser.getVirtualDirectory().printList(request.getArgument(), os)) {
  -            	write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +             	out.write(mFtpStatus.getResponse(501, request, mUser, null));
               }
               else {
  -               os.flush();
  -               write(out, mFtpStatus.getResponse(226, request, mUser, null));
  +                os.flush();
  +                out.write(mFtpStatus.getResponse(226, request, mUser, null));
               }
           }
           catch(IOException ex) {
  -            write(out, mFtpStatus.getResponse(425, request, mUser, null));
  +             out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
               IoUtils.close(os);
  -            mDataCon.reset();
  +            mDataConnection.reset();
           }
       }
       
  @@ -629,11 +359,11 @@
        * 
        * Returns the date and time of when a file was modified.
        */
  -    protected void doMDTM(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doMDTM(FtpRequest request, FtpWriter out) throws IOException {
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
          
  @@ -649,10 +379,10 @@
           // now print date
           if(reqFile.exists()) {
               String args[] = {DATE_FMT.format(new Date(reqFile.lastModified()))};
  -            write(out, mFtpStatus.getResponse(213, request, mUser, args));
  +            out.write(mFtpStatus.getResponse(213, request, mUser, args));
           }
           else {
  -            write(out, mFtpStatus.getResponse(550, request, mUser, null));
  +             out.write(mFtpStatus.getResponse(550, request, mUser, null));
           }
       } 
       
  @@ -665,14 +395,14 @@
        * or as a subdirectory of the current working directory (if
        * the pathname is relative).
        */
  -    protected void doMKD(FtpRequest request, Writer out) throws IOException {
  +     public void doMKD(FtpRequest request, FtpWriter out) throws IOException {
          
          // reset state variables
          resetState(); 
           
          // argument check
          if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
          }
          
  @@ -684,16 +414,16 @@
          
          // check permission
          if(!mUser.getVirtualDirectory().hasCreatePermission(physicalName, true)) {
  -           write(out, mFtpStatus.getResponse(450, request, mUser, args));
  +           out.write(mFtpStatus.getResponse(450, request, mUser, args));
              return;
          }
          
  -    // now create directory
  +       // now create directory
          if(new File(fileName).mkdirs()) {
  -          write(out, mFtpStatus.getResponse(250, request, mUser, args)); 
  +           out.write(mFtpStatus.getResponse(250, request, mUser, args)); 
          }
          else {
  -          write(out, mFtpStatus.getResponse(450, request, mUser, args));
  +           out.write(mFtpStatus.getResponse(450, request, mUser, args));
          }
       }
   
  @@ -705,22 +435,22 @@
        * the data transfer modes described in the Section on
        * Transmission Modes.
        */
  -    protected void doMODE(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doMODE(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
           
           if (mUser.setMode(request.getArgument().charAt(0))) {
  -           write(out, mFtpStatus.getResponse(200, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(200, request, mUser, null));
           }
           else {
  -           write(out, mFtpStatus.getResponse(504, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(504, request, mUser, null));
           }
       }
       
  @@ -735,31 +465,36 @@
        * will return a stream of names of files and no other
        * information.
        */
  -    protected void doNLST(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doNLST(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
           
  -        write(out, mFtpStatus.getResponse(150, request, mUser, null));
  +        out.write(mFtpStatus.getResponse(150, request, mUser, null));
           Writer os = null;
           try {
  -            Socket dataSoc = mDataCon.getDataSocket();
  +             Socket dataSoc = mDataConnection.getDataSocket();
  +             if (dataSoc == null) {
  +                  out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +                  return;
  +             }
  +             
               os = new OutputStreamWriter(dataSoc.getOutputStream());
               
               if (!mUser.getVirtualDirectory().printNList(request.getArgument(), os)) {
  -            	write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +             	out.write(mFtpStatus.getResponse(501, request, mUser, null));
               }
               else {
  -               os.flush();
  -               write(out, mFtpStatus.getResponse(226, request, mUser, null));
  +                os.flush();
  +                out.write(mFtpStatus.getResponse(226, request, mUser, null));
               }
           }
           catch(IOException ex) {
  -            write(out, mFtpStatus.getResponse(425, request, mUser, null));
  +             out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
               IoUtils.close(os);
  -            mDataCon.reset();
  +            mDataConnection.reset();
           }
       }
       
  @@ -771,12 +506,12 @@
        * entered commands. It specifies no action other than that the
        * server send an OK reply.
        */
  -    protected void doNOOP(FtpRequest request, Writer out) throws IOException {
  +     public void doNOOP(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
           
  -        write(out, mFtpStatus.getResponse(200, request, mUser, null));
  +        out.write(mFtpStatus.getResponse(200, request, mUser, null));
       } 
       
       
  @@ -787,11 +522,11 @@
        * password.  This command must be immediately preceded by the
        * user name command.
        */
  -    protected void doPASS(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doPASS(FtpRequest request, FtpWriter out) throws IOException {
   
           // set state variables
           if(!mbUser) {
  -            write(out, mFtpStatus.getResponse(500, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(500, request, mUser, null));
               resetState();
               return;
           }
  @@ -802,12 +537,18 @@
           String pass = request.hasArgument() ? request.getArgument() : "";
           mUser.setPassword(pass);     
   
  -        if (!mCfg.getConnectionService().login(mUser)){
  -           throw new FtpException(530);
  +         // login failure - close connection
  +         String args[] = {mUser.getName()};
  +         if (mConfig.getConnectionService().login(mUser)) {
  +            out.write(mFtpStatus.getResponse(230, request, mUser, args));
  +         }
  +         else {
  +            out.write(mFtpStatus.getResponse(530, request, mUser, args));
  +            ConnectionService conService = mConfig.getConnectionService();
  +            if (conService != null) {
  +                conService.closeConnection(mUser.getSessionId());
  +            }
           }
  -        
  -        String args[] = {mUser.getName()};
  -        write(out, mFtpStatus.getResponse(230, request, mUser, args));
       }
       
       
  @@ -820,21 +561,27 @@
        * transfer command.  The response to this command includes the
        * host and port address this server is listening on.
        */
  -    protected void doPASV(FtpRequest request, Writer out) throws FtpException, IOException {
  -        mDataCon.setPasvCommand();
  +     public void doPASV(FtpRequest request, FtpWriter out) throws IOException {
  +    
  +         if (!mDataConnection.setPasvCommand()) {
  +             out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +             return;   
  +         }
           
  -        InetAddress servAddr = mDataCon.getInetAddress();
  +        InetAddress servAddr = mDataConnection.getInetAddress();
           if(servAddr == null) {
  -            servAddr = mCfg.getSelfAddress();
  +             servAddr = mConfig.getSelfAddress();
           }        
   
  -        int servPort = mDataCon.getPort();
  +         int servPort = mDataConnection.getPort();
           
           String addrStr = servAddr.getHostAddress().replace( '.', ',' ) + ',' + (servPort>>8) + ',' + (servPort&0xFF);
           String[] args = {addrStr};
           
  -        write(out, mFtpStatus.getResponse(227, request, mUser, args));
  -        mDataCon.listenPasvConnection();
  +         out.write(mFtpStatus.getResponse(227, request, mUser, args));
  +         if (!mDataConnection.listenPasvConnection()) {
  +            out.write(mFtpStatus.getResponse(425, request, mUser, args));
  +         }
       }
       
       
  @@ -856,7 +603,7 @@
        * 
        * where h1 is the high order 8 bits of the internet host address.
        */
  -    protected void doPORT(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doPORT(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
  @@ -866,13 +613,13 @@
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
   
           StringTokenizer st = new StringTokenizer(request.getArgument(), ",");
           if(st.countTokens() != 6) {
  -            write(out, mFtpStatus.getResponse(510, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(510, request, mUser, null));
               return;
           }
               
  @@ -883,7 +630,7 @@
               clientAddr = InetAddress.getByName(dataSrvName);
           }
           catch(UnknownHostException ex) {
  -            write(out, mFtpStatus.getResponse(553, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(553, request, mUser, null));
               return;
           }
           
  @@ -894,11 +641,11 @@
               clientPort = (hi << 8) | lo;     
           }
           catch(NumberFormatException ex) {
  -           write(out, mFtpStatus.getResponse(552, request, mUser, null)); 
  +           out.write(mFtpStatus.getResponse(552, request, mUser, null)); 
              return; 
           }
  -        mDataCon.setPortCommand(clientAddr, clientPort);
  -        write(out, mFtpStatus.getResponse(200, request, mUser, null));
  +        mDataConnection.setPortCommand(clientAddr, clientPort);
  +        out.write(mFtpStatus.getResponse(200, request, mUser, null));
       }
       
       
  @@ -908,12 +655,12 @@
        * This command causes the name of the current working
        * directory to be returned in the reply.
        */
  -    protected void doPWD(FtpRequest request, Writer out) throws IOException {
  +     public void doPWD(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
           String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
  -        write(out, mFtpStatus.getResponse(257, request, mUser, args));
  +        out.write(mFtpStatus.getResponse(257, request, mUser, args));
       }
       
       
  @@ -923,13 +670,17 @@
        * This command terminates a USER and if file transfer is not
        * in progress, the server closes the control connection.
        */
  -    protected void doQUIT(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doQUIT(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
           
           // and exit
  -        throw new FtpException(221);
  +        out.write(mFtpStatus.getResponse(221, request, mUser, null));
  +        ConnectionService conService = mConfig.getConnectionService();
  +        if (conService != null) {
  +            conService.closeConnection(mUser.getSessionId());
  +        }
       }
       
       
  @@ -943,11 +694,11 @@
        * by the appropriate FTP service command which shall cause
        * file transfer to resume.
        */
  -    protected void doREST(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doREST(FtpRequest request, FtpWriter out) throws IOException {
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
          
  @@ -959,16 +710,16 @@
                mlSkipLen = Long.parseLong(skipNum);
           }
           catch(NumberFormatException ex) {
  -            write(out, mFtpStatus.getResponse(501, request, mUser, null)); 
  +             out.write(mFtpStatus.getResponse(501, request, mUser, null)); 
               return;
           }
           if(mlSkipLen < 0) {
               mlSkipLen = 0;
  -            write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +             out.write(mFtpStatus.getResponse(501, request, mUser, null));
               return;
           }
           mbReset = true;
  -        write(out, mFtpStatus.getResponse(350, request, mUser, null));
  +        out.write(mFtpStatus.getResponse(350, request, mUser, null));
       } 
       
       
  @@ -980,7 +731,7 @@
        * at the other end of the data connection.  The status and
        * contents of the file at the server site shall be unaffected.
        */
  -    protected void doRETR(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doRETR(FtpRequest request, FtpWriter out) throws IOException {
           
           // set state variables
           long skipLen = (mbReset) ? mlSkipLen : 0;
  @@ -988,7 +739,7 @@
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
           
  @@ -1001,16 +752,21 @@
           
           // check permission
           if(!mUser.getVirtualDirectory().hasReadPermission(physicalName, true)) {
  -            write(out, mFtpStatus.getResponse(550, request, mUser, args));
  +            out.write(mFtpStatus.getResponse(550, request, mUser, args));
               return;
           }
           
           // now transfer file data
  -        write(out, mFtpStatus.getResponse(150, request, mUser, null));
  +        out.write(mFtpStatus.getResponse(150, request, mUser, null));
           InputStream is = null;
           OutputStream os = null;
           try {
  -            Socket dataSoc = mDataCon.getDataSocket();
  +             Socket dataSoc = mDataConnection.getDataSocket();
  +             if (dataSoc == null) {
  +                  out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                  return;
  +             }
  +             
               os = mUser.getOutputStream(dataSoc.getOutputStream());
               
               RandomAccessFile raf = new RandomAccessFile(requestedFile, "r");
  @@ -1024,22 +780,22 @@
               msc.connect();
               
               if(msc.hasException()) {
  -                write(out, mFtpStatus.getResponse(451, request, mUser, args));
  +                out.write(mFtpStatus.getResponse(451, request, mUser, args));
                   return;
               }
               else {
  -                mCfg.getStatistics().setDownload(requestedFile, mUser, msc.getTransferredSize());
  +                 mConfig.getStatistics().setDownload(requestedFile, mUser, msc.getTransferredSize());
               }
               
  -            write(out, mFtpStatus.getResponse(226, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(226, request, mUser, null));
           }
           catch(IOException ex) {
  -            write(out, mFtpStatus.getResponse(425, request, mUser, null));
  +             out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
               IoUtils.close(is);
               IoUtils.close(os);
  -            mDataCon.reset();
  +            mDataConnection.reset();
           }
       }
       
  @@ -1052,14 +808,14 @@
        * or as a subdirectory of the current working directory (if
        * the pathname is relative).
        */
  -    protected void doRMD(FtpRequest request, Writer out) throws IOException {
  +     public void doRMD(FtpRequest request, FtpWriter out) throws IOException {
          
          // reset state variables
          resetState(); 
           
          // argument check
          if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
          }
          
  @@ -1072,16 +828,16 @@
          
          // check permission
          if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  -           write(out, mFtpStatus.getResponse(450, request, mUser, args));
  +           out.write(mFtpStatus.getResponse(450, request, mUser, args));
              return;
          }
       
          // now delete
          if(requestedFile.delete()) {
  -          write(out, mFtpStatus.getResponse(250, request, mUser, args)); 
  +           out.write(mFtpStatus.getResponse(250, request, mUser, args)); 
          }
          else {
  -          write(out, mFtpStatus.getResponse(450, request, mUser, args));
  +           out.write(mFtpStatus.getResponse(450, request, mUser, args));
          }
       }
       
  @@ -1093,14 +849,14 @@
        * to be renamed.  This command must be immediately followed by
        * a "rename to" command specifying the new file pathname.
        */
  -    protected void doRNFR(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doRNFR(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variable
           resetState();
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
           
  @@ -1113,7 +869,7 @@
           mstRenFr = mUser.getVirtualDirectory().getPhysicalName(fileName);
           String args[] = {fileName};
           
  -        write(out, mFtpStatus.getResponse(350, request, mUser, args));
  +        out.write(mFtpStatus.getResponse(350, request, mUser, args));
       }
       
       
  @@ -1125,19 +881,19 @@
        * command.  Together the two commands cause a file to be
        * renamed.
        */
  -    protected void doRNTO(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doRNTO(FtpRequest request, FtpWriter out) throws IOException {
           
           // argument check
           if(!request.hasArgument()) {
              resetState(); 
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
           
           // set state variables
           if((!mbRenFr) || (mstRenFr == null)) {
                resetState();
  -             write(out, mFtpStatus.getResponse(100, request, mUser, null));
  +             out.write(mFtpStatus.getResponse(100, request, mUser, null));
                return;
           }
           
  @@ -1154,16 +910,16 @@
           
           // check permission
           if(!mUser.getVirtualDirectory().hasCreatePermission(physicalToFileStr, true)) {
  -           write(out, mFtpStatus.getResponse(553, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(553, request, mUser, null));
              return;
           }
           
           // now rename
           if(fromFile.renameTo(toFile)) {
  -            write(out, mFtpStatus.getResponse(250, request, mUser, args));
  +             out.write(mFtpStatus.getResponse(250, request, mUser, args));
           }
           else {
  -            write(out, mFtpStatus.getResponse(553, request, mUser, args));
  +             out.write(mFtpStatus.getResponse(553, request, mUser, args));
           }
       } 
       
  @@ -1176,8 +932,9 @@
        * but not sufficiently universal to be included as commands in
        * the protocol.
        */
  -    protected void doSITE(FtpRequest request, Writer out) throws FtpException, IOException {
  -        write(out, mFtpStatus.getResponse(200, request, mUser, null));
  +     public void doSITE(FtpRequest request, FtpWriter out) throws IOException {
  +         SiteCommandHandler siteCmd = new SiteCommandHandler( mConfig, mUser );
  +         out.write( siteCmd.getResponse(request) );
       }
       
       
  @@ -1186,11 +943,11 @@
        *
        * Returns the size of the file in bytes.
        */
  -    protected void doSIZE(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doSIZE(FtpRequest request, FtpWriter out) throws IOException {
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
          
  @@ -1206,10 +963,10 @@
           // print file size
           if(reqFile.exists()) {
               String args[] = {String.valueOf(reqFile.length())};             
  -            write(out, mFtpStatus.getResponse(213, request, mUser, args));
  +            out.write(mFtpStatus.getResponse(213, request, mUser, args));
           }
           else {
  -            write(out, mFtpStatus.getResponse(550, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(550, request, mUser, null));
           }
       } 
       
  @@ -1220,14 +977,14 @@
        * This command shall cause a status response to be sent over
        * the control connection in the form of a reply.
        */
  -    protected void doSTAT(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doSTAT(FtpRequest request, FtpWriter out) throws IOException {
           String args[] = {
  -           mCfg.getSelfAddress().getHostAddress(),
  -           mControlSoc.getInetAddress().getHostAddress(),
  -           mUser.getName()
  +            mConfig.getSelfAddress().getHostAddress(),
  +            mControlSocket.getInetAddress().getHostAddress(),
  +            mUser.getName()
           };
         
  -        write(out, mFtpStatus.getResponse(211, request, mUser, args)); 
  +        out.write(mFtpStatus.getResponse(211, request, mUser, args)); 
       } 
       
       
  @@ -1242,7 +999,7 @@
        * created at the server site if the file specified in the
        * pathname does not already exist.
        */
  -    protected void doSTOR(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doSTOR(FtpRequest request, FtpWriter out) throws IOException {
           
           // set state variables
           long skipLen = (mbReset) ? mlSkipLen : 0;
  @@ -1250,7 +1007,7 @@
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
           
  @@ -1262,16 +1019,21 @@
           
           // get permission
           if(!mUser.getVirtualDirectory().hasCreatePermission(physicalName, true)) {
  -            write(out, mFtpStatus.getResponse(550, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(550, request, mUser, null));
               return;
           }
           
           // now transfer file data
  -        write(out, mFtpStatus.getResponse(150, request, mUser, null));
  +        out.write(mFtpStatus.getResponse(150, request, mUser, null));
           InputStream is = null;
           OutputStream os = null;
           try {
  -            Socket dataSoc = mDataCon.getDataSocket();
  +            Socket dataSoc = mDataConnection.getDataSocket();
  +            if (dataSoc == null) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +                return;
  +            }
  +             
               is = dataSoc.getInputStream();
               
               RandomAccessFile raf = new RandomAccessFile(requestedFile, "rw");
  @@ -1285,22 +1047,22 @@
               msc.connect();
               
               if(msc.hasException()) {
  -                write(out, mFtpStatus.getResponse(451, request, mUser, null));
  +                out.write(mFtpStatus.getResponse(451, request, mUser, null));
                   return;
               }
               else {
  -                mCfg.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
  +                mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
               }
               
  -            write(out, mFtpStatus.getResponse(226, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(226, request, mUser, null));
           }
           catch(IOException ex) {
  -            write(out, mFtpStatus.getResponse(425, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
               IoUtils.close(is);
               IoUtils.close(os);
  -            mDataCon.reset();
  +            mDataConnection.reset();
           }
       }
       
  @@ -1313,7 +1075,7 @@
        * unique to that directory.  The 250 Transfer Started response
        * must include the name generated.
        */
  -    protected void doSTOU(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doSTOU(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
  @@ -1328,16 +1090,22 @@
           
           // check permission
           if(!mUser.getVirtualDirectory().hasCreatePermission(fileName, false)) {
  -            write(out, mFtpStatus.getResponse(550, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(550, request, mUser, null));
               return;
           }
           
           // now transfer file data
  -        write(out, mFtpStatus.getResponse(150, request, mUser, null));
  +        out.write(mFtpStatus.getResponse(150, request, mUser, null));
           InputStream is = null;
           OutputStream os = null;
           try {
  -            Socket dataSoc = mDataCon.getDataSocket();
  +             Socket dataSoc = mDataConnection.getDataSocket();
  +             if (dataSoc == null) {
  +                  out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                  return;
  +             }
  +
  +             
               is = dataSoc.getInputStream();
               os = mUser.getOutputStream( new FileOutputStream(requestedFile) );
               
  @@ -1348,24 +1116,24 @@
               msc.connect();
               
               if(msc.hasException()) {
  -                write(out, mFtpStatus.getResponse(451, request, mUser, null));
  +                out.write(mFtpStatus.getResponse(451, request, mUser, null));
                   return;
               }
               else {
  -                mCfg.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
  +                mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
               }
               
  -            write(out, mFtpStatus.getResponse(226, request, mUser, null));
  -            mDataCon.reset();
  -            write(out, mFtpStatus.getResponse(250, request, mUser, args));
  +             out.write(mFtpStatus.getResponse(226, request, mUser, null));
  +             mDataConnection.reset();
  +             out.write(mFtpStatus.getResponse(250, request, mUser, args));
           }
           catch(IOException ex) {
  -            write(out, mFtpStatus.getResponse(425, request, mUser, null));
  +             out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
              IoUtils.close(is);
              IoUtils.close(os);
  -           mDataCon.reset(); 
  +           mDataConnection.reset(); 
           }
       }
       
  @@ -1376,22 +1144,22 @@
        * The argument is a single Telnet character code specifying
        * file structure.
        */
  -    protected void doSTRU(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doSTRU(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +           out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }
           
           if (mUser.setStructure(request.getArgument().charAt(0))) {
  -           write(out, mFtpStatus.getResponse(200, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(200, request, mUser, null));
           }
           else {
  -        	write(out, mFtpStatus.getResponse(504, request, mUser, null));
  +         	out.write(mFtpStatus.getResponse(504, request, mUser, null));
           }
       }
       
  @@ -1402,13 +1170,13 @@
        * This command is used to find out the type of operating
        * system at the server.
        */
  -    protected void doSYST(FtpRequest request, Writer out) throws IOException {
  +     public void doSYST(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
           
  -        String args[] = {mCfg.getSystemName()};
  -        write(out, mFtpStatus.getResponse(215, request, mUser, args));
  +        String args[] = {mConfig.getSystemName()};
  +        out.write(mFtpStatus.getResponse(215, request, mUser, args));
       }
       
       
  @@ -1417,7 +1185,7 @@
        *
        * The argument specifies the representation type.
        */
  -    protected void doTYPE(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doTYPE(FtpRequest request, FtpWriter out) throws IOException {
           
           // reset state variables
           resetState();
  @@ -1430,10 +1198,10 @@
           
           // set it
           if (mUser.setType(type)) {
  -           write(out, mFtpStatus.getResponse(200, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(200, request, mUser, null));
           }
           else {
  -        	write(out, mFtpStatus.getResponse(504, request, mUser, null));
  +         	out.write(mFtpStatus.getResponse(504, request, mUser, null));
           }
       }
       
  @@ -1447,14 +1215,14 @@
        * normally be the first command transmitted by the user after
        * the control connections are made.
        */
  -    protected void doUSER(FtpRequest request, Writer out) throws FtpException, IOException {
  +     public void doUSER(FtpRequest request, FtpWriter out) throws IOException {
           
           // set state variables
           resetState();
           
           // argument check
           if(!request.hasArgument()) {
  -           write(out, mFtpStatus.getResponse(501, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
              return;  
           }         
           
  @@ -1462,28 +1230,33 @@
           mbUser = true;
           if(mUser.hasLoggedIn()) {
               if(mUser.getName().equals(request.getArgument())) {
  -                write(out, mFtpStatus.getResponse(230, request, mUser, null));
  +                out.write(mFtpStatus.getResponse(230, request, mUser, null));
                   return;
               }
               else {
  -                mCfg.getConnectionService().closeConnection(mUser.getSessionId());
  +                mConfig.getConnectionService().closeConnection(mUser.getSessionId());
               }
           }
   
           // set user name and send appropriate message
           mUser.setName(request.getArgument());
           if(mUser.getIsAnonymous()) {
  -            if(mCfg.isAnonymousLoginAllowed()) { 
  -                FtpRequest anoRequest = new FtpRequest(mUser.getName());
  -                write(out, mFtpStatus.getResponse(331, anoRequest, mUser, null));
  +             if(mConfig.isAnonymousLoginAllowed()) { 
  +                 FtpRequest anoRequest = new FtpRequest(mUser.getName());
  +                 out.write(mFtpStatus.getResponse(331, anoRequest, mUser, null));
               }
               else {
  -                throw new FtpException(530);
  +                 out.write(mFtpStatus.getResponse(530, request, mUser, null));
  +                 ConnectionService conService = mConfig.getConnectionService();
  +                 if (conService != null) {
  +                    conService.closeConnection(mUser.getSessionId());
  +                 }
               }
           }
           else {
  -            write(out, mFtpStatus.getResponse(331, request, mUser, null));
  +             out.write(mFtpStatus.getResponse(331, request, mUser, null));
           }
       }
   
   }
  +
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message