i have a weird problem with my local Testing-Setup of a simple Java URL FTP Connection.
Following code fragments (removed try/catches):
URL url = new URL("ftp://127.0.0.1/subOne/subTwo/subThree/subFour");
URLConnection conn = url.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
InputStream is = conn.getInputStream(); /// And here flies the IOException!
… The actual IOException-Cause is “subOne/subTwo/subThree/subFour”, but the funny things happen on server side:
(000012)23.02.2011 13:01:05 - (not logged in) (127.0.0.1)> Connected, sending welcome message...
(000012)23.02.2011 13:01:05 - (not logged in) (127.0.0.1)> 220 Blabla
(000012)23.02.2011 13:01:05 - (not logged in) (127.0.0.1)> USER anonymous
(000012)23.02.2011 13:01:05 - (not logged in) (127.0.0.1)> 331 Password required for anonymous
(000012)23.02.2011 13:01:05 - (not logged in) (127.0.0.1)> PASS *************
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 230 Logged on
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> TYPE I
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 200 Type set to I
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> CWD das
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 250 CWD successful. "/subOne" is current directory.
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> CWD 2011
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 250 CWD successful. "/subOne/subTwo" is current directory.
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> CWD 02
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 250 CWD successful. "/subOne/subTwo/subThree" is current directory.
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> EPSV ALL
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 229 Entering Extended Passive Mode (|||3881|)
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> EPSV
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 229 Entering Extended Passive Mode (|||3882|)
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> RETR subFour
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 550 File not found
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> CWD subOne
(000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 550 CWD failed. "/subOne/subTwo/subThree/subOne": directory not found.
(000012)23.02.2011 13:03:06 - anonymous (127.0.0.1)> 421 Connection timed out.
(000012)23.02.2011 13:03:06 - anonymous (127.0.0.1)> disconnected.
I don’t understand at all, why the Tester is trying to get into extended passive mode and why it’s added subOne after it can’t retrieve subFour.
I just installed the FileZilla Server and set up the anonymous user and shared drives. I checked via browser and FileZilla-Client that the FTP-Dir is reachable (same logins of course) and that’s it.
Everything is installed and running on the same machine!
Don’t know any further…
Thanks for any help!
This way to connect to the FTP is quite limited and obscurely documented. I can give you an answer for the EPSV first. The connection is established by internal implementation which in my JDK happens to be
sun.net.www.protocol.ftp.FtpURLConnection.When connecting to the server first
EPSVandPASVwill be tried (default is the passive mode) then it will fall back to the active mode –PORT– if the passive mode cannot be established. You can see the implementation details here.The essential comment explaining one of your questions is:
As for your second question… the unsuccessful retrieval of subFour… Well, at first quick look it seems to behave that way because it is buggy. But I cannot really install the proper environment to verify that now. Further you have the exception. I guess that the problem is initiated on line 455 when it tries to navigate to the full path again. The full source of the FTP connection is here.
I would advise you to use the Apache Commons Net library for FTP operations. It is much more advanced and straightforward to use.
Cheers and happy debugging if you feel like!