1

I am using appache commons method to download some files from my FTP server and I am having some issues with the zip file being corrupted. I am able to download the file and place the file in the correct folder but when I open it there are files missing and it claims it's corrupted, if I try downloading with normal .txt files it works fine.

public boolean downloadFiles(String folder, String file) throws Exception
{
    File output = new File(folder + "\\" + file);
    System.out.println(output);
    FileOutputStream out    =   new FileOutputStream(output);
    client.retrieveFile(file, out);
    out.close();

    if(output.exists())      
        return true;
    else
        return false;

}
jn025
  • 2,755
  • 6
  • 38
  • 73
  • See also http://stackoverflow.com/questions/1601872/corrupt-image-file-after-uploading-it-using-ftp-command-from-linux-with-type-as – Raedwald Jun 19 '14 at 12:03
  • See also http://stackoverflow.com/questions/6155905/in-what-situation-should-i-use-ascii-to-transfer-a-file-over-ftp-im-not-askin – Raedwald Jun 19 '14 at 12:04
  • See also [FTPClient - Java, upload file](http://stackoverflow.com/questions/5925572/ftpclient-java-upload-file) – Raedwald Jun 19 '14 at 12:05

2 Answers2

3

Make sure you use binary mode for the FTP transfer. The fact that txt files work indicates that this is most likely your problem.

1

The file you are downloading on java client, try opening manually going to the FTP location itself. see if the zip file is okay or not. i had similar issue and found out that zip file was corrupt. Second step would be , check the size of the zip file you are downloading and the size of the downloaded file.

ppuskar
  • 773
  • 6
  • 9
  • Yeah I am able to download the file from the client and its not corrupted. The file size downloaded from the program is actually larger than when I download it just from the client o.o – jn025 Jun 19 '14 at 11:42
  • paste impl of retrieveFile(..) method. – ppuskar Jun 19 '14 at 11:47