Author: ngn
Date: Thu Sep 11 13:55:06 2008
New Revision: 694474

URL: http://svn.apache.org/viewvc?rev=694474&view=rev
Log:
Fixes issue where the data connection is not closed if QUIT is called before a 
data transfer command is sent (FTPSERVER-177)

Modified:
    
mina/ftpserver/trunk/core/src/examples/java/org/apache/ftpserver/examples/EmbeddingFtpServer.java
    
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/QUIT.java
    
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvTest.java
    
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/test/TestUtil.java
    
mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DataConnectionFactory.java

Modified: 
mina/ftpserver/trunk/core/src/examples/java/org/apache/ftpserver/examples/EmbeddingFtpServer.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/examples/java/org/apache/ftpserver/examples/EmbeddingFtpServer.java?rev=694474&r1=694473&r2=694474&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/examples/java/org/apache/ftpserver/examples/EmbeddingFtpServer.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/examples/java/org/apache/ftpserver/examples/EmbeddingFtpServer.java
 Thu Sep 11 13:55:06 2008
@@ -22,7 +22,7 @@
 import java.io.File;
 
 import org.apache.ftpserver.FtpServer;
-import org.apache.ftpserver.ssl.DefaultSslConfiguration;
+import org.apache.ftpserver.ssl.impl.DefaultSslConfiguration;
 
 public class EmbeddingFtpServer {
 

Modified: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/QUIT.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/QUIT.java?rev=694474&r1=694473&r2=694474&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/QUIT.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/QUIT.java
 Thu Sep 11 13:55:06 2008
@@ -50,6 +50,7 @@
                 FtpReply.REPLY_221_CLOSING_CONTROL_CONNECTION, "QUIT", null));
 
         session.closeOnFlush().awaitUninterruptibly(10000);
+        session.getDataConnection().closeDataConnection();
     }
 
 }

Modified: 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvTest.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvTest.java?rev=694474&r1=694473&r2=694474&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvTest.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PasvTest.java
 Thu Sep 11 13:55:06 2008
@@ -20,6 +20,9 @@
 package org.apache.ftpserver.clienttests;
 
 import org.apache.commons.net.ftp.FTPConnectionClosedException;
+import org.apache.ftpserver.FtpServer;
+import org.apache.ftpserver.interfaces.DataConnectionConfiguration;
+import org.apache.ftpserver.listener.Listener;
 import org.apache.ftpserver.test.TestUtil;
 
 /**
@@ -34,6 +37,31 @@
         return false;
     }
 
+    @Override
+    protected FtpServer createServer() throws Exception {
+        FtpServer server = super.createServer();
+        
+        Listener l = server.getServerContext().getListener("default");
+        DataConnectionConfiguration dcc = l.getDataConnectionConfiguration();
+        
+        int passivePort = TestUtil.findFreePort(12444);
+        
+        dcc.setPassivePorts(passivePort + "-" + passivePort);
+        
+        return server;
+    }
+
+    public void testMultiplePasv() throws Exception {
+        for (int i = 0; i < 5; i++) {
+            client.connect("localhost", port);
+            client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+            client.pasv();
+
+            client.quit();
+            client.disconnect();
+        }
+    }
+    
     /**
      * This tests that the correct IP is returned, that is the IP that the
      * client has connected to.

Modified: 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/test/TestUtil.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/test/TestUtil.java?rev=694474&r1=694473&r2=694474&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/test/TestUtil.java 
(original)
+++ 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/test/TestUtil.java 
Thu Sep 11 13:55:06 2008
@@ -56,22 +56,34 @@
     }
 
     /**
-     * Attempts to find a free port or fallback to a default
+     * Attempts to find a free port
      * 
      * @throws IOException
      * 
      * @throws IOException
      */
     public static int findFreePort() throws IOException {
+        return findFreePort(DEFAULT_PORT);
+    }
+    
+    /**
+     * Attempts to find a free port
+     * @param initPort The first port to try, before resolving to 
+     *   brute force searching
+     * @throws IOException
+     * 
+     * @throws IOException
+     */
+    public static int findFreePort(int initPort) throws IOException {
         int port = -1;
         ServerSocket tmpSocket = null;
         // first try the default port
         try {
-            tmpSocket = new ServerSocket(DEFAULT_PORT);
+            tmpSocket = new ServerSocket(initPort);
 
-            port = DEFAULT_PORT;
+            port = initPort;
         } catch (IOException e) {
-            System.out.println("Failed to use default port");
+            System.out.println("Failed to use specified port");
             // didn't work, try to find one dynamically
             try {
                 int attempts = 0;

Modified: 
mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DataConnectionFactory.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DataConnectionFactory.java?rev=694474&r1=694473&r2=694474&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DataConnectionFactory.java
 (original)
+++ 
mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/DataConnectionFactory.java
 Thu Sep 11 13:55:06 2008
@@ -44,7 +44,8 @@
     boolean isSecure();
 
     /**
-     * Close data socket.
+     * Close data socket. If no open data connection exists,
+     * this will silently ignore the call.
      */
     void closeDataConnection();
 


Reply via email to