Author: sebb
Date: Wed Dec 10 12:12:44 2014
New Revision: 1644381

URL: http://svn.apache.org/r1644381
Log:
Add display timezone option for listing methods
Allow multiple listing methods in a single connect session

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=1644381&r1=1644380&r2=1644381&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 
Wed Dec 10 12:12:44 2014
@@ -79,6 +79,7 @@ public final class FTPClientExample
         "\t-w msec - wait time for keep-alive reply 
(setControlKeepAliveReplyTimeout)\n" +
         "\t-T  all|valid|none - use one of the built-in TrustManager 
implementations (none = JVM default)\n" +
         "\t-Z timezone - set the server timezone for parsing LIST responses\n" 
+
+        "\t-z timezone - set the timezone for displaying MDTM, LIST, MLSD, 
MLST responses\n" +
         "\t-PrH server[:port] - HTTP Proxy host and optional port[80] \n" +
         "\t-PrU user - HTTP Proxy server username\n" +
         "\t-PrP password - HTTP Proxy server password\n" +
@@ -104,6 +105,7 @@ public final class FTPClientExample
         String password = null;
         String encoding = null;
         String serverTimeZoneId = null;
+        String displayTimeZoneId = null;
 
 
         int base = 0;
@@ -177,6 +179,9 @@ public final class FTPClientExample
             else if (args[base].equals("-Z")) {
                 serverTimeZoneId = args[++base];
             }
+            else if (args[base].equals("-z")) {
+                displayTimeZoneId = args[++base];
+            }
             else if (args[base].equals("-PrH")) {
                 proxyHost = args[++base];
                 String parts[] = proxyHost.split(":");
@@ -360,48 +365,48 @@ __main:
 
                 input.close();
             }
-            else if (listFiles)
+            // Allow multiple list types for single invocation
+            else if (listFiles || mlsd || mdtm || mlst || listNames)
             {
-                if (lenient || serverTimeZoneId != null) {
-                    FTPClientConfig config = new FTPClientConfig();
-                    config.setLenientFutureDates(lenient);
-                    if (serverTimeZoneId != null) {
-                        config.setServerTimeZoneId(serverTimeZoneId);
+                if (mlsd) {
+                    for (FTPFile f : ftp.mlistDir(remote)) {
+                        System.out.println(f.getRawListing());
+                        
System.out.println(f.toFormattedString(displayTimeZoneId));
                     }
-                    ftp.configure(config );
                 }
-
-                for (FTPFile f : ftp.listFiles(remote)) {
-                    System.out.println(f.getRawListing());
-                    System.out.println(f.toFormattedString());
+                if (mdtm) {
+                    FTPFile f = new FTPFile();
+                    f.setName(remote);
+                    String stamp = ftp.getModificationTime(remote);
+                    f.setTimestamp(parseGMTdate(stamp) ); // parse the 
returned string
+                    System.out.println(f.toFormattedString(displayTimeZoneId));
                 }
-            }
-            else if (mlsd)
-            {
-                for (FTPFile f : ftp.mlistDir(remote)) {
-                    System.out.println(f.getRawListing());
-                    System.out.println(f.toFormattedString());
+                if (mlst) {
+                    FTPFile f = ftp.mlistFile(remote);
+                    if (f != null){
+                        
System.out.println(f.toFormattedString(displayTimeZoneId));
+                    }
                 }
-            }
-            else if (mdtm)
-            {
-                FTPFile f = new FTPFile();
-                f.setName(remote);
-                String stamp = ftp.getModificationTime(remote);
-                f.setTimestamp(parseGMTdate(stamp) ); // parse the returned 
string
-                System.out.println(f.toFormattedString());
-            }
-            else if (mlst)
-            {
-                FTPFile f = ftp.mlistFile(remote);
-                if (f != null){
-                    System.out.println(f.toFormattedString());
+                if (listNames) {
+                    for (String s : ftp.listNames(remote)) {
+                        System.out.println(s);
+                    }
                 }
-            }
-            else if (listNames)
-            {
-                for (String s : ftp.listNames(remote)) {
-                    System.out.println(s);
+                // Do this last because it changes the client
+                if (listFiles) {
+                    if (lenient || serverTimeZoneId != null) {
+                        FTPClientConfig config = new FTPClientConfig();
+                        config.setLenientFutureDates(lenient);
+                        if (serverTimeZoneId != null) {
+                            config.setServerTimeZoneId(serverTimeZoneId);
+                        }
+                        ftp.configure(config );
+                    }
+    
+                    for (FTPFile f : ftp.listFiles(remote)) {
+                        System.out.println(f.getRawListing());
+                        
System.out.println(f.toFormattedString(displayTimeZoneId));
+                    }
                 }
             }
             else if (feat)


Reply via email to