ssh

package module
v0.0.0-...-fdc588c Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 16 Imported by: 0

README

sshtool

Package sshtool provides openssh client 方便go使用ssh连接。

使用方法

请查看 termianl_test.go测试文件使用方法。

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	Username   string
	Password   string
	PrivateKey string
	NetworkConfig
}

type Client

type Client interface {
	Login() error
	Run(cmd string, stdout, stderr io.Writer) error
	Get(src, dst string) error
	Push(src, dst string) error
	TunnelStart(Local, Remote NetworkConfig) error
	Proxy(RemoteAuthConfig *AuthConfig) (Client, error)
	Close() error
}

func NewClient

func NewClient(conf *AuthConfig, option ...Option) (Client, error)

type ClientType

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

func (*ClientType) Close

func (c *ClientType) Close() error

func (*ClientType) Get

func (c *ClientType) Get(src, dst string) error
Example
cli, _ := NewClient(auth)
defer cli.Close()
if err := cli.Get("/tmp/test02", "."); err != nil {
	log.Fatal(err)
}
Output:

func (*ClientType) GetDir

func (c *ClientType) GetDir(src string, dst string) error

func (*ClientType) GetFile

func (c *ClientType) GetFile(src string, dst string) error

func (*ClientType) Login

func (c *ClientType) Login() error
Example
cli, _ := NewClient(auth)
if err := cli.Login(); err != nil {
	log.Fatal(err)
}
Output:

func (*ClientType) Proxy

func (c *ClientType) Proxy(auth *AuthConfig) (Client, error)

func (*ClientType) Push

func (c *ClientType) Push(src, dst string) error
Example
cli, _ := NewClient(auth)
defer cli.Close()
if err := cli.Push("./test", "/tmp"); err != nil {
	log.Fatal(err)
}
Output:

func (*ClientType) PushDir

func (c *ClientType) PushDir(src string, dst string) error

func (*ClientType) PushFile

func (c *ClientType) PushFile(src string, dst string) error

func (*ClientType) Run

func (c *ClientType) Run(cmd string, stdout, stderr io.Writer) error
Example
cli, _ := NewClient(auth)
if err := cli.Run("w", stdout, stderr); err != nil {
	log.Fatal(err)
}
Output:

func (*ClientType) TunnelStart

func (c *ClientType) TunnelStart(Local, Remote NetworkConfig) error
Example
cli, _ := NewClient(auth)
local := NetworkConfig{
	Network: "tcp",
	Address: "127.0.0.1:9000",
}
remote := NetworkConfig{
	Network: "unix",
	Address: "/var/run/docker.sock",
}
if err := cli.TunnelStart(local, remote); err != nil {
	log.Fatal(err)
}
Output:

type NetworkConfig

type NetworkConfig struct {
	Network string
	// 如果Network 为unix,则Address为对应的文件路径
	// 如果Network 为tcp,则Address为 ip:port
	Address        string
	ConnectTimeout int
}

same as net.Dial

type Option

type Option func(*ClientType)

func WithProgressBar

func WithProgressBar(show bool) Option

Jump to

Keyboard shortcuts

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