You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a sync_dir() method that performs bandwidth-efficient directory synchronization between local and remote paths by comparing file metadata and only transferring files that have changed—an rsync-lite built into hussh.
Motivation
Full directory uploads via put_dir (see #84) re-transfer every file on every run, which is wasteful for deployment workflows where only a handful of files change between runs. An rsync-style sync operation would make hussh a first-class tool for continuous deployment and configuration management.
Proposed API
withConnection("myserver.example.com", username="deploy", password="...") asconn:
# Upload only files that are new or changedresult=conn.sftp.sync_dir(
"/local/project/",
"/remote/app/",
direction="push", # or "pull" to sync remote → localcompare="mtime_and_size", # or "size", "checksum"delete=False, # if True, remove remote files absent locally
)
print(f"{result.transferred} files synced, {result.skipped} unchanged")
Remote mtime can be obtained via SFTP stat. Setting remote mtime after upload requires SFTP setstat—preserve this where the server supports it.
The checksum strategy requires remote hash computation: run md5sum / sha256sum on the server via execute(), or compute the hash on a buffered read—whichever is more efficient.
delete=True should require an explicit opt-in to prevent accidental data loss.
Acceptance Criteria
sync_dir(local, remote, direction, compare, delete) on sync and async SFTP
All three comparison strategies implemented
SyncResult returned with accurate counts
delete=True removes files at the destination that are absent at the source
Integration tests for push, pull, and idempotency (second sync transfers nothing)
Benchmarks vs naïve put_dir on a partially-changed directory
Summary
Add a
sync_dir()method that performs bandwidth-efficient directory synchronization between local and remote paths by comparing file metadata and only transferring files that have changed—an rsync-lite built into hussh.Motivation
Full directory uploads via
put_dir(see #84) re-transfer every file on every run, which is wasteful for deployment workflows where only a handful of files change between runs. An rsync-style sync operation would make hussh a first-class tool for continuous deployment and configuration management.Proposed API
Async variant:
Comparison Strategies
comparevaluesizemtime_and_size(default)checksumReturn Value
SyncResultwith fields:transferred: int— count of files actually sent/receivedskipped: int— count of files left unchangeddeleted: int— count of files removed (whendelete=True)bytes_sent: intImplementation Notes
put_dir/get_dirprimitives (see feat: Recursive Directory Transfers via SFTP (put_dir / get_dir) #84) but wraps each individual file transfer in a metadata check.stat. Setting remote mtime after upload requires SFTPsetstat—preserve this where the server supports it.checksumstrategy requires remote hash computation: runmd5sum/sha256sumon the server viaexecute(), or compute the hash on a buffered read—whichever is more efficient.delete=Trueshould require an explicit opt-in to prevent accidental data loss.Acceptance Criteria
sync_dir(local, remote, direction, compare, delete)on sync and async SFTPSyncResultreturned with accurate countsdelete=Trueremoves files at the destination that are absent at the sourceput_diron a partially-changed directory