haozheyu / scp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

License:Apache License 2.0


Languages

Language:Go 100.0%