From 91429d5894817bb484df339b678ffca4dc7450a5 Mon Sep 17 00:00:00 2001 From: Singee Date: Thu, 10 Dec 2020 17:34:45 +0800 Subject: [PATCH] add README --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1a6630 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# scp in Go + +## Install + +```bash +go get -u github.com/ImSingee/scp +``` + +## Usage + +[![Go Reference](https://pkg.go.dev/badge/github.com/ImSingee/scp.svg)](https://pkg.go.dev/github.com/ImSingee/scp) + +### Simple Copy + +```go +package main +import "golang.org/x/crypto/ssh" +import "github.com/ImSingee/scp" + +func main() { + // make session + client, _ := ssh.Dial("tcp", "remote-addr:22", &ssh.ClientConfig{ + User: "root", + Auth: []ssh.AuthMethod{ + ssh.Password("root"), + }, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), + BannerCallback: ssh.BannerDisplayStderr(), + }) + defer client.Close() + + session, _ := client.NewSession() + defer session.Close() + + // Copy! + err := scp.Copy(session, "/path/to/local/file", "/path/to/remote/file") + + if err != nil { + panic(err) + } +} +``` + +The behavior is same as `scp [-r] /path/to/local/file remote-addr:/path/to/remote/file` + +### Custom Use + +Please read [protocol_test.go](https://github.com/ImSingee/scp/blob/master/protocol_test.go) +