Downloading a file from ftp server while file is being altered/overwritten

We're downloading a file from FTP server. Content of the file changes sometimes. File name is always the same.

Is this scenario possible?

  1. File content is "aaaaaaaaaaaaa"
  2. We start downloading
  3. File is overwritten and it looks like "bbbbbbbbbbbbb"
  4. File content we get is "aaaaabbbbbbb"

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")));
Answer:1

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.

Answer:2

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.

Answer:3

I am having trouble with my last method. I am informed that I have to use my adjust method from my BankAccount.class in my monthlyFee method in my bank class and I can not figure it out. I've tried ...

I am trying to integrate a processing applet in a jsp, with the following code added in the jsp: <!--<applet code="Test1.class" archive="C:\Users\user\Desktop\MyApplet.jar" width="600" height="...

The code works fine. Just looking for information on how to set up my print f and get the desired results. signs more than one print f statement(s): import java.util.Scanner; public class Coupon { ...

This issue is really frustrating me. I am developping a webapp that creates ical files for users. The issue that I am facing, is whenever the ical event repeates weekly or daily or monthly, the start ...