로컬 디스크에있는 파일과 FTP 서버에있는 파일을 비교해야하는 프로그램이 있습니다. md5 체크섬을 사용하기로 결정했습니다. 나는 로컬 파일로 할 수 있지만, ftp 파일에 문제가있다. 또한 Apache FTPClient를 공통으로 사용하고 있습니다.FTP 서버에있는 파일의 Java 체크섬 md5
MessageDigest digest = MessageDigest.getInstance("MD5");
FileInputStream is = new FileInputStream(FTP_listFiles[i]); //ERROR HERE
//FTP_files is a FTPFile from FTPClient apache commons.
byte[] buffer = new byte[8192];
int read = 0;
try {
while((read = is.read(buffer)) > 0) {
digest.update(buffer, 0, read);
}
byte[] md5sum = digest.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
String output = bigInt.toString(16);
System.out.println("MD5: \n" + output);
}
catch(IOException e) {
throw new RuntimeException("Unable to process file for MD5", e);
} finally {
try {
is.close();
}
catch(IOException e) {
throw new RuntimeException("Unable to close input stream for MD5 calculation", e);
}
}
NB : 불가능할 경우, md5와 동등한 것을 알고 있습니까? 그렇지만 동일한 작업을 수행 할 수 있습니까?
무엇을 달성하려고합니까? Md5를 로컬에서 계산하려면 전체 파일을 다운로드해야한다는 것을 알고 있습니까? –
무슨 문제가 있습니까? 어떤 코드? – EJP