I have problem when use Jakarta Commons Net in Java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: I have problem when use Jakarta Commons Net in Java

Threaded View

  1. #1
    Join Date
    Mar 2006
    Posts
    4

    Question I have problem when use Jakarta Commons Net in Java

    Hi you, I'm new in Network Programming in Java and I'm excuting a FTP class to list all files and directories information from FTP Host . But I had a problem when I try to use "org.apache.commons.net.ftp" package in Jakarta Commons Net Library. It logins OK but fail when try list information in current working directory .
    Error:
    220 ftp1.0catch.com NcFTPd Server (licensed copy) ready.
    Workdir >>/
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/oro/text/regex/MalformedPatternException
    at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createUnixFTPEntryParse r(DefaultFTPFileEntryParserFactory.java:169)
    at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createFileEntryParser(D efaultFTPFileEntryParserFactory.java:94)
    at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2358)
    at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2141)
    at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2188)
    at JClient.FTPClientTrial.useFTP(FTPClientTrial.java:52)
    at JClient.FTPClientTrial.main(FTPClientTrial.java:23)
    Java Result: 1


    CODE :
    import java.text.DateFormat;
    import java.util.Date;
    import org.apache.commons.net.ftp.*;

    import java.io.*;
    public class FTPClientTrial {
    public static void main(String[] args) {
    new FTPClientTrial().useFTP("ftp://thanhnam-it.0catch.com", "/", "J://AcrobatReader//Readme.htm",
    "usernam", "password");
    }

    public void useFTP(String ftpserver, String directoryName,
    String filetoUpload, String username, String password) {
    FTPClient ftpClient = new FTPClient();

    try {
    ftpClient.connect(ftpserver);
    System.out.print(ftpClient.getReplyString());

    // check reply code.
    if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
    ftpClient.disconnect();
    System.out.println("Connection refused.");
    return;
    }

    ftpClient.login(username, password);
    System.out.println("Workdir >>" +
    ftpClient.printWorkingDirectory());

    //Store file
    FileInputStream input = new FileInputStream(filetoUpload);
    ftpClient.storeFile(filetoUpload, input);

    //ERROR HERE : List all Files and directories
    FTPFile[] files = ftpClient.listFiles(); System.out.println( "Number of files in dir: " + files.length );
    DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );
    for( int i=0; i<files.length; i++ )
    {
    Date fileDate = files[ i ].getTimestamp().getTime();

    // Download a file from the FTP Server
    System.out.print( df.format( files[ i ].getTimestamp().getTime() ) );
    System.out.println( "\t" + files[ i ].getName() );
    File file = new File( "/directory" + File.separator + files[ i ].getName() );
    FileOutputStream fos = new FileOutputStream( file );
    ftpClient.retrieveFile( files[ i ].getName(), fos );
    fos.close();
    file.setLastModified( fileDate.getTime() );
    }

    ftpClient.logout();
    ftpClient.disconnect();
    System.out.println("Disconnected");

    } catch (IOException e) {
    if (ftpClient.isConnected()) {
    try {
    ftpClient.disconnect();
    System.out.println("Disconnected");
    }
    catch (IOException f) {
    // do nothing
    }
    }

    e.printStackTrace();
    }
    finally {
    try {
    ftpClient.logout();
    ftpClient.disconnect();
    }
    catch (IOException f) {
    System.out.println("Disconnected");
    }
    }
    }
    }
    ---------------------
    So I don't understand what type of error and how I can solve it? Anyone show me? Thank u a lot!
    Last edited by wintersun; 11-25-2006 at 10:38 AM.

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2006, 04:16 PM
  2. Java 3D to 2D applet problem
    By nataku in forum Java
    Replies: 0
    Last Post: 04-27-2006, 06:29 PM
  3. Replies: 1
    Last Post: 01-03-2006, 07:45 AM
  4. Replies: 2
    Last Post: 11-07-2005, 05:00 AM
  5. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 07:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center