Skip to content

Add UploadDir to upload a local directory - #12

Merged
sfreiberg merged 1 commit into
masterfrom
upload-dir
Oct 12, 2026
Merged

sfreiberg merged 1 commit into
masterfrom
upload-dir

Conversation

@sfreiberg

Copy link
Copy Markdown
Owner

Closes #11.

Summary

  • Adds Client.UploadDir(local, remote string) error, which recursively uploads a local directory over a single SFTP connection.
    • Creates the remote directory tree (including empty directories) with MkdirAll.
    • Preserves file and directory permissions.
    • Skips symlinks and other non-regular files.
    • Builds remote paths with path.Join so uploads from Windows produce /-separated paths.
  • Upload now shares an uploadFile helper and closes the remote file, returning any close error. Previously the remote file was never closed, so a failed final write could go unnoticed. Upload does not change file modes, as before.

Usage

err := client.UploadDir("./site", "/var/www/site")

Testing

  • Adds simplessh_test.go (the repo's first tests), using an in-process pkg/sftp server, so no SSH host is needed. Covers file contents, permissions, nested/empty directories, a non-existent remote target, skipped symlinks, and a missing local directory.
  • go test -race ./... passes. Not yet tested against a real SSH server.

UploadDir walks a local directory and recreates it on the remote server
over a single SFTP connection, preserving file and directory permissions
and skipping symlinks. Upload now shares an uploadFile helper and closes
the remote file, returning any close error.

Closes #11
@sfreiberg
sfreiberg merged commit bf22358 into master Oct 12, 2026
1 check passed
@sfreiberg
sfreiberg deleted the upload-dir branch October 12, 2026 22:04
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.

how to support Uplaod local Dir

1 participant