windows - Java FTP Connection Problem with FileZilla -
i have weird problem local testing-setup of 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 = conn.getinputstream(); /// , here flies ioexception!
... actual ioexception-cause "subone/subtwo/subthree/subfour", 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 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 (000012)23.02.2011 13:01:05 - anonymous (127.0.0.1)> 200 type set (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" 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" 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" current directory. (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 (|||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 @ all, why tester trying extended passive mode , why it's added subone after can't retrieve subfour.
i installed filezilla server , set anonymous user , shared drives. checked via browser , filezilla-client ftp-dir reachable (same logins of course) , that's it. installed , running on same machine!
don't know further...
thanks help!
this way connect ftp quite limited , obscurely documented. can give answer epsv first. connection established internal implementation in jdk happens sun.net.www.protocol.ftp.ftpurlconnection
.
when connecting server first epsv
, pasv
tried (default passive mode) fall active mode - port
- if passive mode cannot established. can see implementation details here.
the essential comment explaining 1 of questions is:
/** * here idea: * * - first want try new (and ipv6 compatible) epsv command * since want nice nat software, we'll issue * epsv cmd first. * epsv documented in rfc2428 * - if epsv fails, fall older, yet ok pasv command * - if pasv fails well, throw exception , calling method * have try eprt or port command */
as second question... unsuccessful retrieval of subfour... well, @ first quick seems behave way because buggy. cannot install proper environment verify now. further have exception. guess problem initiated on line 455 when tries navigate full path again. full source of ftp connection here.
373 public inputstream getinputstream() throws ioexception { ... 390 try { 391 decodepath(url.getpath()); 392 if (filename == null || type == dir) { ... 399 } else { 400 if (type == ascii) 401 ftp.ascii(); 402 else 403 ftp.binary(); 404 cd(pathname); 405 = new ftpinputstream(ftp, ftp.get(filename)); 406 } 407 408 ... 453 } catch (filenotfoundexception e) { 454 try { 455 cd(fullpath); 456 /* if worked, make directory listing 457 , build html stream files in 458 directory */ 459 ftp.ascii(); 460 461 = new ftpinputstream(ftp, ftp.list()); 462 msgh.add("content-type", "text/plain"); 463 } catch (ioexception ex) { 464 throw new filenotfoundexception(fullpath); 465 } 466 } ... 469 }
i advise use apache commons net library ftp operations. more advanced , straightforward use.
cheers , happy debugging if feel like!
Comments
Post a Comment