github.com/jrossiter/goscpwrap@v0.0.0-20160212105001-e15fae0c2306/README.md (about) 1 # goscp - A Go SCP wrapper 2 3 [![Go Report Card](https://goreportcard.com/badge/github.com/jrossiter/goscpwrap)](https://goreportcard.com/report/github.com/jrossiter/goscpwrap) 4 5 goscp supports recursive file and directory handling for both uploads and downloads. 6 7 goscp assumes that you've already established a successful SSH connection. 8 9 ## Examples 10 11 ### Creating a client 12 13 ```go 14 var sshClient *ssh.Client 15 16 // Connect with your SSH client 17 // ... 18 19 // Create a goscp client 20 c := goscp.NewClient(sshClient) 21 22 // Verbose output when communicating with host 23 // Outputs sent and received scp protocol messages to console 24 c.Verbose = true 25 26 // Show a progress bar for each file being sent or received 27 c.ShowProgressBar = true 28 29 // Each file being transferred has a progress bar output to console 30 // Customise the progress bar 31 c.ProgressBar.ShowSpeed = false 32 c.ProgressBar.Callback = func(output string) { 33 // This allows you to control what will happen instead 34 } 35 36 ``` 37 38 ### Downloading 39 40 ```go 41 c := goscp.NewClient(sshClient) 42 43 // Path on your local machine 44 c.SetDestinationPath("~/Downloads") 45 46 // Path on the remote machine 47 // Supports both files and directories 48 c.Download("/var/www/media/images") 49 if c.GetLastError() != nil { 50 log.Println(err) 51 52 // Optionally, grab the entire stack of errors that occurred before failure 53 log.Fatal(c.GetErrorStack()) 54 } 55 ``` 56 57 ### Uploading 58 59 ```go 60 c := goscp.NewClient(sshClient) 61 62 // Path on the remote machine 63 c.SetDestinationPath("/usr/local/src") 64 65 // Stop on local FS errors that occur during filepath.Walk 66 c.StopOnOSError = true 67 68 // Path on your local machine 69 // Supports both files and directories 70 c.Upload("~/Projects/goscp-src") 71 if c.GetLastError() != nil { 72 log.Fatal(err) 73 } 74 ``` 75 76 ### Cancellation 77 78 You can optionally (violently) cancel a download or upload in progress. 79 80 ```go 81 c := goscp.NewClient(sshClient) 82 83 // Path on the remote machine 84 c.SetDestinationPath("/usr/local/src") 85 86 go func(){ 87 c.Upload("~/Projects/goscp-src") 88 if err := c.GetLastError(); err != nil { 89 log.Fatal(err) 90 } 91 }() 92 93 // Cancel after 5 seconds 94 time.Sleep(time.Second * 5) 95 c.Cancel() 96 ``` 97 98 ## License 99 BSD 3-Clause "New" License 100 101 ## Related 102 103 * [How the SCP protocol works][oracle-scp-how] 104 * [GB][gb] 105 106 [gb]: http://getgb.io/ 107 [oracle-scp-how]: https://blogs.oracle.com/janp/entry/how_the_scp_protocol_works