Java FTPClient를 사용하여 서버에서 파일을 다운로드하고 있습니다. 파일이 다운로드되면 무결성을 확인한 다음 삭제하고 싶습니다. 다운로드 한 파일의 크기 (바이트)와 서버의 파일 크기 (바이트)를 비교하여 결과를 얻지는 않습니다. 당신이 볼 수FTP 서버에서 다운로드 한 파일의 길이가 서버의 파일 길이와 같지 않습니다.
다음public void checkIfExists(File downloadedFile, FTPFile remoteFileToDelete) {
Long downloadedLength = downloadedFile.length();
Long remoteLength = remoteFileToDelete.getSize();
if (downloadedFile.length() == remoteFileToDelete.getSize()) {
LOGGER.info(downloadedLength + "exists and is the same length as " + remoteLength + ". Let's delete");
} else {
LOGGER.info(downloadedLength + "is not the same length as " + remoteLength + ". Let's not delete");
}
}
가 두 번 루프를 실행 한 후 출력 인의 크기
다음for (int i = 0; i <= insideDirectory.length - 1; i++) {
FTPFile transferFile = insideDirectory[i];
LOGGER.info("Passing file" + folder.getName() + "/" + transferFile.getName());
File downloadFile = new File("https://stackoverflow.com/users/home/example" + i + ".mp4");
OutputStream outputStream2 = new BufferedOutputStream(new FileOutputStream(downloadFile));
System.out.println(transferFile.getSize());
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
InputStream inputStream = ftpClient
.retrieveFileStream(folder.getName() + "/" + transferFile.getName());
byte[] bytesArray = new byte[4096];
int bytesRead = -1;
while ((bytesRead = inputStream.read(bytesArray)) != -1) {
outputStream2.write(bytesArray, 0, bytesRead);
}
Boolean success = ftpClient.completePendingCommand();
if (success) {
System.out.println("File #" + i + " has been downloaded successfully.");
checkIfExists(downloadFile, transferFile);
}
가 내 checkIfExists
방법 : 아래
File #0 has been downloaded successfully.
INFO: 7596008is not the same length as 7600840. Let's not delete
File #1 has been downloaded successfully.
INFO: 6873664is not the same length as 6878544. Let's not delete
File #2 has been downloaded successfully.
INFO: 7558112is not the same length as 7564744. Let's not delete
File #3 has been downloaded successfully.
INFO: 8662336is not the same length as 8665108. Let's not delete
File #0 has been downloaded successfully.
INFO: 7594312is not the same length as 7600840. Let's not delete
File #1 has been downloaded successfully.
INFO: 6870392is not the same length as 6878544. Let's not delete
File #2 has been downloaded successfully.
INFO: 7559184is not the same length as 7564744. Let's not delete
File #3 has been downloaded successfully.
INFO: 8660888is not the same length as 8665108. Let's not delete
어떻게 확인할 수 있습니까? – steam1234322
하단의 출력이 충분하지 않습니까? 두 파일의 크기를 바이트로 비교합니다. – steam1234322
아, 알겠습니다. 그럼 알 니탁이 알아 냈어. –