2011-09-09 2 views
1

나는 무언가를 알아 내기 힘든 시간을 보내고 있습니다. (저는이 모든 것을 처음 접했습니다.) 이 java pgm을 사용하여 대용량 파일을 대상 서버에 ftp로 작성했습니다. 내가 보내고있다 파일에 무슨 일이 일어나고 이상한FTP 클라이언트 문제

public static void ftpUpload(String path, String upfileName, String dirName) throws Exception 
{ 
    FTPClient client = new FTPClient(); 
    client.addProtocolCommandListener((ProtocolCommandListener) new PrintCommandListener(new PrintWriter(System.out))); 
    client.enterLocalPassiveMode(); 

    FileInputStream fis = null; 

    int reply; 

    try { 
     client.connect(ftpserver); 
     client.login(ftpuserid, ftppasswd); 
     reply = client.getReplyCode(); 

     if(FTPReply.isPositiveCompletion(reply)){ 
      client.changeWorkingDirectory(ftpdirectoryName + "/" + dirName); 

      boolean mkDir = client.makeDirectory(getCurrentMMMYY().toLowerCase()); 

      client.changeWorkingDirectory(getCurrentMMMYY().toLowerCase()); 

       //Create an InputStream of the file to be uploaded 
      fis = new FileInputStream(path + upfileName); 

      //Store file to server 
      client.storeFile(upfileName, fis); 

     }  
    } catch (IOException e) { 
     e.printStackTrace(); 
    } finally { 
     try { 
      if (fis != null) { 
       fis.close(); 
      } 
      client.logout(); 
      //client.disconnect(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

} 

뭔가 ... 크기 발신 서버 내 파일의 하나입니다 82575786, 그리고 : 은 여기 (코드는 디스플레이에 대한 약간의 수정 된) 코드입니다 이 파일을 ftp로 보내면 거의 전체 파일을 보냅니다. 실제로 82574867을 보냅니다. (누락 된 919) 원본 서버의 다른 파일은 717885이며이 파일을 ftp로 보내면 거의 전체 파일을 보냅니다. 실제로 717522를 보냅니다. (누락 363)

나는 로그를 가져와 충돌이 발생했는지 확인했지만 전송에는 아무런 문제가없는 것으로 나타났습니다. 다음은 전송을 나타내는 2 개의 로그 항목입니다.

[08/09/11 20 : 21 : 13 : 618 EDT] 00000043 SystemOut 221 - 717522 바이트를 1 파일로 전송했습니다. 221- 1 파일에 82574867 바이트를 전송했습니다.

누구나 도움을 주실 수 있습니다. 감사합니다. Dan.

+0

내가 요청할 수 있습니다을 그래서 whydoes sendfile은 하나의 입력 스트림 만 가져오고 작동하지 않습니다. 고마워! – 98percentmonkey

답변

3

바이너리 대신 ASCII 모드로 전송 하시겠습니까? ASCII 모드는 서버 및 클라이언트 설정에 따라 CR/LF를 LF로 또는 그 반대로 변환합니다.

Apache's FTP 클라이언트를 사용하고 있습니까?

client.setFileType(FTPClient.BINARY_FILE_TYPE); 
+0

Jason에게 감사드립니다. 파일은 바이너리 파일 유형을 추가하여 조금 더 앞서졌지만 여전히 전체 파일을 ftp하지 않았습니다. 두 파일 모두 여전히 마지막 두 레코드를 얻지 못했습니다. –

1

당신이 FTP.BINARY_FILE_TYPE를 사용할 필요하지만 충분하지 않다 바이너리 파일을 업로드하려면이 기본이 ASCII, 당신은 setFileTypeBINARY_FILE_TYPE 설정을 시도 할 수 말합니다.

만 입력 스트림을 사용하고 있고 나는이 예제에서는 도움이 될 수 있기를 바랍니다 너무

OutputStream에 사용할 필요가 : 당신이 입력 및 outpustream를 사용하는 이유

FTPClient client = new FTPClient(); 
client.connect("192.168.30.20"); 
client.login("pwd", "pwd"); 

client.setFileType(FTP.BINARY_FILE_TYPE); 
String path_base = "/myPath/"; 
InputStream fis = new FileInputStream("A.pdf"); 
OutputStream os = client.storeFileStream(path_base+ "B.pdf"); 


byte buf[] = new byte[8192]; 
int bytesRead = fis.read(buf); 
while (bytesRead != -1) { 
    os.write(buf, 0, bytesRead); 
    bytesRead = fis.read(buf);} 

fis.close(); 
os.close(); 
client.completePendingCommand(); 
client.logout(); 
client.disconnect();