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;
}
'in.close();'다음에 성공하면 true로 설정 했습니까? – itro
@itro 물론. – EJP