I am trying to do a directory listing within a directory and I am getting a StringIndexOutOfBoundsException.
This is my test code
import com.enterprisedt.net.ftp.FTPException;
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPTransferType;
import java.io.IOException;
public class FTPClientTest
{
public static void main(String args[])
{
FTPClient ftp;
// we want remote host, user name and password
if (args.length < 3) {
System.out.println(args.length);
usage();
System.exit(1);
}
try {
// assign args to make it clear
String host = args[0];
String user = args[1];
String password = args[2];
ftp = new FTPClient(host);
// switch on debug of responses
ftp.debugResponses(true);
ftp.login(user, password);
System.out.println("Logged in");
// change dir
ftp.chdir("IMC");
System.out.println("Changed directory to IMC");
String listing[] = ftp.dir("IMC",true);
System.out.println(listing);
ftp.quit();
}
catch (IOException ex) {
System.out.println("Caught exception: " + ex.getMessage());
}
catch (FTPException ex) {
System.out.println("Caught exception: " + ex.getMessage());
}
}
public static void usage() {
System.out.println("FTPClientTest remotehost user password");
}
}
This is result when I do a ftp.dir() on IMC dicretory.
DEBUG [SocketUtils] 6 Feb 2008 22:25:48.664 : Could not use Socket.isConnected (java.lang.NoSuchMeth
odException)
DEBUG [SocketUtils] 6 Feb 2008 22:25:48.666 : Could not use Socket.isConnected (java.lang.NoSuchMeth
odException)
DEBUG [FTPControlSocket] 6 Feb 2008 22:25:48.668 : ---> USER xxxx
DEBUG [FTPControlSocket] 6 Feb 2008 22:25:48.713 : 331 User name Okay, need password.
DEBUG [SocketUtils] 6 Feb 2008 22:25:48.715 : Could not use Socket.isConnected (java.lang.NoSuchMeth
odException)
DEBUG [FTPControlSocket] 6 Feb 2008 22:25:48.716 : ---> PASS ********
DEBUG [FTPControlSocket] 6 Feb 2008 22:25:48.724 : 230 User logged in, proceed.
Logged in
DEBUG [SocketUtils] 6 Feb 2008 22:25:48.725 : Could not use Socket.isConnected (java.lang.NoSuchMeth
odException)
DEBUG [FTPControlSocket] 6 Feb 2008 22:25:48.726 : ---> CWD IMC
DEBUG [FTPControlSocket] 6 Feb 2008 22:25:48.734 : 250 Requested file action okey, completed.
Changed directory to IMC
DEBUG [SocketUtils] 6 Feb 2008 22:25:48.735 : Could not use Socket.isConnected (java.lang.NoSuchMeth
odException)
DEBUG [FTPControlSocket] 6 Feb 2008 22:25:48.736 : ---> PASV
DEBUG [FTPControlSocket] 6 Feb 2008 22:25:48.744 : 202 Command not implemented, superfluous at this
site.
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -49
at java.lang.String.substring(Unknown Source)
at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocketPASV(FTPControlSocket.java:670)
at com.enterprisedt.net.ftp.FTPControlSocket.createDataSocket(FTPControlSocket.java:450)
at com.enterprisedt.net.ftp.FTPClient.setupDataSocket(FTPClient.java:1917)
at com.enterprisedt.net.ftp.FTPClient.dir(FTPClient.java:2718)
at FTPClientTest.main(FTPClientTest.java:36)
$
This is the result I get when I manually do an FTP from windows command line and list directory contents of IMC directory.
C:\Documents and Settings\MMM>ftp XXX.XXX.X.XXX
Connected to XXX.XXX.X.XXX.
220-Welcome to XXXXX firmware File System
For first time user, please do key in REMOTEHELP to see how to use this.
220 Service ready for new user.
User (XXX.XXX.X.XXX:(none)): XXXX
331 User name Okay, need password.
Password:
230 User logged in, proceed.
ftp> cd IMC
250 Requested file action okey, completed.
ftp> dir
200 Command okay.
150 File Status okey; about to open data connection.
XXXXX Firmware Directory: /IMC
Running Firmware Revision: X.X.X
Built on: Mon Oct 08 20:30:57 2007
Status: MAIN = FAIL, BKUP = FAIL
Hardware Info: CPUBOARD = 0
Volume Name : 11.0.0 [0l]
RW- 867328 bytes 1694 blocks Wed Feb 6 22:51:04 2008 XXX.HXB [1]
RW- 859436 bytes 1679 blocks Fri Nov 2 14:55:18 2007 XXX1.HXB [2]
------------- -----------
1726764 bytes 3373 blocks used
3687 blocks dirty [1887744 bytes]
367 blocks clean [ 187904 bytes]
226 Closing data connection.
ftp: 535 bytes received in 1.00Seconds 0.54Kbytes/sec.
ftp>
Any help here?
Thanks