Accessing the ftp server directories through the java program is not possible. Connection is established but reading the content is a problem. It works fine at root level.
SAMPLE PROGRAM
-----------------------------------------------------------------
import java.io.*;
import java.util.*;
import java.net.*;
class temp{
public static void main(String args []) throws Exception {
// javasoft4.india is ftp server name
String filename = "ftp://javasoft4.india" ; // works fine
String filename = "ftp://javasoft4.india/" ;// works fine
String filename = "ftp://javasoft4.india/pub" ;// gives error
String filename = "ftp://javasoft4.india/etc" ;// gives error
String filename = "ftp://javasoft4.india/usr" ;// gives error
String filename = "ftp://javasoft4.india/dev" ;// gives error
URL u = new URL(filename);
System.err.println("URL: " + u);
URLConnection uc = u.openConnection();
System.err.println("uc="+uc+"("+uc.getClass()+")");
System.err.println(uc.getContentEncoding());
System.err.println(uc.getContent());
System.err.println("Content Length of File: " + uc.getContentLength());
InputStream is = uc.getInputStream();
int size = 0;
int len = 0;
try{
byte[] b = new byte[100];
while ((len = is.read(b)) > 0) {
System.err.println("+"+len);
size+=len;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
-----------------------------------------------------------------
ERROR generated
-----------------------------------------------------------------
"Error: sun.net.ftp.FtpProtocolException: PORT :501 PORT not
allowed after EPSV ALL"
------------------------------------------------------------------
I have checked it with mantis jdk too. The problem is always reproducible.
SAMPLE PROGRAM
-----------------------------------------------------------------
import java.io.*;
import java.util.*;
import java.net.*;
class temp{
public static void main(String args []) throws Exception {
// javasoft4.india is ftp server name
String filename = "ftp://javasoft4.india" ; // works fine
String filename = "ftp://javasoft4.india/" ;// works fine
String filename = "ftp://javasoft4.india/pub" ;// gives error
String filename = "ftp://javasoft4.india/etc" ;// gives error
String filename = "ftp://javasoft4.india/usr" ;// gives error
String filename = "ftp://javasoft4.india/dev" ;// gives error
URL u = new URL(filename);
System.err.println("URL: " + u);
URLConnection uc = u.openConnection();
System.err.println("uc="+uc+"("+uc.getClass()+")");
System.err.println(uc.getContentEncoding());
System.err.println(uc.getContent());
System.err.println("Content Length of File: " + uc.getContentLength());
InputStream is = uc.getInputStream();
int size = 0;
int len = 0;
try{
byte[] b = new byte[100];
while ((len = is.read(b)) > 0) {
System.err.println("+"+len);
size+=len;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
-----------------------------------------------------------------
ERROR generated
-----------------------------------------------------------------
"Error: sun.net.ftp.FtpProtocolException: PORT :501 PORT not
allowed after EPSV ALL"
------------------------------------------------------------------
I have checked it with mantis jdk too. The problem is always reproducible.