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 FtpDataConnection.java FtpConnection.java
Date Tue, 29 Oct 2002 17:06:20 GMT
rana_b      2002/10/29 09:06:20

  Modified:    ftpserver/src/java/org/apache/avalon/ftpserver
                        FtpDataConnection.java FtpConnection.java
  Log:
  PASV socket closing bug fixed
  
  Revision  Changes    Path
  1.8       +57 -50    jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpDataConnection.java
  
  Index: FtpDataConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/FtpDataConnection.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FtpDataConnection.java	10 Oct 2002 16:02:56 -0000	1.7
  +++ FtpDataConnection.java	29 Oct 2002 17:06:20 -0000	1.8
  @@ -1,4 +1,5 @@
   //$Id$
  +
   /*
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
  @@ -6,7 +7,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    */
  -
  + 
   package org.apache.avalon.ftpserver;
   
   import java.net.Socket;
  @@ -23,15 +24,15 @@
    */
   class FtpDataConnection {
       
  -    private FtpConfig    mConfig  = null;
  -    private Socket       mDataSoc = null;
  +    private FtpConfig mConfig = null;
  +    private Socket mDataSoc = null;
       private ServerSocket mServSoc = null;
       
  -    private InetAddress  mAddress = null;
  +    private InetAddress mAddress = null;
       private int          miPort   = 0;
       
  -    private boolean mbPort  = false;
  -    private boolean mbPasv  = false;
  +    private boolean mbPort = false;
  +    private boolean mbPasv = false;
       
       
       /**
  @@ -47,28 +48,45 @@
        * Close data socket.
        */
       public void closeDataSocket() {
  +        
  +        // close client socket if any
           if(mDataSoc != null) {
  -            try { 
  -                mDataSoc.close(); 
  -            } 
  +            try {
  +                mDataSoc.close();
  +            }
               catch(Exception ex) {
  -                mConfig.getLogger().warn("FtpDataConnection.reset()", ex);
  +                mConfig.getLogger().warn("FtpDataConnection.closeDataSocket()", ex);
               }
               mDataSoc = null;
           }
  +        
  +        // close server socket if any
  +        if(mServSoc != null) {
  +            try {
  +                mServSoc.close();
  +            }
  +            catch(Exception ex) {
  +                mConfig.getLogger().warn("FtpDataConnection.closeDataSocket()", ex);
  +            }
  +            mServSoc = null;
  +        }
       }
  -     
  -     
  +    
  +    
       /**
        * Port command.
        */
       public void setPortCommand(InetAddress addr, int port) {
  +        
  +        // close old sockets if any
           closeDataSocket();
  +        
  +        // set variables
           mbPort = true;
           mbPasv = false;
           mAddress = addr;
           miPort = port;
  -    } 
  +    }
       
       
       /**
  @@ -76,21 +94,21 @@
        */
       public boolean setPasvCommand() {
           boolean bRet = false;
  -        closeDataSocket(); 
  +        
  +        // close old sockets if any
  +        closeDataSocket();
           
           try {
               
  -            // open passive server socket if not done already      
  -            if (mServSoc == null)  {
  -                mServSoc = new ServerSocket(getPassivePort(), 1, mConfig.getSelfAddress());
  -            }  
  -            
  -          mAddress = mConfig.getSelfAddress();
  -          miPort = mServSoc.getLocalPort();
  +            // open passive server socket and get parameters
  +            mServSoc = new ServerSocket(getPassivePort(), 1, mConfig.getSelfAddress());
  +            mAddress = mConfig.getSelfAddress();
  +            miPort = mServSoc.getLocalPort();
               
  -          mbPort = false;
  -          mbPasv = true;
  -          bRet = true;
  +            // set different state variables
  +            mbPort = false;
  +            mbPasv = true;
  +            bRet = true;
           }
           catch(Exception ex) {
               mServSoc = null;
  @@ -98,36 +116,34 @@
           }
           return bRet;
       }
  -     
  -     
  +    
  +    
       /**
        * Get client address.
        */
       public InetAddress getInetAddress() {
           return mAddress;
       }
  -     
  -     
  +    
  +    
       /**
        * Get port number.
        */
       public int getPort() {
           return miPort;
       }
  -     
  -     
  +    
  +    
       /**
        * Get the data socket. In case of error returns null.
        */
       public Socket getDataSocket() {
          
  -        // close data connecton if not done already
  -        closeDataSocket();
  -       
  -        // get socket depending on the selection
           try {
  +            
  +            // get socket depending on the selection
               if(mbPort) {
  -                mDataSoc = new Socket(mAddress, miPort);                  
  +                mDataSoc = new Socket(mAddress, miPort);
               }
               else if(mbPasv) {
                   mDataSoc = mServSoc.accept();
  @@ -140,11 +156,11 @@
           
           return mDataSoc;
       }
  -
       
  -   /**
  +    
  +    /**
        * Get the passive port. Later we shall use only predefined 
  -     * port range for passive connection.
  +     * port range for passive connections.
        */
       private int getPassivePort() {
           return 0;
  @@ -153,19 +169,10 @@
       
       /**
        * Dispose data connection
  -     */ 
  +     */
       public void dispose() {
           closeDataSocket();
  -        if (mServSoc != null) {
  -            try {
  -               mServSoc.close();
  -            }
  -            catch(Exception ex) {
  -                mConfig.getLogger().warn("FtpDataConnection.dispose()", ex);
  -            }
  -            mServSoc = null;
  -        }
       }
  -
  +              
   }
       
  
  
  
  1.15      +565 -546  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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- FtpConnection.java	10 Oct 2002 16:03:21 -0000	1.14
  +++ FtpConnection.java	29 Oct 2002 17:06:20 -0000	1.15
  @@ -1,4 +1,5 @@
   // $Id$
  +
   /*
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
  @@ -41,57 +42,58 @@
    */
   public
   class FtpConnection extends BaseFtpConnection {
  -
  +    
       // as SimpleDateFormat is not thread-safe we have to use ThreadLocal
  -    private final static ThreadLocal DATE_FMT = new ThreadLocal() {
  +    private final static ThreadLocal DATE_FMT = new ThreadLocal()  {
           protected Object initialValue() {
  -            return new SimpleDateFormat("yyyyMMddHHmmss.SSS"); 
  +            return new SimpleDateFormat("yyyyMMddHHmmss.SSS");
           }
       };
  -
  +    
       // command state specific temporary variables
  -    private boolean mbReset   = false;
  -    private long    mlSkipLen = 0;
  -
  -    private boolean mbRenFr   = false;
  -    private String  mstRenFr  = null;
  -
  -    private boolean mbUser    = false;
  -    private boolean mbPass    = false;
  -
  +    private boolean mbReset = false;
  +    private long mlSkipLen = 0;
  +    
  +    private boolean mbRenFr = false;
  +    private String mstRenFr = null;
  +    
  +    private boolean mbUser = false;
  +    private boolean mbPass = false;
  +    
       /**
        * Set configuration file and the control socket.
        */
       public FtpConnection(FtpConfig cfg) {
           super(cfg);
       }
  -
  +    
  +    
       /**
        * Check the user permission to execute this command.
        */
       protected boolean hasPermission(FtpRequest request) {
           String cmd = request.getCommand();
  -        return mUser.hasLoggedIn() ||
  -                cmd.equals("USER") ||
  +        return mUser.hasLoggedIn() || 
  +                cmd.equals("USER") || 
                   cmd.equals("PASS") ||
                   cmd.equals("HELP") ||
                   cmd.equals("SYST");
       }
  -
  +    
       /**
        * Reset temporary state variables.
        */
       private void resetState() {
           mbRenFr = false;
           mstRenFr = null;
  -
  +            
           mbReset = false;
           mlSkipLen = 0;
  -
  +            
           mbUser = false;
           mbPass = false;
       }
  -
  +    
       ////////////////////////////////////////////////////////////
       /////////////////   all the FTP handlers   /////////////////
       ////////////////////////////////////////////////////////////
  @@ -107,17 +109,17 @@
        * Current implementation does not do anything. As here data
        * transfers are not multi-threaded.
        */
  -     public void doABOR(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doABOR(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state variables
           resetState();
  -         
  +        
           // and abort any data connection
           mDataConnection.closeDataSocket();
           out.write(mFtpStatus.getResponse(226, request, mUser, null));
       }
  -
  -
  +    
  +    
       /**
        * <code>APPE &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -128,73 +130,82 @@
        * appended to that file; otherwise the file specified in the
        * pathname shall be created at the server site.
        */
  -     public void doAPPE(FtpRequest request, FtpWriter out) throws IOException {
  -
  -        // reset state variables
  -        resetState();
  -
  -        // argument check
  -        if(!request.hasArgument()) {
  -            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  -        }
  -
  -        // get filenames
  -        String fileName = request.getArgument();
  -        fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  -        String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  -        File requestedFile = new File(physicalName);
  -        String args[] = {fileName};
  -
  -        // check permission
  -        if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  -             out.write(mFtpStatus.getResponse(450, request, mUser, args));
  -            return;
  -        }
  -
  -        // now transfer file data
  -        out.write(mFtpStatus.getResponse(150, request, mUser, args));
  +    public void doAPPE(FtpRequest request, FtpWriter out) throws IOException {
  +         
           InputStream is = null;
           OutputStream os = null;
  +        String[] args = null;
  +         
           try {
  -             Socket dataSoc = mDataConnection.getDataSocket();
  -             if (dataSoc == null) {
  -                  out.write(mFtpStatus.getResponse(550, request, mUser, args));
  -                  return;
  -             }
  -
  +            
  +            // reset state variables
  +            resetState();
  +            
  +            // argument check
  +            if(!request.hasArgument()) {
  +                out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +                return ;
  +            }
  +            
  +            // get filenames
  +            String fileName = request.getArgument();
  +            fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  +            String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  +            File requestedFile = new File(physicalName);
  +             args = new String[] {fileName};
  +            
  +            // check file existance
  +            if(!(requestedFile.exists() && requestedFile.isFile())) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                return ;
  +            }
  +            
  +            // check permission
  +            if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  +                out.write(mFtpStatus.getResponse(450, request, mUser, args));
  +                return ;
  +            }
  +            
  +            // now transfer file data
  +            out.write(mFtpStatus.getResponse(150, request, mUser, args));
  +            Socket dataSoc = mDataConnection.getDataSocket();
  +            if(dataSoc == null) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                return ;
  +            }
  +            
               // go to the end of the file
               is = dataSoc.getInputStream();
               RandomAccessFile raf = new RandomAccessFile(requestedFile, "rw");
               raf.seek(raf.length());
  -            os = mUser.getOutputStream( new FileOutputStream(raf.getFD()) );
  -
  +            os = mUser.getOutputStream(new FileOutputStream(raf.getFD()));
  +            
               // receive data from client
               StreamConnector msc = new StreamConnector(is, os);
               msc.setMaxTransferRate(mUser.getMaxUploadRate());
               msc.setObserver(this);
               msc.connect();
  -
  +             
               if(msc.hasException()) {
  -                 out.write(mFtpStatus.getResponse(451, request, mUser, args));
  +                out.write(mFtpStatus.getResponse(451, request, mUser, args));
               }
               else {
  -                 mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
  +                mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
               }
  -
  -             out.write(mFtpStatus.getResponse(226, request, mUser, args));
  +             
  +            out.write(mFtpStatus.getResponse(226, request, mUser, args));
           }
           catch(IOException ex) {
  -             out.write(mFtpStatus.getResponse(425, request, mUser, args));
  +            out.write(mFtpStatus.getResponse(425, request, mUser, args));
           }
           finally {
  -           IoUtils.close(is);
  -           IoUtils.close(os);
  -           mDataConnection.closeDataSocket(); 
  +            IoUtils.close(is);
  +            IoUtils.close(os);
  +            mDataConnection.closeDataSocket();
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>CDUP &lt;CRLF&gt;</code><br>
        *
  @@ -204,22 +215,22 @@
        * syntaxes for naming the parent directory.  The reply codes
        * shall be identical to the reply codes of CWD.
        */
  -     public void doCDUP(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doCDUP(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state variables
           resetState();
  -
  +        
           // change directory
  -        if (mUser.getVirtualDirectory().changeDirectory("..")) {
  -            String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
  +        if(mUser.getVirtualDirectory().changeDirectory("..")) {
  +             String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
               out.write(mFtpStatus.getResponse(200, request, mUser, args));
           }
           else {
  -         	out.write(mFtpStatus.getResponse(431, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(431, request, mUser, null));
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>CWD  &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -229,69 +240,69 @@
        * parameters are similarly unchanged.  The argument is a
        * pathname specifying a directory.
        */
  -     public void doCWD(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doCWD(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state variables
           resetState();
  -
  +        
           // get new directory name
           String dirName = "/";
  -        if (request.hasArgument()) {
  -        	dirName = request.getArgument();
  +        if(request.hasArgument()) {
  +            dirName = request.getArgument();
           }
  -
  +        
           // change directory
  -        if (mUser.getVirtualDirectory().changeDirectory(dirName)) {
  -            String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
  +        if(mUser.getVirtualDirectory().changeDirectory(dirName)) {
  +             String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
               out.write(mFtpStatus.getResponse(200, request, mUser, args));
           }
           else {
  -         	out.write(mFtpStatus.getResponse(431, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(431, request, mUser, null));
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>DELE &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
        * This command causes the file specified in the pathname to be
        * deleted at the server site.
        */
  -     public void doDELE(FtpRequest request, FtpWriter out) throws IOException {
  -
  -       // reset state variables
  -       resetState();
  -
  -       // argument check
  -       if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  -       }
  -
  -       // get filenames
  -       String fileName = request.getArgument();
  -       fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  -       String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  -       File requestedFile = new File(physicalName);
  -       String[] args = {fileName};
  -
  -       // check permission
  -       if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  -           out.write(mFtpStatus.getResponse(450, request, mUser, args));
  -           return;
  -       }
  -
  -       // now delete
  -       if(requestedFile.delete()) {
  -           out.write(mFtpStatus.getResponse(250, request, mUser, args));
  -           mConfig.getStatistics().setDelete(requestedFile, mUser);
  -       }
  -       else {
  -           out.write(mFtpStatus.getResponse(450, request, mUser, args));
  -       }
  +    public void doDELE(FtpRequest request, FtpWriter out) throws IOException {
  +        
  +        // reset state variables
  +        resetState();
  +        
  +        // argument check
  +        if(!request.hasArgument()) {
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
  +        }
  +        
  +        // get filenames
  +        String fileName = request.getArgument();
  +        fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  +        String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  +        File requestedFile = new File(physicalName);
  +        String[] args = {fileName};
  +        
  +        // check permission
  +        if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  +            out.write(mFtpStatus.getResponse(450, request, mUser, args));
  +            return ;
  +        }
  +        
  +        // now delete
  +        if(requestedFile.delete()) {
  +            out.write(mFtpStatus.getResponse(250, request, mUser, args));
  +            mConfig.getStatistics().setDelete(requestedFile, mUser);
  +        }
  +        else {
  +            out.write(mFtpStatus.getResponse(450, request, mUser, args));
  +        }
       }
  -
  -
  +    
  +    
       /**
        * <code>HELP [&lt;SP&gt; <string>] &lt;CRLF&gt;</code><br>
        *
  @@ -301,24 +312,24 @@
        * argument (e.g., any command name) and return more specific
        * information as a response.
        */
  -     public void doHELP(FtpRequest request, FtpWriter out) throws IOException {
  +    public void doHELP(FtpRequest request, FtpWriter out) throws IOException {
           resetState();
  -
  +        
           // print global help
           if(!request.hasArgument()) {
               out.write(mFtpStatus.getResponse(214, null, mUser, null));
  -            return;
  +            return ;
           }
  -
  +        
           // print command specific help
           String ftpCmd = request.getArgument().toUpperCase();
           String args[] = null;
           FtpRequest tempRequest = new FtpRequest(ftpCmd);
           out.write(mFtpStatus.getResponse(214, tempRequest, mUser, args));
  -        return;
  +        return ;
       }
  -
  -
  +    
  +    
       /**
        * <code>LIST [&lt;SP&gt; &lt;pathname&gt;] &lt;CRLF&gt;</code><br>
        *
  @@ -331,75 +342,75 @@
        * default directory.  The data transfer is over the data
        * connection
        */
  -     public void doLIST(FtpRequest request, FtpWriter out) throws IOException {
  -
  -        // reset state variables
  -        resetState();
  -
  -        out.write(mFtpStatus.getResponse(150, request, mUser, null));
  +    public void doLIST(FtpRequest request, FtpWriter out) throws IOException {
  +         
           Writer os = null;
           try {
  -         
  -             // get data connection
  -             Socket dataSoc = mDataConnection.getDataSocket();
  -             if (dataSoc == null) {
  -                  out.write(mFtpStatus.getResponse(550, request, mUser, null));
  -                  return;
  -             }
  -
  -             // transfer listing data
  +            
  +            // reset state variables
  +            resetState();
  +            
  +            // get data connection
  +            out.write(mFtpStatus.getResponse(150, request, mUser, null));
  +            Socket dataSoc = mDataConnection.getDataSocket();
  +            if(dataSoc == null) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +                return ;
  +            }
  +            
  +            // transfer listing data
               os = new OutputStreamWriter(dataSoc.getOutputStream());
  -            if (!mUser.getVirtualDirectory().printList(request.getArgument(), os)) {
  -             	out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            if(!mUser.getVirtualDirectory().printList(request.getArgument(), os)) {
  +                out.write(mFtpStatus.getResponse(501, request, mUser, null));
               }
               else {
                   out.write(mFtpStatus.getResponse(226, request, mUser, null));
               }
           }
           catch(IOException ex) {
  -             out.write(mFtpStatus.getResponse(425, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
               IoUtils.close(os);
               mDataConnection.closeDataSocket();
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>MDTM &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
        * Returns the date and time of when a file was modified.
        */
  -     public void doMDTM(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doMDTM(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state
           resetState();
  -         
  +        
           // argument check
           if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
  -
  +        
           // get filenames
           String fileName = request.getArgument();
           fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
           String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
           File reqFile = new File(physicalName);
  -
  +        
           // now print date
           if(reqFile.exists()) {
  -             SimpleDateFormat fmt = (SimpleDateFormat)DATE_FMT.get();
  +            SimpleDateFormat fmt = (SimpleDateFormat)DATE_FMT.get();
                String args[] = {fmt.format(new Date(reqFile.lastModified()))};
               out.write(mFtpStatus.getResponse(213, request, mUser, args));
           }
           else {
  -             out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(550, request, mUser, null));
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>MKD  &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -408,39 +419,39 @@
        * or as a subdirectory of the current working directory (if
        * the pathname is relative).
        */
  -     public void doMKD(FtpRequest request, FtpWriter out) throws IOException {
  -
  -       // reset state
  -       resetState();
  -
  -       // argument check
  -       if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  -       }
  -
  -       // get filename
  -       String fileName = request.getArgument();
  -       fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  -       String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  -       String args[] = {fileName};
  -
  -       // check permission
  -       if(!mUser.getVirtualDirectory().hasCreatePermission(physicalName, true)) {
  -           out.write(mFtpStatus.getResponse(450, request, mUser, args));
  -           return;
  -       }
  -
  -       // now create directory
  -       if(new File(physicalName).mkdirs()) {
  -           out.write(mFtpStatus.getResponse(250, request, mUser, args));
  -       }
  -       else {
  -           out.write(mFtpStatus.getResponse(450, request, mUser, args));
  -       }
  +    public void doMKD(FtpRequest request, FtpWriter out) throws IOException {
  +        
  +        // reset state
  +        resetState();
  +        
  +        // argument check
  +        if(!request.hasArgument()) {
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
  +        }
  +        
  +        // get filename
  +        String fileName = request.getArgument();
  +        fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  +        String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  +        String args[] = {fileName};
  +        
  +        // check permission
  +        if(!mUser.getVirtualDirectory().hasCreatePermission(physicalName, true)) {
  +            out.write(mFtpStatus.getResponse(450, request, mUser, args));
  +            return ;
  +        }
  +        
  +        // now create directory
  +        if(new File(physicalName).mkdirs()) {
  +            out.write(mFtpStatus.getResponse(250, request, mUser, args));
  +        }
  +        else {
  +            out.write(mFtpStatus.getResponse(450, request, mUser, args));
  +        }
       }
  -
  -
  +    
  +    
       /**
        * <code>MODE &lt;SP&gt; <mode-code> &lt;CRLF&gt;</code><br>
        *
  @@ -448,27 +459,27 @@
        * the data transfer modes described in the Section on
        * Transmission Modes.
        */
  -     public void doMODE(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doMODE(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state
           resetState();
  -
  +        
           // argument check
           if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
  -
  +        
           // set mode
  -        if (mUser.setMode(request.getArgument().charAt(0))) {
  +        if(mUser.setMode(request.getArgument().charAt(0))) {
               out.write(mFtpStatus.getResponse(200, request, mUser, null));
           }
           else {
               out.write(mFtpStatus.getResponse(504, request, mUser, null));
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>NLST [&lt;SP&gt; &lt;pathname&gt;] &lt;CRLF&gt;</code><br>
        *
  @@ -479,41 +490,41 @@
        * will return a stream of names of files and no other
        * information.
        */
  -     public void doNLST(FtpRequest request, FtpWriter out) throws IOException {
  -
  -        // reset state
  -        resetState();
  -
  -        out.write(mFtpStatus.getResponse(150, request, mUser, null));
  +    public void doNLST(FtpRequest request, FtpWriter out) throws IOException {
  +         
           Writer os = null;
           try {
  -         
  -             // get data connection
  -             Socket dataSoc = mDataConnection.getDataSocket();
  -             if (dataSoc == null) {
  -                  out.write(mFtpStatus.getResponse(550, request, mUser, null));
  -                  return;
  -             }
  -
  +            
  +            // reset state
  +            resetState();
  +            
  +            // get data connection
  +            out.write(mFtpStatus.getResponse(150, request, mUser, null));
  +            Socket dataSoc = mDataConnection.getDataSocket();
  +            if(dataSoc == null) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +                return ;
  +            }
  +            
               // print listing data
               os = new OutputStreamWriter(dataSoc.getOutputStream());
  -            if (!mUser.getVirtualDirectory().printNList(request.getArgument(), os)) {
  -             	out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            if(!mUser.getVirtualDirectory().printNList(request.getArgument(), os)) {
  +                out.write(mFtpStatus.getResponse(501, request, mUser, null));
               }
               else {
                   out.write(mFtpStatus.getResponse(226, request, mUser, null));
               }
           }
           catch(IOException ex) {
  -             out.write(mFtpStatus.getResponse(425, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
               IoUtils.close(os);
               mDataConnection.closeDataSocket();
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>NOOP &lt;CRLF&gt;</code><br>
        *
  @@ -521,12 +532,12 @@
        * entered commands. It specifies no action other than that the
        * server send an OK reply.
        */
  -     public void doNOOP(FtpRequest request, FtpWriter out) throws IOException {
  +    public void doNOOP(FtpRequest request, FtpWriter out) throws IOException {
           resetState();
           out.write(mFtpStatus.getResponse(200, request, mUser, null));
       }
  -
  -
  +    
  +    
       /**
        * <code>PASS &lt;SP&gt; <password> &lt;CRLF&gt;</code><br>
        *
  @@ -534,36 +545,36 @@
        * password.  This command must be immediately preceded by the
        * user name command.
        */
  -     public void doPASS(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doPASS(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // set state variables
           if(!mbUser) {
               out.write(mFtpStatus.getResponse(500, request, mUser, null));
               resetState();
  -            return;
  +            return ;
           }
           resetState();
           mbPass = true;
  -
  +        
           // set user password and login
           String pass = request.hasArgument() ? request.getArgument() : "";
           mUser.setPassword(pass);
  -
  -         // login failure - close connection
  +        
  +        // login failure - close connection
            String args[] = {mUser.getName()};
  -         if (mConfig.getConnectionService().login(mUser)) {
  +        if(mConfig.getConnectionService().login(mUser)) {
               out.write(mFtpStatus.getResponse(230, request, mUser, args));
  -         }
  -         else {
  +        }
  +        else {
               out.write(mFtpStatus.getResponse(530, request, mUser, args));
               ConnectionService conService = mConfig.getConnectionService();
  -            if (conService != null) {
  +            if(conService != null) {
                   conService.closeConnection(mUser.getSessionId());
               }
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>PASV &lt;CRLF&gt;</code><br>
        *
  @@ -573,32 +584,32 @@
        * transfer command.  The response to this command includes the
        * host and port address this server is listening on.
        */
  -     public void doPASV(FtpRequest request, FtpWriter out) throws IOException {
  -
  -         // reset state
  -         resetState();
  -         
  -         // set data connection
  -         if (!mDataConnection.setPasvCommand()) {
  -             out.write(mFtpStatus.getResponse(550, request, mUser, null));
  -             return;
  -         }
  -
  -         // get connection info
  +    public void doPASV(FtpRequest request, FtpWriter out) throws IOException {
  +        
  +        // reset state
  +        resetState();
  +        
  +        // set data connection
  +        if(!mDataConnection.setPasvCommand()) {
  +            out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +            return ;
  +        }
  +        
  +        // get connection info
           InetAddress servAddr = mDataConnection.getInetAddress();
           if(servAddr == null) {
  -             servAddr = mConfig.getSelfAddress();
  +            servAddr = mConfig.getSelfAddress();
           }
   
           int servPort = mDataConnection.getPort();
  -
  -         // send connection info to client
  -        String addrStr = servAddr.getHostAddress().replace( '.', ',' ) + ',' + (servPort>>8) + ',' + (servPort&0xFF);
  -        String[] args = {addrStr};
  +        
  +        // send connection info to client
  +        String addrStr = servAddr.getHostAddress().replace('.', ',') + ',' + (servPort >> 8) + ',' + (servPort & 0xFF);
  +         String[] args = {addrStr};
           out.write(mFtpStatus.getResponse(227, request, mUser, args));
       }
  -
  -
  +    
  +    
       /**
        * <code>PORT &lt;SP&gt; <host-port> &lt;CRLF&gt;</code><br>
        *
  @@ -617,35 +628,35 @@
        *
        * where h1 is the high order 8 bits of the internet host address.
        */
  -     public void doPORT(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doPORT(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state variables
           resetState();
  -
  +        
           // argument check
           if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
   
           StringTokenizer st = new StringTokenizer(request.getArgument(), ",");
           if(st.countTokens() != 6) {
               out.write(mFtpStatus.getResponse(510, request, mUser, null));
  -            return;
  +            return ;
           }
  -
  +        
           // get data server
  -        String dataSrvName = st.nextToken() + '.' + st.nextToken() + '.' +
  -                             st.nextToken() + '.' + st.nextToken();
  +         String dataSrvName = st.nextToken() + '.' + st.nextToken() + '.' +
  +                              st.nextToken() + '.' + st.nextToken();
           InetAddress clientAddr = null;
           try {
               clientAddr = InetAddress.getByName(dataSrvName);
           }
           catch(UnknownHostException ex) {
               out.write(mFtpStatus.getResponse(553, request, mUser, null));
  -            return;
  +            return ;
           }
  -
  +        
           // get data server port
           int clientPort = 0;
           try {
  @@ -654,44 +665,44 @@
               clientPort = (hi << 8) | lo;
           }
           catch(NumberFormatException ex) {
  -           out.write(mFtpStatus.getResponse(552, request, mUser, null));
  -           return;
  +            out.write(mFtpStatus.getResponse(552, request, mUser, null));
  +            return ;
           }
            
           mDataConnection.setPortCommand(clientAddr, clientPort);
           out.write(mFtpStatus.getResponse(200, request, mUser, null));
       }
  -
  -
  +    
  +    
       /**
        * <code>PWD  &lt;CRLF&gt;</code><br>
        *
        * This command causes the name of the current working
        * directory to be returned in the reply.
        */
  -     public void doPWD(FtpRequest request, FtpWriter out) throws IOException {
  +    public void doPWD(FtpRequest request, FtpWriter out) throws IOException {
           resetState();
  -        String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
  +         String args[] = {mUser.getVirtualDirectory().getCurrentDirectory()};
           out.write(mFtpStatus.getResponse(257, request, mUser, args));
       }
  -
  -
  +    
  +    
       /**
        * <code>QUIT &lt;CRLF&gt;</code><br>
        *
        * This command terminates a USER and if file transfer is not
        * in progress, the server closes the control connection.
        */
  -     public void doQUIT(FtpRequest request, FtpWriter out) throws IOException {
  +    public void doQUIT(FtpRequest request, FtpWriter out) throws IOException {
           resetState();
           out.write(mFtpStatus.getResponse(221, request, mUser, null));
           ConnectionService conService = mConfig.getConnectionService();
  -        if (conService != null) {
  +        if(conService != null) {
               conService.closeConnection(mUser.getSessionId());
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>REST &lt;SP&gt; <marker> &lt;CRLF&gt;</code><br>
        *
  @@ -702,34 +713,34 @@
        * by the appropriate FTP service command which shall cause
        * file transfer to resume.
        */
  -     public void doREST(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doREST(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // argument check
           if(!request.hasArgument()) {
               out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            return ;
           }
  -
  +       
           resetState();
           mlSkipLen = 0;
           String skipNum = request.getArgument();
           try {
  -             mlSkipLen = Long.parseLong(skipNum);
  +            mlSkipLen = Long.parseLong(skipNum);
           }
           catch(NumberFormatException ex) {
  -             out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -            return;
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
           if(mlSkipLen < 0) {
               mlSkipLen = 0;
  -             out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -            return;
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
           mbReset = true;
           out.write(mFtpStatus.getResponse(350, request, mUser, null));
       }
  -
  -
  +    
  +    
       /**
        * <code>RETR &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -738,66 +749,75 @@
        * at the other end of the data connection.  The status and
        * contents of the file at the server site shall be unaffected.
        */
  -     public void doRETR(FtpRequest request, FtpWriter out) throws IOException {
  -
  -        // set state variables
  -        long skipLen = (mbReset) ? mlSkipLen : 0;
  -        resetState();
  -
  -        // argument check
  -        if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  -        }
  -
  -        // get filename
  -        String fileName = request.getArgument();
  -        fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  -        String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  -        File requestedFile = new File(physicalName);
  -        String args[] = {fileName};
  -
  -        // check permission
  -        if(!mUser.getVirtualDirectory().hasReadPermission(physicalName, true)) {
  -            out.write(mFtpStatus.getResponse(550, request, mUser, args));
  -            return;
  -        }
  -
  -        // now transfer file data
  -        out.write(mFtpStatus.getResponse(150, request, mUser, null));
  +    public void doRETR(FtpRequest request, FtpWriter out) throws IOException {
  +        
           InputStream is = null;
           OutputStream os = null;
           try {
  -             Socket dataSoc = mDataConnection.getDataSocket();
  -             if (dataSoc == null) {
  -                  out.write(mFtpStatus.getResponse(550, request, mUser, args));
  -                  return;
  -             }
  -
  +            
  +            // set state variables
  +            long skipLen = (mbReset) ? mlSkipLen : 0;
  +            resetState();
  +            
  +            // argument check
  +            if(!request.hasArgument()) {
  +                out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +                return ;
  +            }
  +            
  +            // get filename
  +            String fileName = request.getArgument();
  +            fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  +            String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  +            File requestedFile = new File(physicalName);
  +             String args[] = {fileName};
  +            
  +            // check file existance
  +            if(!(requestedFile.exists() && requestedFile.isFile())) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                return ;
  +            }
  +            
  +            // check permission
  +            if(!mUser.getVirtualDirectory().hasReadPermission(physicalName, true)) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                return ;
  +            }
  +            
  +            // now transfer file data
  +            out.write(mFtpStatus.getResponse(150, request, mUser, null));
  +            Socket dataSoc = mDataConnection.getDataSocket();
  +            if(dataSoc == null) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                return ;
  +            }
  +             
               os = mUser.getOutputStream(dataSoc.getOutputStream());
  -
  -             // move to the appropriate offset
  +            
  +            // move to the appropriate offset
               RandomAccessFile raf = new RandomAccessFile(requestedFile, "r");
               raf.seek(skipLen);
               is = new FileInputStream(raf.getFD());
  -
  -             // send file data to client
  +            
  +              
  +            // send file data to client
               StreamConnector msc = new StreamConnector(is, os);
               msc.setMaxTransferRate(mUser.getMaxDownloadRate());
               msc.setObserver(this);
               msc.connect();
  +             
               if(msc.hasException()) {
                   out.write(mFtpStatus.getResponse(451, request, mUser, args));
  -                return;
  +                return ;
               }
               else {
  -                 mConfig.getStatistics().setDownload(requestedFile, mUser, msc.getTransferredSize());
  +                mConfig.getStatistics().setDownload(requestedFile, mUser, msc.getTransferredSize());
               }
  -
  +            
               out.write(mFtpStatus.getResponse(226, request, mUser, null));
           }
           catch(IOException ex) {
  -             out.write(mFtpStatus.getResponse(425, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
               IoUtils.close(is);
  @@ -805,8 +825,8 @@
               mDataConnection.closeDataSocket();
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>RMD  &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -815,40 +835,40 @@
        * or as a subdirectory of the current working directory (if
        * the pathname is relative).
        */
  -     public void doRMD(FtpRequest request, FtpWriter out) throws IOException {
  -
  -       // reset state variables
  -       resetState();
  -
  -       // argument check
  -       if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  -       }
  -
  -       // get file names
  -       String fileName = request.getArgument();
  -       fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  -       String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  -       File requestedFile = new File(physicalName);
  -       String args[] = {fileName};
  -
  -       // check permission
  -       if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  -           out.write(mFtpStatus.getResponse(450, request, mUser, args));
  -           return;
  -       }
  -
  -       // now delete
  -       if(requestedFile.delete()) {
  -           out.write(mFtpStatus.getResponse(250, request, mUser, args));
  -       }
  -       else {
  -           out.write(mFtpStatus.getResponse(450, request, mUser, args));
  -       }
  +    public void doRMD(FtpRequest request, FtpWriter out) throws IOException {
  +        
  +        // reset state variables
  +        resetState();
  +        
  +        // argument check
  +        if(!request.hasArgument()) {
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
  +        }
  +        
  +        // get file names
  +        String fileName = request.getArgument();
  +        fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  +        String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  +        File requestedFile = new File(physicalName);
  +        String args[] = {fileName};
  +        
  +        // check permission
  +        if(!mUser.getVirtualDirectory().hasWritePermission(physicalName, true)) {
  +            out.write(mFtpStatus.getResponse(450, request, mUser, args));
  +            return ;
  +        }
  +        
  +        // now delete
  +        if(requestedFile.delete()) {
  +            out.write(mFtpStatus.getResponse(250, request, mUser, args));
  +        }
  +        else {
  +            out.write(mFtpStatus.getResponse(450, request, mUser, args));
  +        }
       }
  -
  -
  +    
  +    
       /**
        * <code>RNFR &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -856,30 +876,30 @@
        * to be renamed.  This command must be immediately followed by
        * a "rename to" command specifying the new file pathname.
        */
  -     public void doRNFR(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doRNFR(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state variable
           resetState();
  -
  +        
           // argument check
           if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
  -
  +        
           // set state variable
           mbRenFr = true;
  -
  +        
           // get filename
           String fileName = request.getArgument();
           fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
           mstRenFr = mUser.getVirtualDirectory().getPhysicalName(fileName);
  -        String args[] = {fileName};
  -
  +         String args[] = {fileName};
  +         
           out.write(mFtpStatus.getResponse(350, request, mUser, args));
       }
  -
  -
  +    
  +    
       /**
        * <code>RNTO &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -888,22 +908,22 @@
        * command.  Together the two commands cause a file to be
        * renamed.
        */
  -     public void doRNTO(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doRNTO(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // argument check
           if(!request.hasArgument()) {
  -           resetState();
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            resetState();
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
  -
  +        
           // set state variables
           if((!mbRenFr) || (mstRenFr == null)) {
  -             resetState();
  -             out.write(mFtpStatus.getResponse(100, request, mUser, null));
  -             return;
  +            resetState();
  +            out.write(mFtpStatus.getResponse(100, request, mUser, null));
  +            return ;
           }
  -
  +        
           // get filenames
           String fromFileStr = mUser.getVirtualDirectory().getVirtualName(mstRenFr);
           String toFileStr = request.getArgument();
  @@ -911,26 +931,26 @@
           String physicalToFileStr = mUser.getVirtualDirectory().getPhysicalName(toFileStr);
           File fromFile = new File(mstRenFr);
           File toFile = new File(physicalToFileStr);
  -        String args[] = {fromFileStr, toFileStr};
  -
  +         String args[] = {fromFileStr, toFileStr};
  +         
           resetState();
  -
  +        
           // check permission
           if(!mUser.getVirtualDirectory().hasCreatePermission(physicalToFileStr, true)) {
  -           out.write(mFtpStatus.getResponse(553, request, mUser, null));
  -           return;
  +            out.write(mFtpStatus.getResponse(553, request, mUser, null));
  +            return ;
           }
  -
  +        
           // now rename
           if(fromFile.renameTo(toFile)) {
  -             out.write(mFtpStatus.getResponse(250, request, mUser, args));
  +            out.write(mFtpStatus.getResponse(250, request, mUser, args));
           }
           else {
  -             out.write(mFtpStatus.getResponse(553, request, mUser, args));
  +            out.write(mFtpStatus.getResponse(553, request, mUser, args));
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>SITE &lt;SP&gt; <string> &lt;CRLF&gt;</code><br>
        *
  @@ -939,67 +959,67 @@
        * but not sufficiently universal to be included as commands in
        * the protocol.
        */
  -     public void doSITE(FtpRequest request, FtpWriter out) throws IOException {
  -         resetState();
  -         SiteCommandHandler siteCmd = new SiteCommandHandler( mConfig, mUser );
  -         out.write( siteCmd.getResponse(request) );
  +    public void doSITE(FtpRequest request, FtpWriter out) throws IOException {
  +        resetState();
  +        SiteCommandHandler siteCmd = new SiteCommandHandler(mConfig, mUser);
  +        out.write(siteCmd.getResponse(request));
       }
  -
  -
  +    
  +    
       /**
        * <code>SIZE &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
        * Returns the size of the file in bytes.
        */
  -     public void doSIZE(FtpRequest request, FtpWriter out) throws IOException {
  -
  -         // reset state variables
  -         resetState();
  -         
  +    public void doSIZE(FtpRequest request, FtpWriter out) throws IOException {
  +        
  +        // reset state variables
  +        resetState();
  +        
           // argument check
           if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
  -
  +        
           // get filenames
           String fileName = request.getArgument();
           fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
           String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
           File reqFile = new File(physicalName);
  -
  +        
           // print file size
           if(reqFile.exists()) {
  -            String args[] = {String.valueOf(reqFile.length())};
  +             String args[] = {String.valueOf(reqFile.length())};             
               out.write(mFtpStatus.getResponse(213, request, mUser, args));
           }
           else {
               out.write(mFtpStatus.getResponse(550, request, mUser, null));
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>STAT [&lt;SP&gt; &lt;pathname&gt;] &lt;CRLF&gt;</code><br>
        *
        * This command shall cause a status response to be sent over
        * the control connection in the form of a reply.
        */
  -     public void doSTAT(FtpRequest request, FtpWriter out) throws IOException {
  -         
  -         // reset state variables
  -         resetState();
  +    public void doSTAT(FtpRequest request, FtpWriter out) throws IOException {
  +        
  +        // reset state variables
  +        resetState();
           
  -         // write the status info
  -        String args[] = {
  +        // write the status info
  +        String args[] =  {
               mConfig.getSelfAddress().getHostAddress(),
               mControlSocket.getInetAddress().getHostAddress(),
               mUser.getName()
           };
           out.write(mFtpStatus.getResponse(211, request, mUser, args));
       }
  -
  -
  +    
  +    
       /**
        * <code>STOR &lt;SP&gt; &lt;pathname&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -1011,50 +1031,51 @@
        * created at the server site if the file specified in the
        * pathname does not already exist.
        */
  -     public void doSTOR(FtpRequest request, FtpWriter out) throws IOException {
  -
  -        // set state variables
  -        long skipLen = (mbReset) ? mlSkipLen : 0;
  -        resetState();
  -
  -        // argument check
  -        if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  -        }
  -
  -        // get filenames
  -        String fileName = request.getArgument();
  -        fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  -        String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  -        File requestedFile = new File(physicalName);
  +    public void doSTOR(FtpRequest request, FtpWriter out) throws IOException {
   
  -        // get permission
  -        if(!mUser.getVirtualDirectory().hasCreatePermission(physicalName, true)) {
  -            out.write(mFtpStatus.getResponse(550, request, mUser, null));
  -            return;
  -        }
  -
  -        // now transfer file data
  -        out.write(mFtpStatus.getResponse(150, request, mUser, null));
           InputStream is = null;
           OutputStream os = null;
           try {
  -             
  -             // get data connection
  +            
  +            // set state variables
  +            long skipLen = (mbReset) ? mlSkipLen : 0;
  +            resetState();
  +            
  +            // argument check
  +            if(!request.hasArgument()) {
  +                out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +                return ;
  +            }
  +            
  +            // get filenames
  +            String fileName = request.getArgument();
  +            fileName = mUser.getVirtualDirectory().getAbsoluteName(fileName);
  +            String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  +            File requestedFile = new File(physicalName);
  +            
  +            // get permission
  +            if(!mUser.getVirtualDirectory().hasCreatePermission(physicalName, true)) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +                return ;
  +            }
  +            
  +            // now transfer file data
  +            out.write(mFtpStatus.getResponse(150, request, mUser, null));
  +            
  +            // get data connection
               Socket dataSoc = mDataConnection.getDataSocket();
  -            if (dataSoc == null) {
  +            if(dataSoc == null) {
                   out.write(mFtpStatus.getResponse(550, request, mUser, null));
  -                return;
  +                return ;
               }
               is = dataSoc.getInputStream();
  -
  -             // go to the appropriate offset
  +            
  +            // go to the appropriate offset
               RandomAccessFile raf = new RandomAccessFile(requestedFile, "rw");
               raf.setLength(skipLen);
               raf.seek(skipLen);
  -            os = mUser.getOutputStream( new FileOutputStream(raf.getFD()) );
  -
  +            os = mUser.getOutputStream(new FileOutputStream(raf.getFD()));
  +            
               // get data from client
               StreamConnector msc = new StreamConnector(is, os);
               msc.setMaxTransferRate(mUser.getMaxUploadRate());
  @@ -1062,12 +1083,12 @@
               msc.connect();
               if(msc.hasException()) {
                   out.write(mFtpStatus.getResponse(451, request, mUser, null));
  -                return;
  +                return ;
               }
               else {
                   mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
               }
  -
  +             
               out.write(mFtpStatus.getResponse(226, request, mUser, null));
           }
           catch(IOException ex) {
  @@ -1079,8 +1100,8 @@
               mDataConnection.closeDataSocket();
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>STOU &lt;CRLF&gt;</code><br>
        *
  @@ -1089,140 +1110,138 @@
        * unique to that directory.  The 250 Transfer Started response
        * must include the name generated.
        */
  -     public void doSTOU(FtpRequest request, FtpWriter out) throws IOException {
  -
  -        // reset state variables
  -        resetState();
  -
  -        // get filenames
  -        String fileName = mUser.getVirtualDirectory().getAbsoluteName("ftp.dat");
  -        String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  -        File requestedFile = new File(physicalName);
  -        requestedFile = IoUtils.getUniqueFile(requestedFile);
  -        fileName = mUser.getVirtualDirectory().getVirtualName(requestedFile.getAbsolutePath());
  -        String args[] = {fileName};
  -
  -        // check permission
  -        if(!mUser.getVirtualDirectory().hasCreatePermission(fileName, false)) {
  -            out.write(mFtpStatus.getResponse(550, request, mUser, null));
  -            return;
  -        }
  +    public void doSTOU(FtpRequest request, FtpWriter out) throws IOException {
   
  -        // now transfer file data
  -        out.write(mFtpStatus.getResponse(150, request, mUser, null));
           InputStream is = null;
           OutputStream os = null;
           try {
  -         
  -             // get data connection
  -             Socket dataSoc = mDataConnection.getDataSocket();
  -             if (dataSoc == null) {
  -                  out.write(mFtpStatus.getResponse(550, request, mUser, args));
  -                  return;
  -             }
  -
  -
  +            
  +            // reset state variables
  +            resetState();
  +            
  +            // get filenames
  +            String fileName = mUser.getVirtualDirectory().getAbsoluteName("ftp.dat");
  +            String physicalName = mUser.getVirtualDirectory().getPhysicalName(fileName);
  +            File requestedFile = new File(physicalName);
  +            requestedFile = IoUtils.getUniqueFile(requestedFile);
  +            fileName = mUser.getVirtualDirectory().getVirtualName(requestedFile.getAbsolutePath());
  +             String args[] = {fileName};
  +            
  +            // check permission
  +            if(!mUser.getVirtualDirectory().hasCreatePermission(fileName, false)) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, null));
  +                return ;
  +            }
  +            
  +            // now transfer file data
  +            out.write(mFtpStatus.getResponse(150, request, mUser, null));
  +            Socket dataSoc = mDataConnection.getDataSocket();
  +            if(dataSoc == null) {
  +                out.write(mFtpStatus.getResponse(550, request, mUser, args));
  +                return ;
  +            }
  +            
               // receive data from client
               is = dataSoc.getInputStream();
  -            os = mUser.getOutputStream( new FileOutputStream(requestedFile) );
  -
  +            os = mUser.getOutputStream(new FileOutputStream(requestedFile));
  +             
               StreamConnector msc = new StreamConnector(is, os);
               msc.setMaxTransferRate(mUser.getMaxUploadRate());
               msc.setObserver(this);
               msc.connect();
               if(msc.hasException()) {
                   out.write(mFtpStatus.getResponse(451, request, mUser, null));
  -                return;
  +                return ;
               }
               else {
                   mConfig.getStatistics().setUpload(requestedFile, mUser, msc.getTransferredSize());
               }
  -
  -             out.write(mFtpStatus.getResponse(226, request, mUser, null));
  -             mDataConnection.closeDataSocket();
  -             out.write(mFtpStatus.getResponse(250, request, mUser, args));
  +             
  +            out.write(mFtpStatus.getResponse(226, request, mUser, null));
  +            mDataConnection.closeDataSocket();
  +            out.write(mFtpStatus.getResponse(250, request, mUser, args));
           }
           catch(IOException ex) {
  -             out.write(mFtpStatus.getResponse(425, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(425, request, mUser, null));
           }
           finally {
  -           IoUtils.close(is);
  -           IoUtils.close(os);
  -           mDataConnection.closeDataSocket(); 
  +            IoUtils.close(is);
  +            IoUtils.close(os);
  +            mDataConnection.closeDataSocket();
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>STRU &lt;SP&gt; &lt;structure-code&gt; &lt;CRLF&gt;</code><br>
        *
        * The argument is a single Telnet character code specifying
        * file structure.
        */
  -     public void doSTRU(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doSTRU(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state variables
           resetState();
  -
  +        
           // argument check
           if(!request.hasArgument()) {
  -           out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            out.write(mFtpStatus.getResponse(501, request, mUser, null));
  +            return ;
           }
  -
  -         // set structure
  -        if (mUser.setStructure(request.getArgument().charAt(0))) {
  +        
  +        // set structure
  +        if(mUser.setStructure(request.getArgument().charAt(0))) {
               out.write(mFtpStatus.getResponse(200, request, mUser, null));
           }
           else {
  -         	out.write(mFtpStatus.getResponse(504, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(504, request, mUser, null));
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>SYST &lt;CRLF&gt;</code><br>
        *
        * This command is used to find out the type of operating
        * system at the server.
        */
  -     public void doSYST(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doSYST(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state variables
           resetState();
  -
  +        
           // and print server system info 
  -        String args[] = {mConfig.getSystemName()};
  +         String args[] = {mConfig.getSystemName()};
           out.write(mFtpStatus.getResponse(215, request, mUser, args));
       }
  -
  -
  +    
  +    
       /**
        * <code>TYPE &lt;SP&gt; &lt;type-code&gt; &lt;CRLF&gt;</code><br>
        *
        * The argument specifies the representation type.
        */
  -     public void doTYPE(FtpRequest request, FtpWriter out) throws IOException {
  -
  +    public void doTYPE(FtpRequest request, FtpWriter out) throws IOException {
  +        
           // reset state variables
           resetState();
  -
  +        
           // get type from argument
           char type = 'A';
  -        if (request.hasArgument()){
  -        	type = request.getArgument().charAt(0);
  +        if(request.hasArgument()) {
  +            type = request.getArgument().charAt(0);
           }
  -
  +        
           // set it
  -        if (mUser.setType(type)) {
  +        if(mUser.setType(type)) {
               out.write(mFtpStatus.getResponse(200, request, mUser, null));
           }
           else {
  -         	out.write(mFtpStatus.getResponse(504, request, mUser, null));
  +            out.write(mFtpStatus.getResponse(504, request, mUser, null));
           }
       }
  -
  -
  +    
  +    
       /**
        * <code>USER &lt;SP&gt; &lt;username&gt; &lt;CRLF&gt;</code><br>
        *
  @@ -1232,48 +1251,48 @@
        * normally be the first command transmitted by the user after
        * the control connections are made.
        */
  -     public void doUSER(FtpRequest request, FtpWriter out) throws IOException {
  -
  -         // reset state variables
  +    public void doUSER(FtpRequest request, FtpWriter out) throws IOException {
  +        
  +        // reset state variables
           resetState();
  -
  +        
           // argument check
           if(!request.hasArgument()) {
               out.write(mFtpStatus.getResponse(501, request, mUser, null));
  -           return;
  +            return ;
           }
  -
  +        
           // check user login status
           mbUser = true;
           if(mUser.hasLoggedIn()) {
               if(mUser.getName().equals(request.getArgument())) {
                   out.write(mFtpStatus.getResponse(230, request, mUser, null));
  -                return;
  +                return ;
               }
               else {
                   mConfig.getConnectionService().closeConnection(mUser.getSessionId());
               }
           }
  -
  +        
           // set user name and send appropriate message
           mUser.setName(request.getArgument());
           if(mUser.getIsAnonymous()) {
  -             if(mConfig.isAnonymousLoginAllowed()) {
  -                 FtpRequest anoRequest = new FtpRequest(mUser.getName());
  -                 out.write(mFtpStatus.getResponse(331, anoRequest, mUser, null));
  +            if(mConfig.isAnonymousLoginAllowed()) {
  +                FtpRequest anoRequest = new FtpRequest(mUser.getName());
  +                out.write(mFtpStatus.getResponse(331, anoRequest, mUser, null));
               }
               else {
  -                 out.write(mFtpStatus.getResponse(530, request, mUser, null));
  -                 ConnectionService conService = mConfig.getConnectionService();
  -                 if (conService != null) {
  +                out.write(mFtpStatus.getResponse(530, request, mUser, null));
  +                ConnectionService conService = mConfig.getConnectionService();
  +                if(conService != null) {
                       conService.closeConnection(mUser.getSessionId());
  -                 }
  +                }
               }
           }
           else {
  -             out.write(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