2016-07-08 1 views
1

나는 commons net FTP 3.5 및 Java 1.8.0.45를 사용하여 FTP를 통해 파일의 이름을 바꾸려고합니다. 170K 개의 작은 파일 (25GB)이있는 특정 폴더가 하나 있습니다. 이 폴더를 나열하려고하면 예외가 발생합니다. 나머지 폴더의 경우 파일이 올바르게 실행되고 이름이 바뀝니다.FTP를 통해 170K 개의 파일이있는 폴더에서 FTPConnectionClosedException이 발생하는 이유는 무엇입니까?

org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication. 
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:316) 
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:292) 
    at org.apache.commons.net.ftp.FTP.getReply(FTP.java:712) 
    at org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1857) 
    at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3420) 
    at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3335) 
    at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:3012) 
    at TestFTP.execute(TestFTP.java:27) 
    at TestFTP.main(TestFTP.java:12) 
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication. 
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:316) 
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:292) 
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:503) 
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:628) 
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:602) 
    at org.apache.commons.net.ftp.FTP.quit(FTP.java:884) 
    at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:1152) 
    at TestFTP.execute(TestFTP.java:62) 
    at TestFTP.main(TestFTP.java:12) 

코드 :

import java.io.IOException; 
import java.text.DateFormat; 
import java.text.SimpleDateFormat; 

import org.apache.commons.net.ftp.FTPClient; 
import org.apache.commons.net.ftp.FTPFile; 

public class TestFTP { 
    public static void main(String[] args) { 
     TestFTP.execute(args[0], args[1]); 
    } 
    static DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
    public static void execute(String ip, String folder) { 
     String server = ip; 
     int port = 21; 
     String user = "adminuser"; 
     String pass = "adminuser"; 

     long start = System.currentTimeMillis(); 
     FTPClient ftpClient = new FTPClient(); 
     try { 
      ftpClient.connect(server, port); 
      ftpClient.login(user, pass); 

      FTPFile[] files = ftpClient.listFiles(folder); 
      for (FTPFile file : files) { 
       String details = file.getName(); 

       // renaming file 
       String oldFile = folder + file.getName(); 
       String newFile = folder + "_X_" + file.getName(); 

       boolean success = ftpClient.rename(oldFile, newFile); 
       if (success) { 
        System.out.println(oldFile + " was successfully renamed to: " 
          + newFile); 
       } else { 
        System.out.println("Failed to rename: " + oldFile); 
       } 
      } 

      ftpClient.logout(); 
      ftpClient.disconnect(); 

      long end = System.currentTimeMillis(); 
      System.out.println("time:" +(end-start)); 

     } catch (IOException ex) { 
      ex.printStackTrace(); 
     } finally { 
      if (ftpClient.isConnected()) { 
       try { 
        ftpClient.logout(); 
        ftpClient.disconnect(); 
       } catch (IOException ex) { 
        ex.printStackTrace(); 
       } 
      } 
     } 
    } 
} 

제한 시간을 증가 같은 그런 큰 폴더를 나열하는 요구에 대한 응답을 내 FTP 서버를 만들 수있는 방법이 있나요? 또는 나는 무엇인가 놓치 느냐? 미리 감사드립니다!

+0

당신은 말고 아이디어는 얼마나 많은 시간을 파일의 목록을 어떻게 복용합니까? –

+0

전화를 잡으십시오. 왜 지구상에 170,000 개의 파일 이름을 바꾸기 위해 FTP를 사용하고 있습니까? 이 작업은 서버에서 직접 수행하는 것이 훨씬 더 효율적입니다. 그리고 자바 코드가 아닌 배치 파일이나 쉘 스크립트를 사용합니다. – EJP

+0

@ DanielHernández이 폴더에 대해 목록이 작성되지 않았습니다. 약 100 개의 파일이있는 다른 폴더의 경우 500 밀리 초 정도 걸렸습니다. – bkrish

답변

0

모든 정보 파일을 검색하는 데 시간이 걸리기 때문에 연결이 닫히고있는 경우 제한 시간 연결을 늘려야합니다.

는 당신은 시간 제한으로 재생해야

이 FTPClient에서 현명한 이러한 방법을 사용할 :

setDataTimeout(int timeout) //Sets the timeout in milliseconds to use when reading from the data connection. 

setControlKeepAliveTimeout(long controlIdle) 
//Set the time to wait between sending control connection keepalive messages when processing file upload or download. 
+0

나는 timeout (date timeout => 3600 sec, ControlKeepAliveTimeout = 0,)을 충분히 오래 시도했다. 공통 net FTP 클라이언트는 동일한 방식으로 작동합니다. 터미널에서도 FTP 서버는 즉시 오류 코드 421로 연결을 종료했습니다. 421 서비스를 사용할 수 없으며 원격 서버가 연결을 닫았습니다. 어떤 아이디어? – bkrish

관련 문제