List FTP Directory with examples.ftp.FTPClientExample.java

Q

How to list a FTP directory with examples.ftp.FTPClientExample.java program? I know the directory path on the anonymous server.

✍: FYIcenter.com

A

If you know the directory path on an anonymous FTP server, you can use the following command to list the directory on the FTP server:

java -a -A -d examples.ftp.FTPClientExample host path

Where:
   -a - Use active mode for data connections to avoid firewall settings
   -A - Use anonymous login
   -d - List a directory
   host - Host name or IP address of the FTP server
   path - Path name of the directory on the FTP server

Here is an example of running examples.ftp.FTPClientExample.java program to list the /pub/davis directory from the space.mit.edu FTP server:

C:\fyicenter>\local\jdk-1.8.0\bin\java 
   -cp .;C:\local\commons-net-3.5\commons-net-3.5.jar
        ;C:\local\commons-net-3.5\commons-net-examples-3.5.jar 
   examples.ftp.FTPClientExample -a -A -d space.mit.edu /pub/davis

220-space.mit.edu NcFTPd Server (free educational license) ready.
220-
220- This server is operated by the MIT Center for Space Research.
220- Only anonymous FTP access is allowed to this server.  Use the
220- login Name `ftp', and use your e-mail address for the password.
220-

Connected to space.mit.edu on 21
USER *******
331 Guest login ok, send your complete e-mail address as password.
PASS *******
230 Logged in anonymously.
SYST
215 UNIX Type: L8
Remote system is UNIX Type: L8
TYPE A
200 Type okay.
PORT 192,168,1,7,238,190
200 PORT command successful.
MLSD /pub/davis
150 Opening ASCII mode data connection for MLS.
226 Listing completed.
Type=cdir;Modify=20040203180606;UNIX.mode=0755; /pub/davis
drwxr-xr-x    0   -1 2004-02-03 18:06:06 GMT /pub/davis
Type=pdir;Modify=20160902130025;UNIX.mode=0755; /pub
drwxr-xr-x    0   -1 2016-09-02 13:00:25 GMT /pub
Type=file;Size=537;Modify=19950811161207;UNIX.mode=0644; VMS.readme
-rw-r--r--    0  537 1995-08-11 16:12:07 GMT VMS.readme
Type=file;Size=10175;Modify=20000426170956;UNIX.mode=0644; acsite.m4
-rw-r--r--    010175 2000-04-26 17:09:56 GMT acsite.m4
Type=dir;Modify=20091214023711;UNIX.mode=0755; jed
drwxr-xr-x    0   -1 2009-12-14 02:37:11 GMT jed
Type=dir;Modify=20130924151431;UNIX.mode=0755; misc
drwxr-xr-x    0   -1 2013-09-24 15:14:31 GMT misc
Type=dir;Modify=20080925205417;UNIX.mode=0755; most
drwxr-xr-x    0   -1 2008-09-25 20:54:17 GMT most
Type=dir;Modify=20120317034319;UNIX.mode=0755; slang
drwxr-xr-x    0   -1 2012-03-17 03:43:19 GMT slang
Type=dir;Modify=20121222011319;UNIX.mode=0755; slrn
drwxr-xr-x    0   -1 2012-12-22 01:13:19 GMT slrn
Type=dir;Modify=20040228142210;UNIX.mode=0755; slsc
drwxr-xr-x    0   -1 2004-02-28 14:22:10 GMT slsc
Type=file;Size=0;Modify=19960429185651;UNIX.mode=0644; 
   {READ_BUGS_FILE_IF_PRESENT}
-rw-r--r--    0    0 1996-04-29 18:56:51 GMT {READ_BUGS_FILE_IF_PRESENT}
Type=file;Size=0;Modify=19960429185454;UNIX.mode=0644; 
   {SPECIFY_BINARY_BEFORE_DOWNLOADING}
-rw-r--r--    0    0 1996-04-29 18:54:54 GMT {SPECIFY_BINARY_BEFORE_DOWNLOADING}

NOOP
200 No-op okay.
QUIT
221-
221-    Thanks for stopping by!
221

 

Using commons-net.jar in Java Programs

⇒⇒FAQ for Apache commons-net.jar

2017-05-12, 466👍, 0💬