You use the local path variable pointing to the remote file:
filename = "C:\\tmp\\user\\" + file.getName(); ... client.retrieveFile(filename, fos);
You want to specify the remote file, not the local address, for example:
client.retrieveFile(file.getName(), fos);
Also, make sure you close the fos
stream after reading each file, and not the right at the end. You can use IOUtils.closeQuietly(fos);
for this, if you get a commons.io library that avoids nested try-catch blocks.
You should also use the BINARY file type and BLOCK to transfer ZIP files:
client.setFileTransferMode(FTPClient.BLOCK_TRANSFER_MODE); client.setFileType(FTPClient.BINARY_FILE_TYPE);
source share