commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ojeda, Winston" <>
Subject RE: net.ftp: sendCommand, or executing commands from ftp prompt
Date Fri, 08 Aug 2003 17:42:32 GMT
Who's FTP server is that?
I don't recognize those entries.
Chances are you might have to right your own parser.
See here for examples: net/src/java/org/apache/commons/net/ftp/parser
Come think of it, might want to give a try to the Connect Enterprise Unix
FTP Server From Sterling Commerce Parser that we wrote and see if it works
for you.

Winston Ojeda
Quad Graphics/Information Systems
Data Services Division

-----Original Message-----
From: Stephen Charles Huey []
Sent: Friday, August 08, 2003 11:48 AM
To: Commons Net User list
Subject: net.ftp: sendCommand, or executing commands from ftp prompt

I'm trying to use the FTPClient provided in the Apache Commons Net code:

It has a method called listNames() that returns a String of the files'
names in the current directory. The problem is that the site I'm ftping
into presents to me a virtual file system, and the files "listed" are not
constructed (by servlets?) until I try to download them. On this system,
when I ftp in via a command prompt, I must type "dir" at the ftp prompt
to get a listing (though the listing is not a typical file system one,
seeing as how it includes other things like batch ID, status codes, etc),
and then "get" with parameters in order to download the file I want. All
of the "file names" are actually identical, and their batch ID numbers
are unique (that's what I ask for with that get command). When I call
FTPClient's listNames(), whatever it does returns a string that has only
the pseudo filename (which is useless to me), and does not obtain any of
that other data that I can see when I type dir at the command line. 

So, after logging in, I need a way to pretend I'm sitting at an ftp
prompt with a command line terminal and can type in "dir" and hit enter.
I thought that maybe FTPClient's superclass (FTP) could help me out,
because it has a method called sendCommand(String s). However, when I
send "dir" and call FTPClient.getReplyString(), the reply string simply
says that the dir command was not understood! So I'm not sure what that
sendCommand is for, and I can't find any other suitable methods for
executing a "direct command", and I'm hoping that someone out there
understands this API better than me or has a bright idea about how to
handle this! 

Below is a small sample of what I can see with the dir command:

-ARTE-----TCP A cbeodm   22159   629629 Aug 06 05:47 PSEUDOFILENAME
-ARTE-----TCP A cbeodm    4915  1031030 Aug 06 09:12 PSEUDOFILENAME
-ARTE-----TCP A cbeodm   16941   321321 Aug 06 12:41 PSEUDOFILENAME
-ARTE-----TCP A cbeodm    7872  3010007 Aug 07 02:31 PSEUDOFILENAME
-ARTE-----TCP A cbeodm    2737   564564 Aug 07 05:54 PSEUDOFILENAME
-ARTE-----TCP A cbeodm   14879   991991 Aug 07 08:57 PSEUDOFILENAME
-ARTE-----TCP A cbeodm    5183   332332 Aug 07 12:37 PSEUDOFILENAME
-AR-------TCP A cbeodm    5252  2767765 Aug 08 01:49 PSEUDOFILENAME
-AR-------TCP A cbeodm   15502   537537 Aug 08 05:44 PSEUDOFILENAME
-AR-------TCP A cbeodm   13444  1428427 Aug 08 09:01 PSEUDOFILENAME

The first few letters (ARTE, AR) are flags associated with each file. 
The two sets of numbers represent batch IDs and file sizes.  So, from the
command prompt, after typing dir and Return, I'll see the above listing. 
I was hoping to use FTPClient.getReplyString() or getReplyStrings() to
browse the listing and parse out the pieces I need to check (like batch
ID and the flag codes to see if I've already downloaded that file
before).  If I want to download the file pointed to by batch ID 4915,
then I could type this at the ftp prompt:

get #4915 C:\downloadtemp\aug6_0912_data.dat

Now, as I mentioned, I figured I could maybe use FTP.sendCommand("dir")
to get that listing, like this:

String replyString = ftpClient.getReplyString();

But this is what gets put in that replyString:

500 'DIR': command not understood.

So I need to know how to give the prompt a string with a newline to
execute that command and somehow capture all that text output back to the
terminal.  Just FYI, here's the alternative code I tried just to make

String [] replyStrings = ftpClient.listNames();
System.out.println("num of replyStrings: " + replyStrings.length);

And here is the output:

num of replyStrings: 1

I guess that listNames fails because it asks the "directory" what files
are available through some standard channel, and since all the files have
the same name in this system, it just returns one file name.  Anyway,
when I first saw that method I figured it wouldn't work in this system
anyway.  I just need a way to simulate being at the ftp prompt so I can
give commands and read the terminal output to get the files I need.  I
love this Commons Net package, but I just can't find what I need--that
is, if it exists!  

Thanks for your help,

P.S.  sendCommand is in class FTP:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message