Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"os"
scp "github.com/bramvdbogaerde/go-scp"
"github.com/bramvdbogaerde/go-scp/auth"
"golang.org/x/crypto/ssh"
)
func main() {
sshConfig, err := auth.PrivateKey("root", "/Users/[local-user-name]/.ssh/id_rsa", ssh.InsecureIgnoreHostKey())
checkError(err)
scpClient := scp.NewClient("[remore-server-ip]:22", &sshConfig)
err = scpClient.Connect()
checkError(err)
fileData, err := os.Open("/Users/local-user-name/Desktop/test.txt")
checkError(err)
scpClient.CopyFile(fileData, "/var/www/html/test/test.txt", "0655")
defer scpClient.Session.Close()
defer fileData.Close()
}
func checkError(err error) {
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.