commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1083625 - /commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java
Date Mon, 21 Mar 2011 00:20:09 GMT
Author: sebb
Date: Mon Mar 21 00:20:09 2011
New Revision: 1083625

URL: http://svn.apache.org/viewvc?rev=1083625&view=rev
Log:
Add TrustManager selection

Modified:
    commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java

Modified: commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java?rev=1083625&r1=1083624&r2=1083625&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java Mon Mar 21 00:20:09
2011
@@ -33,6 +33,7 @@ import org.apache.commons.net.ftp.FTPRep
 import org.apache.commons.net.ftp.FTPSClient;
 import org.apache.commons.net.io.CopyStreamEvent;
 import org.apache.commons.net.io.CopyStreamListener;
+import org.apache.commons.net.util.TrustManagerUtils;
 
 /**
  * This is an example program demonstrating how to use the FTPClient class.
@@ -62,6 +63,7 @@ public final class FTPClientExample
         "\t-s - store file on server (upload)\n" +
         "\t-t - list file details using MLST (remote is used as the pathname if provided)\n"
+
         "\t-w msec - wait time for keep-alive reply (setControlKeepAliveReplyTimeout)\n"
+
+        "\t-T  all|valid - use one of the built-in TrustManager implementations\n" +    
   
         "\t-# - add hash display during transfers\n";
 
     public static final void main(String[] args)
@@ -74,6 +76,7 @@ public final class FTPClientExample
         int minParams = 5; // listings require 3 params
         String protocol = null; // SSL protocol
         String doCommand = null;
+        String trustmgr = null;
 
         int base = 0;
         for (base = 0; base < args.length; base++)
@@ -126,6 +129,9 @@ public final class FTPClientExample
             else if (args[base].equals("-w")) {
                 controlKeepAliveReplyTimeout = Integer.parseInt(args[++base]);
             }
+            else if (args[base].equals("-T")) {
+                trustmgr = args[++base];
+            }
             else if (args[base].equals("-#")) {
                 printHash = true;
             }
@@ -165,18 +171,25 @@ public final class FTPClientExample
         if (protocol == null ) {
             ftp = new FTPClient();
         } else {
+            FTPSClient ftps;
             if (protocol.equals("true")) {
-                ftp = new FTPSClient(true);
+                ftps = new FTPSClient(true);
             } else if (protocol.equals("false")) {
-                ftp = new FTPSClient(false);
+                ftps = new FTPSClient(false);
             } else {
                 String prot[] = protocol.split(",");
                 if (prot.length == 1) { // Just protocol
-                    ftp = new FTPSClient(protocol);
+                    ftps = new FTPSClient(protocol);
                 } else { // protocol,true|false
-                    ftp = new FTPSClient(prot[0], Boolean.parseBoolean(prot[1]));       
            
+                    ftps = new FTPSClient(prot[0], Boolean.parseBoolean(prot[1]));      
             
                 }
             }
+            ftp = ftps;
+            if ("all".equals(trustmgr)) {
+                ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
+            } else if ("valid".equals(trustmgr)) {
+                ftps.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
               
+            }
         }
 
         if (printHash) {



Mime
View raw message