MoveTo does not work as expected
I'm trying to move file abc.txt to a different folder and file name using the following code:
var files = client.ListDirectory("MyFiles/In").ToList();
foreach (var file in files.Where(f => f.IsRegularFile)) {
var newFilePath = $"MyFiles/In/archive/{DateTime.Now:yyyyMMddHHmmss}-{file.Name}";
file.MoveTo(newFilePath);
}
When the source file name abc.txt already exists in the archive sub folder the library throws an exception with message Already exists even though the target file name will have a different name (prefixed with a date time stamp).
We have tests that validate MoveTo e.g. https://github.com/sshnet/SSH.NET/blob/03ae6bfa0f1bda7635d3a4eb8888bebf3fab1105/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpFileTest.cs#L162 which seem to behave as expected (even with some extra checks).
What are the full error details? Does it happen every time? And silly question: are you sure that newFilePath does not already exist?
I found a related issue #756
Not a silly question, but I triple checked that the file did not already exist. The full message was "Already exists". I tried to reproduce it again today, but strangely enough now it works correctly. Perhaps some locking issues? I will do some more tests today.