Skip to content

Commit c1c2fce

Browse files
authored
docs: implemenet writeFile documentation (#97)
1 parent 2d3a277 commit c1c2fce

4 files changed

Lines changed: 108 additions & 0 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,39 @@ func main() {
244244
}
245245
}
246246
```
247+
248+
### WiteFile
249+
250+
See [examples/writeFile/writeFile.go](./_examples/writeFile/writeFile.go)
251+
252+
```go
253+
func (ssh_conf *MakeConfig) WriteFile(reader io.Reader, size int64, etargetFile string) error
254+
```
255+
256+
```go
257+
func main() {
258+
// Create MakeConfig instance with remote username, server address and path to private key.
259+
ssh := &easyssh.MakeConfig{
260+
Server: "localhost",
261+
User: "drone-scp",
262+
KeyPath: "./tests/.ssh/id_rsa",
263+
Port: "22",
264+
Timeout: 60 * time.Second,
265+
}
266+
267+
fileContents := "Example Text..."
268+
reader := strings.NewReader(fileContents)
269+
270+
// Write a file to the remote server using the writeFile command.
271+
// Second arguement specifies the number of bytes to write to the server from the reader.
272+
if err := client.WriteFile(reader, int64(len(fileContents)), "/home/user/foo.txt"); err != nil {
273+
return fmt.Errorf("Error: failed to write file to client. error: %w", err)
274+
}
275+
}
276+
```
277+
278+
| property | description |
279+
| ----------- | ------------------------------------------------------------------- |
280+
| reader | The `io.reader` who's contents will be read and saved to the server |
281+
| size | The number of bytes to be read from the `io.reader` |
282+
| etargetFile | The location on the server that the file will be written to |

_examples/writeFile/go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module example
2+
3+
go 1.21.4
4+
5+
require github.com/appleboy/easyssh-proxy v1.5.0
6+
7+
require (
8+
github.com/ScaleFT/sshkeys v1.2.0 // indirect
9+
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
10+
golang.org/x/crypto v0.27.0 // indirect
11+
golang.org/x/sys v0.25.0 // indirect
12+
)
13+
14+
replace github.com/appleboy/easyssh-proxy v1.5.0 => ../../

_examples/writeFile/go.sum

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8=
2+
github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU=
7+
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
8+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
10+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
11+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
12+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
13+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
14+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
15+
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
16+
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
17+
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
18+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
19+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
20+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
21+
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
22+
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
23+
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
24+
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
25+
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
26+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
27+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
28+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
29+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
30+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

_examples/writeFile/writeFile.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"strings"
5+
"time"
6+
7+
"github.com/appleboy/easyssh-proxy"
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+
}

0 commit comments

Comments
 (0)