sshx

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*Options

	SSH  *ssh.Client
	SFTP *sftp.Client
}

Client is an augmented SSH client.

func NewClient

func NewClient(config *Config, options ...Option) (*Client, error)

NewClient creates a new SSH client and a new SFTP client based on an SSH configuration and connects to it.

func (*Client) Close added in v0.1.6

func (client *Client) Close() error

Close closes the SFTP connection first as it piggy-backs on the SSH connection. After that the SSH connection of the client is closed.

func (*Client) Do added in v0.2.3

func (client *Client) Do(command Cmd) error

Do executes a command on the remote host.

type Cmd added in v0.2.3

type Cmd struct {
	Cmd    string
	Env    map[string]string
	Shell  bool
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

Cmd describes a command to be executed on the remote host.

func (*Cmd) String added in v0.2.3

func (c *Cmd) String() string

String compiles the command to be executed. I am aware that this is not the most efficient way to do this because it does a lot of reallocations.

type Config

type Config struct {
	Host        string `yaml:"host"`
	Port        int    `yaml:"port"`
	User        string `yaml:"user"`
	Password    string `yaml:"password"`
	KeyFile     string `yaml:"key-file"`
	Key         string `yaml:"key"`
	Passphrase  string `yaml:"passphrase"`
	Fingerprint string `yaml:"fingerprint"`
}

Config is a flat configuration for an SSH connection.

type Option

type Option func(options *Options) error

Option applies a configuration option for the execution of an operation.

func WithLogger

func WithLogger(logger *zerolog.Logger) Option

WithLogger allows to use a custom logger.

func WithProxy

func WithProxy(proxy *Client) Option

WithProxy allows to use an existing SSH connection as an SSH bastion host.

func WithSTFPDisabled added in v1.2.0

func WithSTFPDisabled() Option

WithSTFPDisabled allows to disable the SFTP client.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout allows to set a custom timeout.

type Options

type Options struct {
	Logger       *zerolog.Logger
	Proxy        *Client
	Timeout      time.Duration
	STFPDisabled bool
}

Options contains the configuration for an operation.

func GetDefaultOptions

func GetDefaultOptions() *Options

GetDefaultOptions returns the default options for all operations of this library.

func (*Options) Apply

func (o *Options) Apply(options ...Option) (*Options, error)

Apply applies the option functions to the current set of options.

Jump to

Keyboard shortcuts

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