To accomplish your need, you have to handle the overwriting manually in the ProblemDetected
event handler.
Create a handler method like this:
static void client_ProblemDetected(object sender, FtpProblemDetectedEventArgs e)
{
// if the file does not exist, we cannot resolve what to do, so do nothing
if (e.ProblemType != TransferProblemType.FileExists)
return;
// first handle the file size
if (e.RemoteItem.Length != e.LocalItem.Length)
{
e.Overwrite(); // overwrite unconditionally
return;
}
// then let the Overwrite method decide the file date and time
// (the same as using ActionOnExistingFiles.OverwriteOlder in Download method)
e.Overwrite(OverwriteCondition.Older); // overwrite conditionally, otherwise skip the file
}
Then assign this method to the ProblemDetected
event of your FTP object before calling the Download method:
// connect and login
var client = new Ftp();
client.Connect("server");
client.Login("username", "password");
// assign the event handler
ftp.ProblemDetected += client_ProblemDetected;
// perform the file transfers
// you can (or rather should) omit the ActionOnExistingFiles argument now
ftp.Download(remotePath, localPath);
Note: This article can be used for the Rebex SFTP component as well - just replace the first line of the code with:
var client = new Sftp();