We're downloading a file from FTP server. Content of the file changes sometimes. File name is always the same.
Is this scenario possible?
Library used for downloading is apache commons-net.
Code used is:
FTPClient ftpClient = new FTPClient(); //client connecting code... //... ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ftpClient.retrieveFile(path, outputStream); outputStream.writeTo(new FileOutputStream(new File("myFile.txt")));
This can actually happen. So I would suggest you to get a checksum of the file before downloading. (Use FTP site command to execute scripts on server to give you the checksum) and then after downloading, compare with the checksum of the downloaded file.
Yes, the scenario is possible, depending on how the FTP server is implemented, and how files are being written to the area it is serving up.
There is nothing that you can do at the FTP client / protocol level to deal with this.
But you can address it at the application level by having the server-side application generate and write a checksum or hash of the updated file and write it to the FTP area as well. The client can then read the data file and the checksum file, and check that the checksum of the data file is correct. If they don't match, the remedy is to fetch the two files again.