Results 1 to 2 of 2
Thread: having trouble with FTPClient
- 06-24-2011, 08:01 PM #1
Member
- Join Date
- Jun 2011
- Location
- Boston, MA
- Posts
- 7
- Rep Power
- 0
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();
}
- 06-24-2011, 08:29 PM #2
The list of files returned are not local files. You couldn't use the File class to access them.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
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
-
Create FtpClient using Java
By kapz_unlocked in forum New To JavaReplies: 0Last Post: 06-22-2011, 09:47 AM -
FTPClient quality loss
By Arnokeh in forum Advanced JavaReplies: 1Last Post: 04-06-2011, 07:20 PM -
FTPClient need to download?
By dudejonne in forum New To JavaReplies: 8Last Post: 11-06-2009, 04:40 PM -
Ftpclient abort download
By Papalazarou in forum New To JavaReplies: 0Last Post: 01-06-2009, 04:18 PM -
problems sun.net.ftp.FtpClient
By tommy in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 04:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks