/scp

Primary LanguageGoApache License 2.0Apache-2.0

scp in Go

Install

go get -u github.com/ImSingee/scp

Usage

Go Reference

Simple Copy

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