Skip to content

Instantly share code, notes, and snippets.

@ceaksan
Last active July 27, 2024 03:44
Show Gist options
  • 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