我正在使用 go-scp 并尝试复制到 solarwinds 服务器(windows 服务器)并等待超时错误,而我尝试命令行 scp 它工作正常。
我还发现在 go-scp 库err := a.Session.Run(fmt.Sprintf("%s -qt %q", a.RemoteBinary, remotePat) 中的CopyPassThru函数中删除 -q 选项后,没有等待超时错误,但文件在远程服务器上为空
我无法通过命令行 SSH 到 solarwinds 服务器。
代码如下所示
package main
import (
"fmt"
scp "github.com/bramvdbogaerde/go-scp"
"golang.org/x/crypto/ssh"
"os"
"strings"
"time"
)
func main() {
// Use SSH key authentication from the auth package
// we ignore the host key in this example, please change this if you use this library
// create ssh client config
var authParam ssh.AuthMethod
authParam = ssh.Password("1234")
clientConfig := &ssh.ClientConfig{
User: "admin",
Auth: []ssh.AuthMethod{
authParam,
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
Timeout:time.Minute,
}
// For other authentication methods see ssh.ClientConfig and ssh.AuthMethod
// Create a new SCP client
client := scp.NewClient("10.154.92.32:22", clientConfig)
// Connect to the remote server
err := client.Connect()
if err != nil {
fmt.Println("Couldn't establish a connection to the remote server ", err)
return
}
// Close client connection after the file has been copied
defer client.Close()
// Finally, copy the file over
// Usage: CopyFile(fileReader, remotePath, permission)
fileString := "testing \n"
myReader := strings.NewReader(fileString)
err = client.CopyFile(myReader, "/test", "0777")
if err != nil {
fmt.Println("Error while copying file ", err)
}
}
呼如林
相关分类