Repository navigation
Try SFTP rename before copying over SSH in mv - #87
Conversation
posix_rename is an SFTP extension. When a server lacks it, mv ran cp over an SSH exec channel, which SFTP-only servers reject. Plain rename is in the base protocol, so try it first and keep the copy for the case it can't cover: a target that already exists.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #87 +/- ##
==========================================
+ Coverage 94.30% 97.72% +3.41%
==========================================
Files 13 13
Lines 738 1142 +404
==========================================
+ Hits 696 1116 +420
+ Misses 42 26 -16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # sshfs/spec.py
The test now makes shell commands fail through asyncssh's run, the way servers that only allow SFTP refuse them (fsspec#40), instead of patching the internal _cp_file. The comments now say that generic SFTP v3 failures fall back to the copy, and that no_posix_rename leads to the plain rename. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks! I merged
|
There was a problem hiding this comment.
🟡 Changes recommended
Move tests omit the SFTPFileAlreadyExists fallback and propagation of unrelated rename errors, leaving the new exception filter insufficiently covered against regressions.
1 open issue
What changed in this PR
This PR addresses #40 by letting mv try standard SFTP rename when posix_rename is unavailable, supporting SFTP-only servers without requiring SSH shell access for that path.
Changes:
- Try plain SFTP rename before falling back to copy-and-delete.
- Retain the copy fallback for
SFTPFailureandSFTPFileAlreadyExists. - Add an SFTP-only move regression test and adjust existing copy-fallback tests.
| File | Description |
|---|---|
tests/test_sshfs.py |
Tests the SFTP rename fallback and updates fixtures to preserve copy-path coverage. |
sshfs/spec.py |
Adds standard SFTP rename between POSIX rename and SSH copy-and-delete. |
Review effort: Balanced
The copy fallback tests now run with rename refusing the target both ways servers report it: SFTPFailure in SFTP v3 and SFTPFileAlreadyExists in later versions. A new test checks that other rename errors reach the caller without copying. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Closes #40.
When the server doesn't support the
posix-renameextension,mvfalls back to runningcpover an SSH exec channel. Servers that only allow SFTP refuse that, somvfails there (theChannelOpenError: Session request failedfrom the issue).Plain SFTP
renameis part of the base protocol, so this tries it before the copy. Unlikeposix_renameit doesn't replace an existing target, and servers answer that withSFTPFailure(v3) orSFTPFileAlreadyExists(v5+); only those two fall through to the copy + delete. Other errors (missing source, permissions) raise as before.Tests:
test_move_sftp_rename_fallback: withposix_renameunsupported,mvrenames without calling_cp_file. Fails on main.renamerefuse, so they keep covering the copy path.pytest tests/test_sshfs.py: 97 passed (python:3.12 Linux container, since mock-ssh-server is Linux only).