ssh

package
v0.0.1-alpha4 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KnownHostsFile

func KnownHostsFile(knownHostsFile string) ssh.HostKeyCallback

KnownHostsFile returns a host key callback function that checks the provided file for the host key

func NewSSHClientConfig

func NewSSHClientConfig(user, password, keyfile, passphrase string) (*ssh.ClientConfig, error)

NewSSHClientConfig returns a new SSH client configuration

Types

type Client

type Client struct {
	Config *ssh.ClientConfig `json:"-"` // Internal use only

	Host          string `json:"host" validate:"required,hostname|ipaddress"`
	User          string `json:"user" validate:"required"`
	Password      string `json:"password,omitempty"`
	Keyfile       string `json:"keyfile,omitempty"`
	KeyPassphrase string `json:"keypassphrase,omitempty"`
	Port          int    `json:"port,omitempty" validate:"omitempty,min=1,max=65535"`
	// contains filtered or unexported fields
}

Client is a struct to hold the SSH client details

func NewSSHClient

func NewSSHClient(host, user, password, keyfile string, port int, keypassphrase string) (*Client, error)

NewSSHClient returns a new SSH client instance

func (*Client) Close

func (c *Client) Close() error

Close closes the SSH connection

func (*Client) Connect

func (c *Client) Connect() error

Connect connects to the SSH server

func (*Client) DownloadFile

func (c *Client) DownloadFile(remoteFilePath, localFilePath string, sudo bool) error

DownloadFile downloads a file from the remote server

func (*Client) Exec

func (c *Client) Exec(cmd *Command) error

Exec executes a given SSH command on the remote machine.

func (*Client) UploadFile

func (c *Client) UploadFile(localFilePath, remoteFilePath string, sudo bool) error

UploadFile uploads a file to the remote server

type Command

type Command struct {
	Stdin  io.Reader
	Stdout OutputWriter
	Stderr OutputWriter
	Path   string
	Env    []string
}

Command is a struct to hold the SSH command details

type OutputWriter

type OutputWriter interface {
	Write([]byte) (int, error)
}

OutputWriter is an interface that wraps the Write method.

Jump to

Keyboard shortcuts

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