나는 서버에서 파일을 다운로드하기 위해 노력하고있어,하지만 0 바이트를 얻을 ...이FTPClient은 0 바이트 파일을
public boolean getFile(String filename){
try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect(ftpAddress, ftpPort);
ftpClient.login(ftpUser, ftpPass);
int reply = ftpClient.getReplyCode();
//FTPReply stores a set of constants for FTP reply codes.
if (!FTPReply.isPositiveCompletion(reply))
{
ftpClient.disconnect();
return false;
}
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setBufferSize(1024*1024);
String remoteFile = serverPath + filename;
logger.debug("remote file is: "+remoteFile); //correct path
File tempFile = new File(downloadDir+"temp.jar");
logger.debug("file will be "+tempFile.toString()); //correctly created
OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile));
ftpClient.retrieveFile(remoteFile, os);
os.close();
String completeJarName = downloadDir+jarName;
//delete previous file
File oldFile = new File(completeJarName);
FileUtils.forceDelete(oldFile);
//rename
File newFile = new File(completeJarName);
FileUtils.moveFile(tempFile, newFile);
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("errore ftp", e);
return false;
}
return true;
}
기본적으로 내 FTPDownload 클래스는
이다, 임시 저런 다운로드 도착하면 이전 파일이 취소되고 임시 파일의 이름이 바뀌었지만 0 바이트입니다 ... 어디서 잘못되었는지 이해할 수 없습니다 ...
출력 스트림'os.flush()'를'ftpClient.retrieveFile' 다음에'os.close()'전에 플러시하려고합니다. – Shadov