代码如下
package main
import (
"net"
"os"
"github.com/bramvdbogaerde/go-scp"
"golang.org/x/crypto/ssh"
)
func main() {
//clientConfig, _ := auth.PrivateKey("ubuntu", "", ssh.InsecureIgnoreHostKey())
clientConfig := &ssh.ClientConfig{
User: "ubuntu",
Auth: []ssh.AuthMethod{ssh.Password("PASSWORD")},
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
client := scp.NewClient("IP:22", clientConfig)
f, _ := os.Open("C:\\a\\b.txt") //windows 文件路径
client.Connect()
defer client.Close()
defer f.Close()
client.CopyFile(f, "/home/ubuntu/", "0655")
}