2012-04-05 4 views
0

정말로 'put'이 파일을 목적지에 넣는 데 성공했는지 알고 싶습니다. 어떤 이유로 든 파일이 대상에 없을 경우 [공간 제약과 같은 대상 서버의 문제로 인한 것일 수 있습니다]이를 알아야합니다.sun.net.ftp.FtpClient에서 ftp 성공/실패를 트래핑하는 방법?

코드 :

private static boolean putFile(String m_sLocalFile, FtpClient m_client) { 
      boolean success = false; 
    int BUFFER_SIZE = 10240; 
    if (m_sLocalFile.length() == 0) { 
     System.out.println("Please enter file name"); 
    } 
    byte[] buffer = new byte[BUFFER_SIZE]; 
    try { 
     File f = new File(m_sLocalFile); 
     int size = (int) f.length(); 
     System.out.println("File " + m_sLocalFile + ": " + size + " bytes"); 
     System.out.println(size); 
     FileInputStream in = new FileInputStream(m_sLocalFile); 
     OutputStream out = m_client.put(f.getName()); 

     int counter = 0; 
     while (true) { 
      int bytes = in.read(buffer); 
      if (bytes < 0) 
       break; 
      out.write(buffer, 0, bytes); 
      counter += bytes; 
      System.out.println(counter); 
     } 

     out.close(); 
     in.close(); 
    } catch (Exception ex) { 
     System.out.println("Error: " + ex.toString()); 
    } 
      return success; 
} 

답변

0

나는 그것이 IOException을 던져 기대. 그렇지 않다고 믿을만한 이유가 있습니까? 하지만 그 클래스를 직접 사용해서는 안되며 을 호출 한 후 ftp : URL과 그 URLConnection 클래스를 사용하여 I/O를 수행해야합니다.

+0

'in.close();'다음에 성공하면 true로 설정 했습니까? – itro

+0

@itro 물론. – EJP