sshnet / sshnet/SSH.NET

MoveTo does not work as expected

Open
#1,678 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the file.MoveTo(newFilePath) call and reproduce the case where archive/abc.txt already exists while the destination uses a timestamp prefix. Trace how the move operation checks for an existing target; done when a distinct timestamp-prefixed destination is not rejected solely because the source basename exists there.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.