0

I have a java class for downloading voice recordings from SFTP server. I use Apache Commons API to do it. The steps should be:

  1. download the recording to byte array (byte[])
  2. validate if the downloaded recording is whole, correct and not corrupt in any way (I mean in comparison with the server one, if it is corrupted on a server then I don't care - I just need it to be the same)
  3. delete the recording from the server

How can I do step 2 to be as sure as possible (maybe 100% is not possible I don't know)? So far I am just checking whether the byte[] is not empty but that is pretty weak. I looked at some checksums but I don't have any other access to the server than via SFTP in java application so I can't make the checksum on the server... Thank you for any help!

Wolf
  • 871
  • 1
  • 7
  • 21
  • what is the sound format? (wav, mp3 etc.) – Andrei Nikolaenko Mar 10 '15 at 17:31
  • @Andrei : the sound format is always mp3 – Wolf Mar 10 '15 at 17:34
  • If you want to be really sure about the file integrity, there is a tool MP3Val http://mp3val.sourceforge.net/ which can check the file. You can run it in command line using `Runtime.exec()` or read the sources and see how it's done, maybe you'll get some ideas. – Andrei Nikolaenko Mar 10 '15 at 17:51
  • 2
    SFTP is a binary protocol that runs over SSH which includes integrity checking. So the files *can not* be corrupted unless the SFTP client you use is buggy. If you have file corruption, you need to search for a bug rather than build corruption detection into your code. – Eugene Mayevski 'Callback Mar 10 '15 at 19:57
  • what do you mean by SFTP client? The apache commons library that I use to connect to SFTP server? ... So you are saying that unless the library throws an exception, the download should be solid? – Wolf Mar 10 '15 at 20:52
  • 1
    @Wolf That's correct. See also [How to check if Paramiko successfully uploaded a file to an SFTP server?](http://stackoverflow.com/q/28967969/850848) – Martin Prikryl Mar 11 '15 at 07:09
  • If anyone wants you can put that all in the answer and I will accept it so the next person that looks for it will know without reading comments. If nobody does that I will add the answer later and delete this comment. – Wolf Mar 11 '15 at 17:54

0 Answers0