Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with Jakarta FTPFile class  RSS feed

 
Mike Cutter
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just downloaded the new Jakarta Commons Net 1.3.0 library. I am trying to use the FTPClient and FTPFile classes. Right now, I'm trying to use this on two HP-UX 11.11 systems running WU-FTP 2.6.1. This is a snippet of my code:

import org.apache.commons.net.ftp.*;
try {
FTPClient ftp = new FTPClient();
ftp.connect("server");
ftp.login("root", "password");
String dir = "/home/root";
FTPFile[] files = ftp.listFiles(dir);
} catch (Exception e) {
e.printStackTrace();
}

I thought I typed this in just like the example figuring this will auto-detect the parser. Logging in as "root", I figure there should be no permission problems. The directory "/home/root" does exist. The line with the FTPFile declaration keeps throwing a MalformedPatternException.

Any suggestions would be appreciated in debugging this.

Mike Cutter
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First and foremost, you'd be wise to follow the instructions in the API:

public class FTPClient
extends FTP
. . .
As with all classes derived from SocketClient, you must first connect to the server with connect before doing anything. . . Then you need to check the FTP reply code to see if the connection was successful.

You are not checking to see if you've successfully connected.
Second, from personal experience, FTP server implementations vary wildly in many aspects. Try your code against different implementations. Chances are you will get different results. If you do, then the problem isn't with your code.
Last, search the
user mailing lists and see if anyone is having a similar problem.
 
Mike Cutter
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I downloaded the jakarta-oro-2.0.8.jar library and added it to the CLASSPATH. This resolved the Malformed Exception I was getting.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!