FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

UploadDirectory in Mirror mode occasionally deletes destination folder's entire contents

Open AlienDave opened this issue 1 year ago • 9 comments

FTP Server OS: Windows FTP Server Type: Windows Server IIS Client Computer OS: Windows FluentFTP Version: 50.0.1 Framework: .NET 4.8.1

I have an app that generates around 1000 XML files (in subfolders). It then uploads a mirror to the FTP server. So, most of the time it's overwriting files with newer versions of themselves. Occasionally, if there are files to remove, it will remove ALL files, not just the extras. The FtpResults report success.

No logs at this stage...

AlienDave avatar May 24 '24 07:05 AlienDave

Well. Until there are logs there is only one slight idea what might be going wrong:

If a folder listing somehow fails, unrecognized, the mirror operation might decide that mirrored folder needs to be empty also.

But without a log of a specific occurrence? Very difficult.

FanDjango avatar May 24 '24 18:05 FanDjango

It uploaded the files, recorded them as successful in the FtpResults, THEN deleted them.

I've done a workaround - delete folder, create folder, upload in Update mode.

On Sat, 25 May 2024, 3:46 am FanDjango, @.***> wrote:

Well. Until there are logs there is only one slight idea what might be going wrong:

If a folder listing somehow fails, unrecognized, the mirror operation might decide that mirrored folder needs to be empty also.

But without a log of a specific occurrence? Very difficult.

— Reply to this email directly, view it on GitHub https://github.com/robinrodricks/FluentFTP/issues/1580#issuecomment-2130118301, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABYK2FUGF6NHBPMP5DZ57O3ZD57YLAVCNFSM6AAAAABIHBAX52VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZQGEYTQMZQGE . You are receiving this because you authored the thread.Message ID: @.***>

AlienDave avatar May 25 '24 02:05 AlienDave

It uploaded the files, recorded them as successful in the FtpResults, THEN deleted them.

Wow. Need to check the code how that can happen.

FanDjango avatar May 25 '24 11:05 FanDjango

Code has some logging to show up what it is doing and why.

LogWithPrefix(FtpTraceLevel.Info, "Delete extra file from server: " + existingServerFile.FullName);

So, without a look at your code, and a log that shows this to be happening, there will be no further analysis of this issue.

FanDjango avatar May 25 '24 18:05 FanDjango

FTP.log

Here's my log, and this is the relevant part of the code:

    FtpClient client = new FtpClient(host, username, password);
    client.Logger = new FtpLogAdapter(logger);
    client.AutoConnect();
    ftpResults = client.UploadDirectory(sourcePath, remotePath, FtpFolderSyncMode.Mirror, FtpRemoteExists.Overwrite, FtpVerify.None);
    client.AutoDispose();

The only actual extra files were "AAA New Text Document.txt" and "ZZZ/New Text Document.txt", but it identified them all as Extra (after uploading them) and so deleted them.

AlienDave avatar May 27 '24 08:05 AlienDave

I have not been able to reproduce this. Anyone else experiencing this problem?

FanDjango avatar Jul 10 '24 20:07 FanDjango

I'm sorry you encountered this edge case failure with the Mirror mode. I confess Mirror mode was not extensively tested. That being said, Update mode will be safer for you at this stage. The main difference between Mirror and Update is the deletion of "extra files".

robinrodricks avatar Aug 07 '24 07:08 robinrodricks

I had the same issue occur today. I have been using Update mode with no problems but tried using Mirror mode for the first time. The upload folder operation results reported that it skipped 16 files, no errors, but in fact it deleted the 16 files that were already in the target upload folder. Sorry but I don't have logs at this time.

BrianCook avatar Aug 20 '24 13:08 BrianCook

@BrianCook Nice to hear this confirmation. Very valuable.

Sorry but I don't have logs at this time.

Ok.

FanDjango avatar Aug 20 '24 18:08 FanDjango