Hi,
I am new to Java. Recently I developed one application for Uploading files to Shared drive. All files are Uploading properly but Checksum Of PDF files are mismatching. Someone please help me to fix this issue
Thanks in advance.

Edited 3 Years Ago by goutham.patnam

All files are Uploading properly but Checksum Of PDF files are mismatching.

This is very unclear... How did you do the checksum? What method are you using? MD5? SHA1? SHA2? etc...

Also, please read the forum posting rules... [ I can't find a link to the rules :( ]

Member rules link is at bottom right corner of (every?) screen.
I think the one you are looking for is
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
J

File Uploading Code:

public void FileToLocal(String localDir, String ftpPath,
            String fileNameStr) throws IOException {
        Boolean status = false;
        File fileName = new File(localDir + "/" + fileNameStr);
        OutputStream outStrm = new FileOutputStream(fileName); // by this line we are uploading the files to the shared drive.

        try {
            ftpClient.changeWorkingDirectory(ftpPath);

            status = ftpClient.retrieveFile(fileNameStr, outStrm);
                 }

Checksum Code:

public class CheckSum {

    public static void main(String[] args) throws IOException{

        String inputFilePath = "D:/checkSumTest/test.pdf"; 
        long checkSumValue = checkSumCalculator(inputFilePath);
        System.out.println("Checksum is " + checkSumValue);
    }

    public static long checkSumCalculator(String fileName) throws IOException{      
        FileInputStream file = new FileInputStream(fileName);
            CheckedInputStream check = new CheckedInputStream(file, new CRC32());
            BufferedInputStream in = new BufferedInputStream(check);
            while (in.read() != -1) {            // Read file in completely
            }      
            return check.getChecksum().getValue();
        }
    }
.

Edited 3 Years Ago by peter_budo: Editing, so code and class marking text are separeted

Hi,
Thanks for the response please find the above code used for uploading as well as doing checksum

You may try to use other algorithm besides CRC32. Refer to Wikipedia, the CRC32 algorithm is not reliable with what you are doing. You could use MD5 or SHA1 algorithm instead.

Hi,

Thanks for the response. I have tried using MD5 and SHA1, but still the checksum is coming wrong. Should I make any changes in the file retrieval code, I mean any setting of property?

Thanks in advance.

How do you call CheckSum on the shared storage? Is the class stored and run on the shared?

The checksum is standalone application which we run after the data transfer is complete. The path will be given as input to this checksum code.

No, what I mean is that the checksum class is in the same server as your file is on? Or it is being called online instead? I am not sure if the checksum could correctly compare when you use different input buffers (run to check on local file V. on an online file). When I upload a file via FTP, I normally see that the file size are different at local and online (via FTP). If I am on the server and look at the file size, the size would be the same as I am looking at my local machine though.

This article has been dead for over six months. Start a new discussion instead.