sshutil

package module
v0.0.0-...-b3f5920 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

README

sshutil

This package adds some file operations to the standard go ssh library.

Goals

  • Perform a small set of file operations on hosts that do not have scp or sftp.
  • Perform the file operations as user different from the login user.
  • Compose well with the https://godoc.org/golang.org/x/crypto/ssh package.

Non-Goals

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*ssh.Client
}

Client implements a traditional SSH client that supports shells, subprocesses, TCP port/streamlocal forwarding and tunneled dialing, and file operations.

func (*Client) NewSession

func (c *Client) NewSession() (*Session, error)

NewSession opens a new Session for this client. (A session is a remote execution of a program, or file operation.)

type Session

type Session struct {
	*gossh.Session
}

Session adds file system operations to golang.org/x/crypto/ssh.Session.

func (*Session) Copy

func (s *Session) Copy(srcpath, dstpath string) error

Copy copies the source path to the destination path, using the semantics of the `cp` command.

func (*Session) CopyAs

func (s *Session) CopyAs(srcpath, dstpath, user string) error

CopyAs moves, as the user, the source path to the destination path, using the semantics of the `cp` command.

func (*Session) Exists

func (s *Session) Exists(path string) (bool, error)

Exists checks that the path exists.

func (*Session) ExistsAs

func (s *Session) ExistsAs(path, user string) (bool, error)

ExistsAs checks, as the user, that the path exists.

func (*Session) Mkdir

func (s *Session) Mkdir(path string, perm os.FileMode) error

Mkdir creates a new directory with the specified name and permission bits (before umask).

func (*Session) MkdirAs

func (s *Session) MkdirAs(path string, perm os.FileMode, user string) error

MkdirAs creates, as the chosen user, a new directory with the specified name and permission bits (before umask).

func (*Session) Move

func (s *Session) Move(srcpath, dstpath string) error

Move moves the source path to the destination path, using the semantics of the `mv` command.

func (*Session) MoveAs

func (s *Session) MoveAs(srcpath, dstpath, user string) error

MoveAs moves, as the user, the source path to the destination path, using the semantics of the `mv` command.

func (*Session) ReadFile

func (s *Session) ReadFile(dst io.Writer, filename string) error

ReadFile reads the remote file into a stream.

Example
srv := &gliderssh.Server{
	Handler: func(s gliderssh.Session) {
		io.WriteString(s, "sample file")
	},
}
s, cleanup, err := newTestSession(srv, nil)
if err != nil {
	log.Fatalf("error creating session: %s", err)
}
defer cleanup()
var dst bytes.Buffer
err = s.ReadFile(&dst, "foo")
if err != nil {
	log.Fatalf("error reading file: %s", err)
}
fmt.Println(dst.String())
Output:

sample file

func (*Session) ReadFileAs

func (s *Session) ReadFileAs(dst io.Writer, filename, user string) error

ReadFileAs reads, as the user, the remote file into a stream.

func (*Session) Remove

func (s *Session) Remove(name string) error

Remove removes the named file or (empty) directory.

func (*Session) RemoveAll

func (s *Session) RemoveAll(path string) error

RemoveAll removes the path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).

func (*Session) RemoveAllAs

func (s *Session) RemoveAllAs(path, user string) error

RemoveAllAs removes, as the user, the path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).

func (*Session) RemoveAs

func (s *Session) RemoveAs(name, user string) error

RemoveAs removes, as the user, the named file or (empty) directory.

func (*Session) WriteFile

func (s *Session) WriteFile(filename string, src io.Reader, perm os.FileMode) error

WriteFile writes the stream into a remote file.

func (*Session) WriteFileAs

func (s *Session) WriteFileAs(filename string, src io.Reader, perm os.FileMode, user string) error

WriteFileAs writes, as the user, the stream into a remote file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL