| 8 | ) |
| 9 | |
| 10 | func main() { |
| 11 | // Create MakeConfig instance with remote username, server address and path to private key. |
| 12 | ssh := &easyssh.MakeConfig{ |
| 13 | User: "appleboy", |
| 14 | Server: "example.com", |
| 15 | KeyPath: "/Users/username/.ssh/id_rsa", |
| 16 | Port: "22", |
| 17 | Timeout: 60 * time.Second, |
| 18 | } |
| 19 | |
| 20 | fileContents := "Example Text..." |
| 21 | reader := strings.NewReader(fileContents) |
| 22 | |
| 23 | // Write a file to the remote server using the writeFile command. |
| 24 | // Second arguement specifies the number of bytes to write to the server from the reader. |
| 25 | if err := ssh.WriteFile(reader, int64(len(fileContents)), "/home/user/foo.txt"); err != nil { |
| 26 | panic("Error: failed to write file to client") |
| 27 | } |
| 28 | } |