0 votes
by (120 points)
edited

Hi,

I'm using your batchtransfer sample to download a directory tree from FTP (using Getfiles). The files on the FTP can be rather large (>1GB) so I don't want to download them when they are already locally available. I do however need to check if we're talking about the same file so I need to calculate a checksum of both the local and remote file.

I implemented this check in the BatchTransferProblemDetected event handler. In there I call the GetRemoteChecksum function and that's where it's going wrong. When the app executes this function I get the error "Another operation is pending". When I disable this function the rest of the app runs smoothly.

It seems that the component is not able to run GetRemoteChecksum while it's busy. Is this by design? Any suggestion how to get this working?

Thanks,

Johan

2 Answers

0 votes
by (73.6k points)
edited

Hello,

when using Ftp one operation can be executed at a time only. Therefore calling the GetRemoteChecksum method when a batch operation is in progress throws the mentioned exception.

We are currently finishing new version of components. When it is released we add new value OverwriteIfChecksumDiffers to the BatchAction enumeration.

In the meantime, you can use following algorithm:

  • Start a batch operation.
  • If the file already exists store the local and remote path into a collection (you can use List<BatchProblemDetectedEventArgs> the event args contains both).
  • When the batch operation finish iterate through the collection and compute desired checksums.
  • If the checksums differ transfer the file immediately using a single file transfer method.

If you want the sample code, please leave the comment.

0 votes
by (73.6k points)
edited

From Version 2013 R3 you are able to use default action OverwriteDifferentChecksum in batch operations like this:

ftp.Download("remote_path", "local_path", 0, 0, ActionOnExistingFiles.OverwriteDifferentChecksum)

Alternatively, you are able to choose "overwrite if checksums differ" from the Ftp.ProblemDetected event like this:

void ftp_ProblemDetected(object sender, FtpProblemDetectedEventArgs e)
{
    // check if computing checksums is supported and allowed
    if (e.IsOverwriteConditionPossible(OverwriteCondition.ChecksumDiffers))
        e.Overwrite(OverwriteCondition.ChecksumDiffers);
}
...