linux

package
v0.0.0-...-b1b21d8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: LGPL-3.0 Imports: 16 Imported by: 0

README

这是一个远程操控Linux 的模块包括文件的上传下载,linux 执行命令

func main() {
	cli, err := linux.NewClient(linux.ClientOption{Host: "192.168.1.30", Port: 22, Usr: "py_baixudong", Pwd: "jhcms001"})
	if err != nil {
		log.Panic(err)
	}
	defer cli.Close()
	scr, err := cli.NewScreen("proxy")
	if err != nil {
		log.Panic(err)
	}
	defer scr.Close()
	log.Print(scr.IsRun)
	rs, err := scr.SudoRun([]byte("sudo ./proxy30\n"))
	if err != nil {
		log.Panic(err)
	}
	log.Print(string(rs))

	// log.Print(cli)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(option ClientOption) (*Client, error)

func (*Client) Close

func (obj *Client) Close() error

func (*Client) NewScreen

func (obj *Client) NewScreen(preCtx context.Context, name string, waitTimes ...time.Duration) (*Screen, error)

func (*Client) NewSftp

func (obj *Client) NewSftp() (*Sftp, error)

func (*Client) NewSsh

func (obj *Client) NewSsh() (*Ssh, error)

type ClientOption

type ClientOption struct {
	Timeout time.Duration //连接超时时间
	Host    string        //远程host
	Port    int           //远程port
	Usr     string        //用户名
	Pwd     string        //密码
	KeyPath string        //key文件的路径,当使用key登陆时使用
	KeyData []byte        //key文件的内容,当使用key登陆时使用
}

type Screen

type Screen struct {
	IsRun bool
	// contains filtered or unexported fields
}

func (*Screen) Close

func (obj *Screen) Close() error

func (*Screen) Run

func (obj *Screen) Run(cmd []byte) ([]byte, error)

func (*Screen) SudoRun

func (obj *Screen) SudoRun(cmd []byte) ([]byte, error)

type ScreenPip

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

func (*ScreenPip) Close

func (obj *ScreenPip) Close() error

func (*ScreenPip) Read

func (obj *ScreenPip) Read(con []byte) (int, error)

func (*ScreenPip) Write

func (obj *ScreenPip) Write(con []byte) (int, error)

type Sftp

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

func (*Sftp) Close

func (obj *Sftp) Close() error

func (*Sftp) Download

func (obj *Sftp) Download(remote_path string, local_paths ...string) error

func (*Sftp) DownloadDir

func (obj *Sftp) DownloadDir(remote_path string, local_path string) error

func (*Sftp) DownloadFile

func (obj *Sftp) DownloadFile(remote_path string, local_path string) error

func (*Sftp) Upload

func (obj *Sftp) Upload(local_path string, remote_paths ...string) error

func (*Sftp) UploadDir

func (obj *Sftp) UploadDir(local_path string, remote_path string) error

func (*Sftp) UploadFile

func (obj *Sftp) UploadFile(local_path string, remote_path string) error

type Ssh

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

func (*Ssh) Close

func (obj *Ssh) Close() error

func (*Ssh) Run

func (obj *Ssh) Run(cmd string) ([]byte, error)

func (*Ssh) SetStdErr

func (obj *Ssh) SetStdErr(val io.Writer)

func (*Ssh) SetStdIn

func (obj *Ssh) SetStdIn(val io.Reader)

func (*Ssh) SetStdOut

func (obj *Ssh) SetStdOut(val io.Writer)

func (*Ssh) StdErrPipe

func (obj *Ssh) StdErrPipe() (io.Reader, error)

func (*Ssh) StdInPipe

func (obj *Ssh) StdInPipe() (io.WriteCloser, error)

func (*Ssh) StdOutPipe

func (obj *Ssh) StdOutPipe() (io.Reader, error)

func (*Ssh) Term

func (obj *Ssh) Term(options ...TermOption) error

type TermOption

type TermOption struct {
	Type     string //defalut  xterm
	DisEcho  bool   // 是否禁用回显
	InSpeed  uint32 // input speed = 14.4kbaud
	OutSpeed uint32 //output speed = 14.4kbaud
	Row      int
	Col      int
}

Jump to

Keyboard shortcuts

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