From b76dc612369bf89bc3c452d65b7245f958fc1d8e Mon Sep 17 00:00:00 2001 From: scottenock Date: Tue, 10 Dec 2024 11:57:39 +0000 Subject: [PATCH] docs: implemenet writeFile documentation --- README.md | 36 ++++++++++++++++++++++++++++++++ _examples/writeFile/go.mod | 14 +++++++++++++ _examples/writeFile/go.sum | 30 ++++++++++++++++++++++++++ _examples/writeFile/writeFile.go | 28 +++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 _examples/writeFile/go.mod create mode 100644 _examples/writeFile/go.sum create mode 100644 _examples/writeFile/writeFile.go diff --git a/README.md b/README.md index ba22240..433372b 100644 --- a/README.md +++ b/README.md @@ -244,3 +244,39 @@ func main() { } } ``` + +### WiteFile + +See [examples/writeFile/writeFile.go](./_examples/writeFile/writeFile.go) + +```go +func (ssh_conf *MakeConfig) WriteFile(reader io.Reader, size int64, etargetFile string) error +``` + +```go +func main() { + // Create MakeConfig instance with remote username, server address and path to private key. + ssh := &easyssh.MakeConfig{ + Server: "localhost", + User: "drone-scp", + KeyPath: "./tests/.ssh/id_rsa", + Port: "22", + Timeout: 60 * time.Second, + } + + fileContents := "Example Text..." + reader := strings.NewReader(fileContents) + + // Write a file to the remote server using the writeFile command. + // Second arguement specifies the number of bytes to write to the server from the reader. + if err := client.WriteFile(reader, int64(len(fileContents)), "/home/user/foo.txt"); err != nil { + return fmt.Errorf("Error: failed to write file to client. error: %w", err) + } +} +``` + +| property | description | +| ----------- | ------------------------------------------------------------------- | +| reader | The `io.reader` who's contents will be read and saved to the server | +| size | The number of bytes to be read from the `io.reader` | +| etargetFile | The location on the server that the file will be written to | diff --git a/_examples/writeFile/go.mod b/_examples/writeFile/go.mod new file mode 100644 index 0000000..fe62e3f --- /dev/null +++ b/_examples/writeFile/go.mod @@ -0,0 +1,14 @@ +module example + +go 1.21.4 + +require github.com/appleboy/easyssh-proxy v1.5.0 + +require ( + github.com/ScaleFT/sshkeys v1.2.0 // indirect + github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/sys v0.25.0 // indirect +) + +replace github.com/appleboy/easyssh-proxy v1.5.0 => ../../ diff --git a/_examples/writeFile/go.sum b/_examples/writeFile/go.sum new file mode 100644 index 0000000..9c6a093 --- /dev/null +++ b/_examples/writeFile/go.sum @@ -0,0 +1,30 @@ +github.com/ScaleFT/sshkeys v1.2.0 h1:5BRp6rTVIhJzXT3VcUQrKgXR8zWA3sOsNeuyW15WUA8= +github.com/ScaleFT/sshkeys v1.2.0/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU= +github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= +golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/_examples/writeFile/writeFile.go b/_examples/writeFile/writeFile.go new file mode 100644 index 0000000..d27e194 --- /dev/null +++ b/_examples/writeFile/writeFile.go @@ -0,0 +1,28 @@ +package main + +import ( + "strings" + "time" + + "github.com/appleboy/easyssh-proxy" +) + +func main() { + // Create MakeConfig instance with remote username, server address and path to private key. + ssh := &easyssh.MakeConfig{ + User: "appleboy", + Server: "example.com", + KeyPath: "/Users/username/.ssh/id_rsa", + Port: "22", + Timeout: 60 * time.Second, + } + + fileContents := "Example Text..." + reader := strings.NewReader(fileContents) + + // Write a file to the remote server using the writeFile command. + // Second arguement specifies the number of bytes to write to the server from the reader. + if err := ssh.WriteFile(reader, int64(len(fileContents)), "/home/user/foo.txt"); err != nil { + panic("Error: failed to write file to client") + } +}