You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rw...@apache.org on 2009/02/08 19:51:49 UTC

svn commit: r742140 - in /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp: FTP.java FTPClient.java FTPCommand.java FTPSClient.java

Author: rwinston
Date: Sun Feb  8 18:51:49 2009
New Revision: 742140

URL: http://svn.apache.org/viewvc?rev=742140&view=rev
Log:
Add FEAT command; clean up

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

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java?rev=742140&r1=742139&r2=742140&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java Sun Feb  8 18:51:49 2009
@@ -503,9 +503,7 @@
         {
             return false;
         }
-
         return socket.isConnected();
-        
     }
 
     /***
@@ -1107,6 +1105,18 @@
     {
         return sendCommand(FTPCommand.ALLO, Integer.toString(bytes));
     }
+    
+    /**
+     * A convenience method to send the FTP FEAT command to the server, receive the reply,
+     * and return the reply code.
+     * @return The reply code received by the server
+     * @throws IOException  If an I/O error occurs while either sending the
+     *      command or receiving the server reply.
+     */
+    public int feat() throws IOException
+    {
+    	return sendCommand(FTPCommand.FEAT);
+    }
 
     /***
      * A convenience method to send the FTP ALLO command to the server,

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=742140&r1=742139&r2=742140&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  8 18:51:49 2009
@@ -1609,6 +1609,26 @@
     {
         return FTPReply.isPositiveCompletion(allo(bytes));
     }
+    
+    /**
+     * Query the server for supported features. The server may reply with a list of server-supported exensions.
+     * For example, a typical client-server interaction might be (from RFC 	2289):
+     * <pre>
+        C> feat
+        S> 211-Extensions supported:
+        S>  MLST size*;create;modify*;perm;media-type
+        S>  SIZE
+        S>  COMPRESSION
+        S>  MDTM
+        S> 211 END
+     * </pre>
+     * @see <a href="http://www.faqs.org/rfcs/rfc2389.html">http://www.faqs.org/rfcs/rfc2389.html</a>
+     * @return True if successfully completed, false if not.
+     * @throws IOException
+     */
+    public boolean features() throws IOException {
+    	return FTPReply.isPositiveCompletion(feat());
+    }
 
 
     /**
@@ -2292,14 +2312,11 @@
         Socket socket;
 
         FTPListParseEngine engine = new FTPListParseEngine(parser);
-
-        // TODO is this the correct thing to do? Should we throw an exception here?
         if ((socket = _openDataConnection_(FTPCommand.LIST, getListArguments(pathname))) == null)
         {
             return engine;
         }
 
-
         try {
             engine.readServerList(socket.getInputStream(), getControlEncoding());
         }

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java?rev=742140&r1=742139&r2=742140&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPCommand.java Sun Feb  8 18:51:49 2009
@@ -28,7 +28,7 @@
  * <p>
  * @author Daniel F. Savarese
  ***/
-
+/** TODO replace this with an enum */
 public final class FTPCommand
 {
 
@@ -68,7 +68,9 @@
     public static final int NOOP = 32;
     /** @since 2.0 */
     public static final int MDTM = 33;
-
+    /** @since 2.1 */
+    public static final int FEAT = 34;
+    
     public static final int USERNAME = USER;
     public static final int PASSWORD = PASS;
     public static final int ACCOUNT = ACCT;
@@ -104,7 +106,9 @@
     //public static final int NOOP = NOOP;
     /** @since 2.0 */
     public static final int MOD_TIME = MDTM;
-
+    /** @since 2.1 */
+    public static final int FEATURES = FEAT;
+    
     // Cannot be instantiated
     private FTPCommand()
     {}
@@ -113,7 +117,7 @@
                                           "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT",
                                           "PASV", "TYPE", "STRU", "MODE", "RETR", "STOR", "STOU", "APPE", "ALLO",
                                           "REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST",
-                                          "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM"
+                                          "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM", "FEAT"
                                       };
 
     /**

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java?rev=742140&r1=742139&r2=742140&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java Sun Feb  8 18:51:49 2009
@@ -51,7 +51,7 @@
     /** truststore type. */
     public static String STORE_TYPE;
 
-    /** The value that I can set in PROT command */
+    /** The value that I can set in PROT command  (C = Clear, P = Protected) */
     private static final String[] PROT_COMMAND_VALUE = {"C","E","S","P"}; 
     /** Default PROT Command */
     private static final String DEFAULT_PROT = "C";
@@ -196,7 +196,6 @@
         if(context == null) {
             try  {
                 context = SSLContext.getInstance(protocol);
-    
                 context.init(new KeyManager[] { getKeyManager() } , new TrustManager[] { getTrustManager() } , null);
             } catch (KeyManagementException e) {
                 IOException ioe = new IOException("Could not initialize SSL context");
@@ -213,7 +212,7 @@
     /**
      * SSL/TLS negotiation. Acquires an SSL socket of a control 
      * connection and carries out handshake processing.
-     * @throws IOException A handicap breaks out by sever negotiation.
+     * @throws IOException If server negotiation fails
      */
     private void sslNegotiation() throws IOException {
         plainSocket = _socket_;
@@ -231,9 +230,9 @@
             socket.setNeedClientAuth(isNeedClientAuth);
             socket.setWantClientAuth(isWantClientAuth);
         }
+
         if (protocols != null) socket.setEnabledProtocols(protocols);
         if (suites != null) socket.setEnabledCipherSuites(suites);
-
         socket.startHandshake();
 
         _socket_ = socket;
@@ -430,7 +429,6 @@
             setSocketFactory(new FTPSSocketFactory(context));
             setServerSocketFactory(new FTPSServerSocketFactory(context));
             initSslContext();
-            
         }
     }
 
@@ -486,13 +484,15 @@
     @Override
     protected Socket _openDataConnection_(int command, String arg)
             throws IOException {
-        Socket socket = super._openDataConnection_(command, arg);
+        Socket socket = super._openDataConnection_(command, arg); 
         if (socket != null && socket instanceof SSLSocket) {
-            SSLSocket sslSocket = (SSLSocket)socket;
+        	SSLSocket sslSocket = (SSLSocket)socket;
+
             sslSocket.setUseClientMode(isClientMode);
             sslSocket.setEnableSessionCreation(isCreation);
+       
             // server mode
-            if (!isClientMode) {
+            if (!isClientMode) {     	
                 sslSocket.setNeedClientAuth(isNeedClientAuth);
                 sslSocket.setWantClientAuth(isWantClientAuth);
             }
@@ -502,6 +502,7 @@
                 sslSocket.setEnabledProtocols(protocols);
             sslSocket.startHandshake();
         }
+       
         return socket;
     }