You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/02/07 03:55:25 UTC

svn commit: r1241337 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/ftp/FTPClient.java

Author: sebb
Date: Tue Feb  7 02:55:24 2012
New Revision: 1241337

URL: http://svn.apache.org/viewvc?rev=1241337&view=rev
Log:
NET-440 Allow user to provide default value in case SYST command fails.

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1241337&r1=1241336&r2=1241337&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Tue Feb  7 02:55:24 2012
@@ -65,6 +65,9 @@ The <action> type attribute can be add,u
 This release fixes a few bugs and adds some new functionality (see below).
   It is binary compatible with previous releases
         ">
+            <action issue="NET-440" dev="sebb" type="add">
+            Allow user to provide default value in case SYST command fails.
+            </action>
             <action issue="NET-438" dev="sebb" type="fix" due-to="Norman Maurer">
             POP3Client.capa() should call POP3Client.getAdditionalReply()
             </action>

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=1241337&r1=1241336&r2=1241337&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java Tue Feb  7 02:55:24 2012
@@ -281,6 +281,14 @@ implements Configurable
     public static final String FTP_SYSTEM_TYPE = "org.apache.commons.net.ftp.systemType";
 
     /**
+     * The system property ({@value}) which can be used as the default system type.<br/>
+     * If defined, the value will be used if the SYST command fails.
+     *
+     * @since 3.1
+     */
+    public static final String FTP_SYSTEM_TYPE_DEFAULT = "org.apache.commons.net.ftp.systemType.default";
+
+    /**
      * The name of an optional systemType properties file ({@value}), which is loaded
      * using {@link Class#getResourceAsStream(String)}.<br/>
      * The entries are the systemType (as determined by {@link FTPClient#getSystemType})
@@ -2492,6 +2500,8 @@ implements Configurable
      * FTP server.  FTPClient will remember the value and return the
      * cached value until a call to disconnect.
      * <p>
+     * If the SYST command fails, and the system property
+     * {@link #FTP_SYSTEM_TYPE_DEFAULT} is defined, then this is used instead.
      * @return The system type obtained from the server. Never null.
      * @exception FTPConnectionClosedException
      *      If the FTP server prematurely closes the connection as a result
@@ -2499,7 +2509,8 @@ implements Configurable
      *      to send FTP reply code 421.  This exception may be caught either
      *      as an IOException or independently as itself.
      * @exception IOException  If an I/O error occurs while either sending a
-     *  command to the server or receiving a reply from the server.
+     *  command to the server or receiving a reply from the server (and the default
+     *  system type property is not defined)
      *  @since 2.2
      ***/
     public String getSystemType() throws IOException
@@ -2513,7 +2524,13 @@ implements Configurable
                 // Assume that response is not empty here (cannot be null)
                 __systemName = _replyLines.get(_replyLines.size() - 1).substring(4);
             } else {
-                throw new IOException("Unable to determine system type - response: " + getReplyString());
+                // Check if the user has provided a default for when the SYST command fails
+                String systDefault = System.getProperty(FTP_SYSTEM_TYPE_DEFAULT);
+                if (systDefault != null) {
+                    __systemName = systDefault;
+                } else {
+                    throw new IOException("Unable to determine system type - response: " + getReplyString());
+                }
             }
         }
         return __systemName;