I am trying to download a tar.gz file from a FTP Server (over HTTP Proxy). While the hastle of connecting over the proxy has been taken care of (I am able to read regular files from FTP site), I am able to download file to a my desktop (obviously a developer machine). But when I try inflate that file I am getting an exception. Below are my code snippets
if (CollectionUtils.isNotEmpty(filesList)) {
for (String fileName : filesList) {
if (fileName.endsWith(getArchiveFileType())) {
// File is a tar.gz file.
// Download this file to a local directory
FtpDownloadMethod downloadMethod = new FtpDownloadMethod();
OutputStream output = new FileOutputStream(getOutputDirectory() + fileName);
downloadMethod.setFileTransferMode(FTPClient.COMPRESSED_TRANSFER_MODE);
downloadMethod.setOutput(output);
downloadMethod.setUri(fileName);
isDownloaded = isDownloaded && getServiceProxy().executeMethod(downloadMethod).isSuccess();
output.close();
}
}
}
Here is the actual method that does the transfer.
String uri; //method arguements
OutputStream output; //method arguements
DefaultFtpResponse response = null;
try {
response = new DefaultFtpResponse();
boolean success = false;
if (StringUtils.isBlank(getUri())) {
response.setStatusCode(FTPReply.FILE_UNAVAILABLE);
} else {
aFtpClient.connect();
aFtpClient.enterLocalPassiveMode();
aFtpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
aFtpClient.setFileTransferMode(getFileTransferMode());
success = aFtpClient.retrieveFile(uri, output);
response.setSuccess(success);
response.setStatusCode(FTPReply.COMMAND_OK);
}
} catch (Exception exp) {
LOGGER.error(exp);
}
return response;
This code creates a file and i can see a file being created in the desired output folder. After downloading, when i try to unzip the downloaded file, i see this error.
java.util.zip.ZipException: oversubscribed literal/length tree
I tried BLOCK_TRANSFERR_MODE AND BINARY_TRANSFER_MODE as well.
The uploaded file was corrupt. I was trying to upload in binary transfer mode. After changing it to Compressed transfer mode, I am able to process the file.