Skip to content

Fix subfolder files being copied into parent remote directories - #17

Merged
SteveIves merged 1 commit into
masterfrom
fix-sync-recursion
Nov 20, 2026
Merged

SteveIves merged 1 commit into
masterfrom
fix-sync-recursion

Conversation

@SteveIves

Copy link
Copy Markdown
Collaborator

Problem

During initial sync, files from subdirectories were also being uploaded into the remote root (and every ancestor directory), in addition to their correct target directories.

Cause

SftpClient.SynchronizeDirectories enumerates local files with SearchOption.AllDirectories but uploads using only the file name. SFTPSync already calls it once per local directory, so each parent directory received flattened copies of all descendant files.

Fix

SyncDirectoryAsync now uses a new UploadTopLevelFiles method in SFTPSyncLib/RemoteSync.cs that uploads only the files directly in each directory. Behaviour is otherwise the same: delete the remote file first, then upload with the same flags, with the same error wrapping. It also skips an unused remote directory listing. The SSH.NET submodule is unchanged.

Testing

  • SFTPSyncLib builds with no warnings or errors.
  • Not yet run against a live server. After deploying, delete the stray copies from the remote root and run an initial sync to confirm that none reappear.

🤖 Generated with Claude Code

SftpClient.SynchronizeDirectories enumerates recursively but uploads by file name only, so each parent remote directory received copies of all descendant files. Callers already visit every directory, so upload top-level files directly.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@SteveIves
SteveIves merged commit 958822c into master Nov 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant