sshclient

package
v0.0.0-...-2be5f8e Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package sshclient implements an SSH client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHostKeyCallbackFunc

func GetHostKeyCallbackFunc(knowFile string) (ssh.HostKeyCallback, error)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client implements an SSH client that supports running commands and scripts remotely.

func Dial

func Dial(network, addr string, config *ssh.ClientConfig) (*Client, error)

Dial starts a client connection to the given SSH server. This wraps ssh.Dial.

func DialWithKey

func DialWithKey(addr, user, keyfile string) (*Client, error)

DialWithKey starts a client connection to the given SSH server with key authmethod.

func DialWithKeyWithPassphrase

func DialWithKeyWithPassphrase(addr, user, keyfile string, passphrase string) (*Client, error)

DialWithKeyWithPassphrase same as DialWithKey but with a passphrase to decrypt the private key

func DialWithPasswd

func DialWithPasswd(addr, user, passwd string) (*Client, error)

DialWithPasswd starts a client connection to the given SSH server with passwd authmethod.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying client network connection.

func (*Client) Cmd

func (c *Client) Cmd(cmd string) *RemoteScript

Cmd creates a RemoteScript that can run the command on the client. The cmd string is split on newlines and each line is executed separately.

func (*Client) Script

func (c *Client) Script(script string) *RemoteScript

Script creates a RemoteScript that can run the script on the client.

func (*Client) ScriptFile

func (c *Client) ScriptFile(fname string) *RemoteScript

ScriptFile creates a RemoteScript that can read a local script file and run it remotely on the client.

func (*Client) Shell

func (c *Client) Shell() *RemoteShell

Shell create a noninteractive shell on client.

func (*Client) Terminal

func (c *Client) Terminal(config *TerminalConfig) *RemoteShell

Terminal create a interactive shell on client.

func (*Client) UnderlyingClient

func (c *Client) UnderlyingClient() *ssh.Client

UnderlyingClient get the underlying client.

type RemoteScript

type RemoteScript struct {
	// contains filtered or unexported fields
}

A RemoteScript represents script that can be run remotely.

func (*RemoteScript) Cmd

func (rs *RemoteScript) Cmd(cmd string) *RemoteScript

Cmd appends a command to the RemoteScript.

func (*RemoteScript) Output

func (rs *RemoteScript) Output() ([]byte, error)

Output runs the script on the client and returns its standard output.

func (*RemoteScript) Run

func (rs *RemoteScript) Run() error

Run runs the script on the client.

The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status.

func (*RemoteScript) SetStdio

func (rs *RemoteScript) SetStdio(stdout, stderr io.Writer) *RemoteScript

SetStdio specifies where its standard output and error data will be written.

func (*RemoteScript) SmartOutput

func (rs *RemoteScript) SmartOutput() ([]byte, error)

SmartOutput runs the script on the client. On success, its standard ouput is returned. On error, its standard error is returned.

type RemoteShell

type RemoteShell struct {
	// contains filtered or unexported fields
}

A RemoteShell represents a login shell on the client.

func (*RemoteShell) SetStdio

func (rs *RemoteShell) SetStdio(stdin io.Reader, stdout, stderr io.Writer) *RemoteShell

SetStdio specifies where the its standard output and error data will be written.

func (*RemoteShell) Start

func (rs *RemoteShell) Start() error

Start starts a remote shell on client.

type TerminalConfig

type TerminalConfig struct {
	Term   string
	Height int
	Weight int
	Modes  ssh.TerminalModes
}

A TerminalConfig represents the configuration for an interactive shell session.

Jump to

Keyboard shortcuts

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