2017-03-08 2 views
2

FTP 서버가 있는데 FTPClient에아파치 공유 net ftp sendCommand가 잘못된 답신 코드를 반환합니다.

을 업로드하려고합니다. openDataConnection는(), 내가 명령은 "STOR"및 인수입니다

if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) { 
    return null; 
} 

라인에 내려하는 것은 "edf0864d-1651-43b2-8453-d160bf9d0742"(나는 저장할 파일의 이름)입니다

서버 로그는 다음과 같습니다 응답 코드가 150 로그에서

PORT 86,185,26,230,213,101 
200 Port command successful 
STOR edf0864d-1651-43b2-8453-d160bf9d0742 
150 Opening data channel for file upload to server of "/edf0864d-1651-43b2-8453-d160bf9d0742" 
(Up to here after calling sendCommand) 
PORT 86,185,26,230,213,102 
200 Port command successful 

만 인 sendCommand 200

O의 응답 코드를 반환 나는 동일한 코드로, FileZilla의 서버

서버는 대부분의 시간을 작동을 사용하고

잠재적으로 중요한 정보를 THER. 파일의 초기 업로드가 정상적으로 작동하면 첫 번째 업로드를 덮어 쓸 다른 파일을 선택하면 이런 일이 발생합니다.

그 다음에는 같은 이름의 다른 파일이 있지만 그 전에는 문제가 없었습니다.

서버는 내가 말할 수있는 한 수동적 인 연결을 위해 구성되었습니다. 예전처럼 그것을 시작할 때 나에게 외치는 것은 아니지만 PASV 명령은 421이 소켓 오류를 생성 할 수 없도록 만듭니다.

FTPClient ftp = new FTPClient(); 
String server = <server ip>; 
int port = 21; 
String username = <username>; 
String password = <password>; 
try{ 
    ftp.connect(server, port); 
} 
catch(SocketException e){ 
    throw new FTPCouldNotConnectException("Threw SocketException during connection", e); 
} 
catch(IOException e){ 
    throw new FTPCouldNotConnectException("Threw IOException during connection", e); 
} 
int reply = ftp.getReplyCode(); 
if(!FTPReply.isPositiveCompletion(reply)){ 
    try{ 
     ftp.disconnect(); 
     throw new FTPCouldNotConnectException("Reply Code: " + reply + ", Could not connect"); 
    } 
    catch(IOException e){ 
     throw new FTPCouldNotConnectException(
       "Threw IOException during disconnection after failing to connect with reply code: " + reply, 
       e); 
    } 
} 
else{ 
    try{ 
     if(ftp.login(username, password)){ 
      LOGGER.info("Successfully logged in to ftp server"); 
      ftp.setFileTransferMode(org.apache.commons.net.ftp.FTP.STREAM_TRANSFER_MODE); 
      ftp.setFileStructure(org.apache.commons.net.ftp.FTP.FILE_STRUCTURE); 
      ftp.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE); 
      ftp.enterLocalActiveMode(); 
     } 
     else{ 
      LOGGER.warn("Failed to log in to ftp server"); 
     } 
    } 
    catch(IOException e){ 
     throw new FTPCouldNotConnectException("Failed to log in to server, threw ioexception", e); 
    } 
} 
try{ 
    ftp.storeFile("edf0864d-1651-43b2-8453-d160bf9d0742", new FileInputStream("test.jpg")); 
} 
catch(IOException e){ 
    LOGGER.error("java.io.IOException caught", e); 
} 
: 나는 3.6

이것은 자바의 관련 부분입니다

을 도울 수있는 추가 정보가 있다면 알려주세요 ACTIVE_LOCAL 모드 I 순 아파치 평민을 사용하고

을 사용하고 있습니다

Wireshark Packets (let me know if you need more)

+0

코드를 추가하십시오 – Grzesiek

+0

사용하는 라이브러리와 버전을 정확하게 추가하십시오. – Grzesiek

+0

자바 코드와 라이브러리 버전을 추가했습니다. –

답변

2

나는 코드의 첫 번째 전화가 잘 작동하지만, 두 번째는 실패했다는 사실에 기초 답을 발견했다.

자바 코드에서 FTPClient.completePendingCommand()를 호출하지 않았습니다. The docs say으로, 후속 호출이 예기치 않게 작동합니다.

관련 문제