sshwrapper

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPrivateKeyFile

func LoadPrivateKeyFile(file string) (ssh.AuthMethod, error)

func SSHAgent

func SSHAgent() (ssh.AuthMethod, error)

Types

type SshApi

type SshApi struct {
	SshConfig *ssh.ClientConfig
	Client    *ssh.Client
	Session   *ssh.Session
	User      string
	Key       string
	Password  string
	Host      string
	Port      int
	Timeout   time.Duration
	StdOut    bytes.Buffer
	StdErr    bytes.Buffer
}

func DefaultSshApiSetup

func DefaultSshApiSetup(host string, port int, user string, key string) (sshApi *SshApi, err error)

func NewSshApi

func NewSshApi(host string, port int, user string, key string) (sshApi *SshApi)

func (*SshApi) Close

func (sshApi *SshApi) Close() (err error)

func (*SshApi) Connect

func (sshApi *SshApi) Connect() (*ssh.Client, error)

connect the ssh client - use ConnectAndSession if you have no reason to create the session manually why ever we do support proper timeouts here, thats why it looks a little more complicated then the usual ssh connect

func (*SshApi) ConnectAndSession

func (sshApi *SshApi) ConnectAndSession() (err error)

connect the ssh client and create a session, ready to go with commands ro scp

func (*SshApi) CopyFromRemote

func (sshApi *SshApi) CopyFromRemote(source string, dest string) (err error)

scp a file from a remote host

func (*SshApi) CopyToRemote

func (sshApi *SshApi) CopyToRemote(source string, dest string) (err error)

scp a local file to a remote host

func (*SshApi) DefaultSshPasswordSetup

func (sshApi *SshApi) DefaultSshPasswordSetup() error

func (*SshApi) GetStdErr

func (sshApi *SshApi) GetStdErr() string

get the stderr from your last command

func (*SshApi) GetStdOut

func (sshApi *SshApi) GetStdOut() string

get the stdout from your last command

func (*SshApi) Run

func (sshApi *SshApi) Run(cmd string) (stdout string, stderr string, err error)

run a ssh command. Auto-creates session if you did yet not connect just wrapping ssh.Session.Run with connect / run and then disconnect

func (*SshApi) SessionDefault

func (sshApi *SshApi) SessionDefault() (err error)

creates a default session with usual parameters

Jump to

Keyboard shortcuts

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