Search code examples
javaftppgp

incompletely download of pgp file from ftp sever using apache.commons.net


I'm trying to transfer a pgp file with apache.commons.net.ftp.FTPClient, result seems successfully, but when I want to convert it to a txt file I encounter to this error: gpg: [don't know]: invalid packet (ctb=20)

and when I check the exact size of downloaded file, I notice that it's size is about 1KB less than original file.

here is the code for downloading file:

            FileOutputStream fos = new FileOutputStream(Localfilename);
            InputStream inputStream = ftpClient.retrieveFileStream(remoteFileDir);
            IOUtils.copy(inputStream, fos);
            fos.flush();
            IOUtils.closeQuietly(fos);
            IOUtils.closeQuietly(inputStream);
            boolean commandOK = ftpClient.completePendingCommand();

can any one understand what is mistake with my way or code?

[edited] noted that the original file decode (convert to txt)successfully, so the problem occures while downloading file.

[edited2] I run the program in my windows desktop and download file in windows, no problem for decode, and I understand that when I run my program with linux server this problem appears!


Solution

  • I found my problem! The problem was with addressing the remote path, a silly mistake! so If any one has this problem recheck and recheck again the addresses.