2013-04-17 4 views
1

나는 sauronsoftware.ftp4j.FTPClient을 사용하여 FTP 서버에서 예약 된 파일 다운로드를 수행합니다. 내 문제는 클라이언트가 파일을 다운로드하는 동안 FTP 서버가 갑자기 작동하지 않는다는 것입니다. 별도의 스레드에서 실행하고 FTP 서버가이 스레드를 죽을 때 영원히처럼 어쨌든 계속 실행ftp4j 클라이언트가 파일을 다운로드하는 동안 FTP 서버가 사망합니다

 for (FTPFile remoteFile : remoteFiles) { 

       String remoteFileName = remoteFile.getName(); 
       String localPath = ftpDir.getLocalPath() + remoteFileName; 
       log.debug("Downloading remote file {} to local path {}", remoteFileName, localPath); 
       try { 
        client.download(remoteFileName, new File(localPath)); 

        if (!ftpDir.isLeaveFilesOnServer()) { 
         //Delete remote file 
         client.deleteFile(remoteFileName);        
        } 

       } catch (IllegalStateException e) { 

        log.error("FTPException ",e); 

        fcr.addErrorFile(remoteFileName); 

       } catch (IOException e) { 

        log.error("FTPException ",e); 

문제는 그 다운로드 (...)입니다 : 이 내가하는 일입니다. 이 문제를 해결할 수있는 방법이 있습니까? 아니면 이와 같은 문제를 처리 할 수있는 다른 FTP 클라이언트를 사용해야합니까?

+0

를 종료하기 전에 완료 될 때까지 메인 쓰레드가 대기 할 수 있도록 'commons-net'을 사용합니까? http://commons.apache.org/proper/commons-net/examples/ftp/FTPClientExample.java – longhua

답변

1

FTP 연결이 갑자기 발생하거나 unexpedtecly인지, 파일을 다운로드하기 전에 주 스레드가 실행을 마친 것이 아닌지 잘 모르겠습니다. 우리가 두 번째 시나리오에 대해 얘기하는 경우에, 어쩌면 당신은 같은 FTPClient 클래스의 다른 방법을 사용할 수 있습니다

public void download(java.lang.String remoteFileName, 
       java.io.File localFile, 
       FTPDataTransferListener listener) 

을 모두 다운로드