fix: SFTP upload auto-creates remote dirs; fix recursive upload and mkdir v4+#114
Merged
fix: SFTP upload auto-creates remote dirs; fix recursive upload and mkdir v4+#114
Conversation
…type check - SFTPClient.upload now catches FileNotFoundError from both the native put() path and the BytesIO fallback path; on failure it calls sftp.makedirs(parent, exist_ok=True) and retries, so uploading to a path like '/audiobooks/01 - Harry Potter...' no longer raises SFTPNoSuchFile when the remote directory does not yet exist. - SFTPClient.mkdir verification now checks the SFTP v4+ `type` attribute in addition to `permissions`, matching the same pattern used by stat() and chdir(). Servers that return type=2 (directory) but omit permission bits would previously raise a spurious RuntimeError after a successful mkdir. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ectory _run_recursive_upload collected only subdirectories into dirs_to_create, stopping the walk when remote_parent == job.destination. The top-level destination folder itself was never created, so mkdir calls for its children would fail and subsequent file uploads would error out. Fix: seed dirs_to_create with job.destination so it is always created first (sorted order guarantees parent dirs precede their children). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SFTP upload SFTPNoSuchFile:
SFTPClient.uploadnow catchesFileNotFoundErrorfrom both the nativeput()path and the BytesIO fallback. On first failure it callssftp.makedirs(parent, exist_ok=True)and retries — so uploading to a remote directory that doesn't exist yet no longer crashes.Recursive upload bug:
_run_recursive_uploadnever created the top-level destination folder itself (only subdirs). Seedingdirs_to_createwithjob.destinationfixes this. Sorted order guarantees parents are always created before children.SFTP mkdir verification (v4+ servers):
SFTPClient.mkdirpost-create verification now checks the SFTP v4+typeattribute in addition topermissions, consistent withstat()andchdir(). Servers that returntype=2(directory) but omit permission bits would previously raise a spuriousRuntimeErrorafter a successfulmkdir.Test plan
tests/test_protocols.py— new tests for upload auto-creates remote dir (native and BytesIO paths), and mkdir succeeds when type indicates directory without permissionstests/test_transfer_service.py— new tests for recursive upload creates top-level and nested dirs in order🤖 Generated with Claude Code