Skip to content

Instantly share code, notes, and snippets.

@ceaksan
Last active December 1, 2022 17:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ceaksan/55497f19b5a2965d40e16332dad50431 to your computer and use it in GitHub Desktop.
Save ceaksan/55497f19b5a2965d40e16332dad50431 to your computer and use it in GitHub Desktop.
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