client

package
v0.0.0-...-9e9b179 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddKnownHost

func AddKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (err error)

AddKnownHost add a a host to known hosts file.

func CheckKnownHost

func CheckKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (found bool, err error)

CheckKnownHost checks is host in known hosts file.

func DefaultKnownHosts

func DefaultKnownHosts() (ssh.HostKeyCallback, error)

DefaultKnownHosts returns host key callback from default known hosts path, and error if any.

func DefaultKnownHostsPath

func DefaultKnownHostsPath() (string, error)

DefaultKnownHostsPath returns default user knows hosts file.

func GetSigner

func GetSigner(prvFile string, passphrase string) (ssh.Signer, error)

GetSigner returns ssh signer from private key file.

func HasAgent

func HasAgent() bool

HasAgent checks if ssh agent exists.

func KnownHosts

func KnownHosts(file string) (ssh.HostKeyCallback, error)

KnownHosts returns host key callback from a custom known hosts path.

Types

type Auth

type Auth []ssh.AuthMethod

Auth represents ssh auth methods.

func Key

func Key(prvFile string, passphrase string) (Auth, error)

Key returns auth method from private key with or without passphrase.

func Password

func Password(pass string) Auth

Password returns password auth method.

func UseAgent

func UseAgent() (Auth, error)

UseAgent auth via ssh agent

type Client

type Client struct {
	*ssh.Client
	Config *Config
}

Client represents ssh client

func NewClient

func NewClient(config *Config) (c *Client, err error)

NewClient returns new client and error if any

func (Client) CleanRemote

func (c Client) CleanRemote(remotePath string) (err error)

CleanRemote Deleting file on the server

func (Client) Close

func (c Client) Close() error

Close client net connection.

func (Client) Download

func (c Client) Download(ctx context.Context, remotePath, localPath string) (err error)

Download file from remote server

func (Client) NewSftp

func (c Client) NewSftp(opts ...sftp.ClientOption) (*sftp.Client, error)

NewSftp returns new sftp client and error if any.

func (Client) Run

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

Run starts a new SSH session and runs the cmd, it returns CombinedOutput and err if any.

func (Client) Upload

func (c Client) Upload(localPath string, remotePath string) (err error)

Upload a local file to remote server!

type Config

type Config struct {
	Auth             Auth
	User             string
	Addr             string
	Key              string
	Port             uint
	Catalog          string
	FwType           string
	UsePassword      bool
	UseKeyPassphrase bool
	Timeout          time.Duration
	Callback         ssh.HostKeyCallback
}

Config for Client

Jump to

Keyboard shortcuts

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