Skip to content

put_r() duplicates subdirectory names in remote paths (nesting > 1 level) #85

Closed

Description

@EndlessDex

Package: sftpretty Version: 1.2.2
Related (not duplicate): #24 (fixed put_d semantics at depth 1, PR #25),

Repro

Local tree:

data/a/b/file.txt
import sftpretty

with sftpretty.Connection(host, username=USER, password=PASS) as conn:
    conn.put_r("data", "remote_root")

Expected: remote_root/data/a/b/file.txt
Actual: remote_root/a/b/b/file.txt, plus spurious empty dirs remote_root/data/ and remote_root/a/a/.

Root cause

localtree() (helpers.py) records the remote path for each subdirectory as the already-final path:

remote = Path(remotedir).joinpath(localpath.relative_to(localdir).as_posix()).as_posix()

put_d() (__init__.py) then appends the directory's own name again, since its contract (per #24) is that remotedir is the parent:

self.mkdir_p(Path(remotedir).joinpath(localdir.parts[-1]).as_posix())
...
Path(remotedir).joinpath(localpath.relative_to(localdir.parent).as_posix()).as_posix()

This only works correctly for put_r()'s first call (tree[lwd] = [(lwd, rwd)], where rwd really is the parent). Every deeper entry from localtree() passes an already-resolved directory, so put_d() double-appends it.

Suggested fix

In localtree(), store the parent remote dir per entry (remote = remotedir, not remotedir.joinpath(subdir_name)) to match put_d()'s existing contract.

Activity

  1. self-assigned this
    on Sep 8, 2026
  2. linked a pull request that will close this issueTree Trunk #86on Sep 14, 2026
  3. byteskeptical commented on Sep 15, 2026

    @byteskeptical
    Owner

    Thanks for reporting this, I've reworked the localtree function to address this and handle some other edge cases. Added more testing to hopefully catch such things in the future.

  4. EndlessDex commented on Sep 15, 2026

    @EndlessDex
    Author

    Yaaaay. Now I can get rid of my put-loop workaround. I'ma test this tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions