• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with my FTP client Program: MalformedPatternException  RSS feed

yathish Gatty
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am writing an FTP application using org.apache.commons.net. I am able to connect and disconnect with my server. As a start up, I am trying to print the list of files in the specified directory.(As later on I want to check whether the file is directory or not) But it gave me bunch of exception although it compiled well. Here is my code:

import org.apache.commons.net.ftp.*;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;

public class MyFTP {

public static void main(String[] args) {

String user="user-name";
String psw="password";
String server="";
String directory="/lic";
try {
FTPClient f= new FTPClient();
f.login(user, psw);

/************* this does not work *************/

FTPFile[] files = f.listFiles();
for(int i=0;i< files.length;i++){
System.out.println("files:" + files[i].getName());
}//end of for loop

/************* up to this *************/


}catch(Exception e){

}//end of function


These are the exception I got:

java.lang.NoClassDefFoundError: org/apache/oro/text/regex/MalformedPatternException
at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createUnixFTPEntryParser(DefaultFTPFileEntryParserFactory.java:121)
at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createFileEntryParser(DefaultFTPFileEntryParserFactory.java:84)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2306)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2055)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2106)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2146)
at MyFTP.main(MyFTP.java:23)
Exception in thread "main"

I dont know how to proceed. All I need to do is download a file from a specified directory in binary mode.
That is my goal. But before that I tried to see whether I am able to get the files/directory listing from a specified directory. Pls help/suggest me If I am doing anything wrong.

Advance Thanks
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!