ssh

package
v0.0.0-...-8d03e1a Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectWithPassword

func ConnectWithPassword(addr string, user string, password string) (*ssh.Client, error)

func ConnectWithPrivateKey

func ConnectWithPrivateKey(addr string, user string, privateKey ...any) (*ssh.Client, error)

ConnectWithPrivateKey connects to a remote host using a private key, privateKey should be string or byte slice, if it is a string, it will be treated as an id_rsa_path to the private key file. if it is a byte slice, it will be treated as the private key itself. you can also not to provide privateKey, it will be treated as an id_rsa_path to the private key file, and the id_rsa_path is "~/.ssh/id_rsa" or "%HOME%/.ssh/id_rsa" (on windows).

func NewCommander

func NewCommander(c *ssh.Client) cmd.Commander

Types

type Client

type Client struct {
	*ssh.Client
}

func (*Client) Run

func (c *Client) Run(cmd string) ([]byte, error)

func (*Client) Send

func (c *Client) Send(cmd string) error

type SFTP

type SFTP struct {
	*sftp.Client
}

func NewSFTP

func NewSFTP(c *ssh.Client) (*SFTP, error)

func (*SFTP) Download

func (s *SFTP) Download(remotePath string, writer io.Writer) error

func (*SFTP) Upload

func (s *SFTP) Upload(reader io.Reader, remotePath string) error

type SSH

type SSH struct {
	// ip:port
	Addr   string
	Config *ssh.ClientConfig
}

func (*SSH) Connect

func (s *SSH) Connect() (*ssh.Client, error)

Connect connects to the remote host, if you want to use custom ssh config, you can use it.

Jump to

Keyboard shortcuts

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