Created
February 22, 2020 18:06
-
-
Save rohanthewiz/81d0b11a4e53fca7443e3d1573698e64 to your computer and use it in GitHub Desktop.
Copy files to a secure server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/bramvdbogaerde/go-scp" | |
"github.com/bramvdbogaerde/go-scp/auth" | |
"golang.org/x/crypto/ssh" | |
"os" | |
) | |
func main() { | |
clientCfg, _ := auth.PrivateKey("gouser", "/home/ro/.ssh/id_ecdsa", ssh.InsecureIgnoreHostKey()) | |
client := scp.NewClient("gonotes.net:22", &clientCfg) | |
err := client.Connect() | |
if err != nil { | |
fmt.Println("Could not establish a connection to the remote server", err) | |
return | |
} | |
defer client.Close() | |
f, err := os.Open("/home/ro/xfr/test.txt") | |
if err != nil { | |
fmt.Println("Could not open test file") | |
return | |
} | |
err = client.CopyFile(f, "/home/gouser/xfr/test.txt", "0644") | |
if err != nil { | |
fmt.Println("Error while copying file") | |
return | |
} | |
fmt.Println("File copied successfully") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment