2011-02-23 2 views
1

간단한 Java URL FTP 연결의 로컬 테스트 설정에 이상한 문제가 있습니다. 코드 부분에 따라 (제거 시도/캐치) :FileZilla를 사용한 Java FTP 연결 문제

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! 

을 ... 실제 IOException이-원인은 "subOne/subTwo/subThree/subFour"하지만 재미있는 일들이 서버 측에서 발생 :

(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. 
subFour를 검색 할 수 없습니다 후에는 subOne을 추가 왜 테스터가 수동 모드 확장에 얻으려고 노력하고 왜 전혀 이해하지 못하는

.

방금 ​​FileZilla Server를 설치하고 익명 사용자 및 공유 드라이브를 설정했습니다. 나는 브라우저와 FileZilla-Client를 통해 FTP-Dir에 도달 할 수 있는지 확인했다 (물론 동일한 로그인). 모든 것이 동일한 기계에 설치되어 실행 중입니다!

더 이상 알 수 없음 ...

어떤 도움을 주셔서 감사합니다!

답변

4

FTP에 연결하는이 방법은 매우 제한적이며 모호하게 문서화되어 있습니다. 먼저 EPSV에 대한 답을 줄 수 있습니다. 연결은 JDK에서 sun.net.www.protocol.ftp.FtpURLConnection 인 내부 구현에 의해 설정됩니다.

서버에 처음 연결할 때 EPSVPASV이 시도됩니다 (기본값은 수동 모드 임). 수동 모드를 설정할 수없는 경우 PORT - 활성 모드로 다시 되돌아갑니다. 구현 세부 사항 here을 볼 수 있습니다.

질문 중 하나를 설명 필수 주석입니다 : 것을 행동하는 것 같다 처음 얼핏에서 두 번째 질문에 대해서는

/** 
    * Here is the idea: 
    * 
    * - First we want to try the new (and IPv6 compatible) EPSV command 
    * But since we want to be nice with NAT software, we'll issue the 
    * EPSV ALL cmd first. 
    * EPSV is documented in RFC2428 
    * - If EPSV fails, then we fall back to the older, yet OK PASV command 
    * - If PASV fails as well, then we throw an exception and the calling method 
    * will have to try the EPRT or PORT command 
    */ 

... subFour의 실패 검색 ... 음, 그것은 버기 때문에 길. 그러나 나는 지금 그것을 확인하기위한 적절한 환경을 설치할 수는 없다. 더 이상 예외가 있습니다. 나는 전체 경로를 다시 탐색하려고 할 때 문제가 455 번째 줄에서 시작되었다고 생각합니다. FTP 연결의 전체 소스는 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     is = new FtpInputStream(ftp, ftp.get(filename)); 
    406    } 
    407 
    408 
    ... 
    453   } catch (FileNotFoundException e) { 
    454    try { 
    455     cd(fullpath); 
    456     /* if that worked, then make a directory listing 
    457      and build an html stream with all the files in 
    458      the directory */ 
    459     ftp.ascii(); 
    460 
    461     is = new FtpInputStream(ftp, ftp.list()); 
    462     msgh.add("content-type", "text/plain"); 
    463    } catch (IOException ex) { 
    464     throw new FileNotFoundException(fullpath); 
    465    } 
    466   } 
    ... 
    469  } 

FTP 작업에는라이브러리를 사용하는 것이 좋습니다. 사용하기가 훨씬 더 진보적이며 직관적입니다.

기분이 좋으면 환호하고 즐거운 시간 되실 수 있습니다!

+0

좋은 답변, @lucho. – andersoj

+0

시간과 답변에 감사드립니다! 나는이 것이 JDK의 깊숙한 곳에 쉽게 묻히게 될지도 모른다고 두려워했다. 나는 Apache Commons를 시도 할 것이다 ... 다시 한번 감사드립니다! – Gruber