Results 1 to 2 of 2
  1. #1
    mniz13 is offline Member
    Join Date
    Jun 2011
    Location
    Boston, MA
    Posts
    7
    Rep Power
    0

    Default having trouble with FTPClient

    I'm attempting to access a directory in an ftp server using java. I am using FTPClient class which i downloaded from org.apache.commons.net.ftp API. I seem to be able to log in to the ftp server just fine but when I attempt to change directories using the doCommand() method, it fails to do so. I can't just use the listFiles() method because that returns and array of FTPFile, which doesn't really help me much because they can't be cast as a regular file and they can't list what they contain, which is the ultimate goal. Here is my code that is supposed to access the ftp and print the list of directories in the specified folder:

    public static void accessFTP() throws SocketException, IOException
    {
    FTPClient client = new FTPClient();
    client.connect("--.-.-.--");
    System.out.println(client.login("userName", "pw")); // returns true as it should
    // confirming the login
    System.out.println(client.doCommand("cd" , "dir1")); // prints false. should be true
    System.out.println(client.doCommand("cd", "dir2")); // also prints false
    String[] work = client.doCommandAsStrings("ls", "");
    for (int i=0; i<work.length; i++) // throws nullPointer because work is null
    {
    System.out.println(work[i]);
    }
    client.disconnect();
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,809
    Rep Power
    25

    Default

    I can't just use the listFiles() method because that returns and array of FTPFile, which doesn't really help me much because they can't be cast as a regular file
    The list of files returned are not local files. You couldn't use the File class to access them.
    You need to use the FTPClient's methods to get to the files that are on the server.
    Read the API doc for the FTPFile class to see how to use it.

Similar Threads

  1. Create FtpClient using Java
    By kapz_unlocked in forum New To Java
    Replies: 0
    Last Post: 06-22-2011, 10:47 AM
  2. FTPClient quality loss
    By Arnokeh in forum Advanced Java
    Replies: 1
    Last Post: 04-06-2011, 08:20 PM
  3. FTPClient need to download?
    By dudejonne in forum New To Java
    Replies: 8
    Last Post: 11-06-2009, 05:40 PM
  4. Ftpclient abort download
    By Papalazarou in forum New To Java
    Replies: 0
    Last Post: 01-06-2009, 05:18 PM
  5. problems sun.net.ftp.FtpClient
    By tommy in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 05:01 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •