ssh

package
v1.33.0 Latest Latest
Warning

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

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

Documentation

Overview

Package ssh is a simple wrapper around an ssh.Client which implements utilities to be performed with a remote server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a wrapper type over a ssh connection that takes care of creating a channel and running commands in a single method.

func (*Client) Close

func (sshc *Client) Close() error

Close closes the underlying connection.

func (*Client) DialContextF added in v1.17.0

func (sshc *Client) DialContextF() func(context.Context, string, string) (net.Conn, error)

DialContextF returns the underlying client's DialContext function

func (*Client) Download

func (sshc *Client) Download(src string, dst io.Writer, sudo bool) error

Download downloads a given src remote filepath to a given dst writer.

func (*Client) RunCommand

func (sshc *Client) RunCommand(cmd string) ([]byte, error)

RunCommand runs a given command in a new ssh session.

func (*Client) StartCommand

func (sshc *Client) StartCommand(cmd string) error

StartCommand starts a given command in a new ssh session. Unlike RunCommand this command does not wait command to finish. This is needed for running commands in the background.

func (*Client) Upload

func (sshc *Client) Upload(src io.Reader, dst string, sudo bool) ([]byte, error)

Upload uploads a given src object to a given destination file.

func (*Client) UploadFile

func (sshc *Client) UploadFile(src, dst string, sudo bool) ([]byte, error)

UploadFile uploads a given file path to a given destination file.

type ExtAgent

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

ExtAgent is a wrapper type over agent.ExtendedAgent provding a method to return a Client.

func NewAgent

func NewAgent() (*ExtAgent, error)

NewAgent connects to the local ssh agent and validates that it has at least one key added. It returns the agent if everything looks good.

func (*ExtAgent) NewClient

func (ea *ExtAgent) NewClient(user, ip string) (*Client, error)

NewClient returns a Client object by dialing the ssh agent on port 22

func (*ExtAgent) NewClientWithPort added in v1.17.0

func (ea *ExtAgent) NewClientWithPort(ip, port, user string) (*Client, error)

NewClientWithPort returns a Client object by dialing the ssh agent on the provided port

func (*ExtAgent) NewClientWithRetry added in v1.33.0

func (ea *ExtAgent) NewClientWithRetry(user, ip string, timeout time.Duration) (*Client, error)

NewClientWithRetry attempts to create an SSH client connection with exponential backoff, retrying until the given timeout is reached. The backoff starts at 2s and doubles each attempt, capped at 30s.

Jump to

Keyboard shortcuts

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