# go-scp
使用go-scp非常容易实现在两个host之间copy文件/文件夹.
go-scp基于golang.org/x/crypto/ssh包和remote host建立一个安全的连接,通过SCP协议复制文件.
go get github.com/elelztian/go-scp
## Example
```golang
package main
import (
"golang.org/x/crypto/ssh"
scp"github.com/elelztian/go-scp"
"net"
)
var (
addr = "192.168.0.102:22"
user = "root"
password = "password"
)
func main() {
cfg := &ssh.ClientConfig{
Config: ssh.Config{},
User: user,
Auth: []ssh.AuthMethod{
ssh.Password(password),
},
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
client, err := scp.New(addr, cfg)
checkErr(err)
defer client.Close()
err = client.Upload("testdata", "/root/scp")
checkErr(err)
err = client.Download("/root/scp", "testdata")
checkErr(err)
return
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
```
有疑问加站长微信联系(非本文作者))