commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwins...@apache.org
Subject svn commit: r628581 - /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
Date Mon, 18 Feb 2008 00:07:55 GMT
Author: rwinston
Date: Sun Feb 17 16:07:54 2008
New Revision: 628581

URL: http://svn.apache.org/viewvc?rev=628581&view=rev
Log:
Add fix for PASV port specifiers

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=628581&r1=628580&r2=628581&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
Sun Feb 17 16:07:54 2008
@@ -285,6 +285,13 @@
     
     private FTPClientConfig __configuration;
 
+    private static String __parms = "\\d{1,3},\\d{1,3},\\d{1,3},\\d{1,3},\\d{1,3},\\d{1,3}";
+    private static java.util.regex.Pattern __parms_pat;
+
+    static {
+       __parms_pat = java.util.regex.Pattern.compile(__parms);
+    }
+
     /***
      * Default FTPClient constructor.  Creates a new FTPClient instance
      * with the data connection mode set to
@@ -334,37 +341,21 @@
     private void __parsePassiveModeReply(String reply)
     throws MalformedServerReplyException
     {
-        int i, index, lastIndex;
-        String octet1, octet2;
-        StringBuffer host;
-
-        reply = reply.substring(reply.indexOf('(') + 1,
-                                reply.indexOf(')')).trim();
-
-        host = new StringBuffer(24);
-        lastIndex = 0;
-        index = reply.indexOf(',');
-        host.append(reply.substring(lastIndex, index));
-
-        for (i = 0; i < 3; i++)
-        {
-            host.append('.');
-            lastIndex = index + 1;
-            index = reply.indexOf(',', lastIndex);
-            host.append(reply.substring(lastIndex, index));
+        java.util.regex.Matcher m = __parms_pat.matcher(reply);
+        if (!m.find()) {
+            throw new MalformedServerReplyException(
+                "Could not parse passive host information.\nServer Reply: " + reply);
         }
+        reply = m.group();
+        String parts[] = m.group().split(",");
+        
+        __passiveHost = parts[0] + '.' + parts[1] + '.' + parts[2] + '.' + parts[3];
 
-        lastIndex = index + 1;
-        index = reply.indexOf(',', lastIndex);
-
-        octet1 = reply.substring(lastIndex, index);
-        octet2 = reply.substring(index + 1);
-
-        // index and lastIndex now used as temporaries
         try
         {
-            index = Integer.parseInt(octet1);
-            lastIndex = Integer.parseInt(octet2);
+            int oct1 = Integer.parseInt(parts[4]);
+            int oct2 = Integer.parseInt(parts[5]);
+            __passivePort = (oct1 << 8) | oct2;
         }
         catch (NumberFormatException e)
         {
@@ -372,11 +363,6 @@
                 "Could not parse passive host information.\nServer Reply: " + reply);
         }
 
-        index <<= 8;
-        index |= lastIndex;
-
-        __passiveHost = host.toString();
-        __passivePort = index;
     }
 
     private boolean __storeFile(int command, String remote, InputStream local)



Mime
View raw message