Author: sebb
Date: Fri Feb 25 22:12:45 2011
New Revision: 1074717
URL: http://svn.apache.org/viewvc?rev=1074717&view=rev
Log:
Add listfiles option
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=1074717&r1=1074716&r2=1074717&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 Fri Feb 25 22:12:45
2011
@@ -28,6 +28,7 @@ import org.apache.commons.net.PrintComma
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPConnectionClosedException;
+import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
/***
@@ -47,12 +48,13 @@ public final class FTPClientExample
"Usage: ftp [-s] [-b] <hostname> <username> <password> <remote
file> <local file>\n" +
"\nDefault behavior is to download a file and use ASCII transfer mode.\n" +
"\t-s store file on server (upload)\n" +
+ "\t-l list files\n" +
"\t-b use binary transfer mode\n";
public static final void main(String[] args)
{
int base = 0;
- boolean storeFile = false, binaryTransfer = false, error = false;
+ boolean storeFile = false, binaryTransfer = false, error = false, listFiles = false;
String server, username, password, remote, local;
FTPClient ftp;
@@ -62,6 +64,8 @@ public final class FTPClientExample
storeFile = true;
else if (args[base].startsWith("-b"))
binaryTransfer = true;
+ else if (args[base].equals("-l"))
+ listFiles = true;
else
break;
}
@@ -152,6 +156,13 @@ __main:
input.close();
}
+ else if (listFiles)
+ {
+ for (FTPFile f : ftp.listFiles(remote)) {
+ System.out.println(f);
+ }
+
+ }
else
{
OutputStream output;
|