ssh

package
v1.0.56 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	User     string
	Password string
}

type ExecInfo

type ExecInfo struct {
	Cmd      string
	Output   []byte
	ExitCode int
}

func (*ExecInfo) OutputString

func (e *ExecInfo) OutputString() string

func (*ExecInfo) String

func (e *ExecInfo) String() string

type SSHClient

type SSHClient struct {
	HostName string
	Port     int

	Password string
	// contains filtered or unexported fields
}

SSHClient结构体

func NewSSHClient

func NewSSHClient(host string, port int, authConfig AuthConfig) (*SSHClient, error)

func (*SSHClient) Close

func (c *SSHClient) Close()

func (*SSHClient) ConnectTest

func (s *SSHClient) ConnectTest() bool

func (*SSHClient) DirFileExist

func (s *SSHClient) DirFileExist(path string) bool

DirFileExist 判断目录或文件是否存在

func (*SSHClient) Download

func (s *SSHClient) Download(dstPath string, localPath string) (*TransferInfo, error)

从远程主机上下载文件到本地

func (*SSHClient) Exec

func (s *SSHClient) Exec(cmd string) (*ExecInfo, error)

一个session只能执行一次命令,也就是说不能在同一个session执行多次s.session.CombinedOutput 如果想执行多次,需要每条为每个命令创建一个session(这里是这样做)

func (*SSHClient) IsConnect

func (s *SSHClient) IsConnect() bool

func (*SSHClient) Ls

func (s *SSHClient) Ls(path string) ([]string, error)

func (*SSHClient) Mkdir

func (s *SSHClient) Mkdir(dir string) (*ExecInfo, error)

func (*SSHClient) NewSession

func (s *SSHClient) NewSession() (*ssh.Session, error)

func (*SSHClient) RM

func (s *SSHClient) RM(file string, dir bool) (*ExecInfo, error)

func (*SSHClient) Reconnect

func (s *SSHClient) Reconnect() error

func (*SSHClient) Test

func (s *SSHClient) Test()

func (*SSHClient) Upload

func (s *SSHClient) Upload(localPath string, dstPath string) error

将本地文件上传到远程主机上

type TransferInfo

type TransferInfo struct {
	Kind         string // upload或download
	Local        string // 本地路径
	Dst          string // 目标路径
	TransferByte int64  // 传输的字节数(byte)
}

func (*TransferInfo) String

func (t *TransferInfo) String() string

Jump to

Keyboard shortcuts

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