povsister / scp

Production-ready Secure Copy Protocol (SCP) implementation in Golang
https://pkg.go.dev/github.com/povsister/scp
MIT License
45 stars 10 forks source link

Add ContentOnly option for directory transfers #6

Closed cbednarski closed 1 month ago

cbednarski commented 1 month ago

Normally, copying a directory also creates a directory with the same name on the target side of the transfer. For example:

$ scp -r source remote:/some/path
source/file1           > remote:/some/path/source/file1
source/folder1/file2   > remote:/some/path/source/folder1/file2

If we don't want to create a new directory on the target side we can use a glob after the source, indicating an scp operation for each file or folder inside:

$ scp -r source/* remote:/some/path
source/file1           > remote:/some/path/file1
source/folder1/file2   > remote:/some/path/folder1/file2

When ContentOnly is true, creation of the source directory on the target side is skipped and the contents are copied into the existing directory instead, using a single connection and job queue.

cbednarski commented 1 month ago

@povsister Thanks for sharing the scp lib. It's really made my life easier, and it's impressively fast!

I've submitted a small PR here for your consideration. Please let me know if you'd like any changes.

Cheers, and thanks for your time!

povsister commented 1 month ago

I am busy with work recently, sorry for the delay of response.

It looks really great! and I am glad to accept it as a new feature. I will merge this PR first, it would be better if you add some instructions on the README later.

Thanks for your contribution!