gsssh

package
v1.9.9 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RunTypeTerminal = iota + 1
	RunTypeBridge
)
View Source
const (
	StatusWait = iota + 1
	StatusRunning
	StatusError
	StatusStop
)
View Source
const EndCommand = `THIS_IS_END_POINT`
View Source
const SshBroken = `notice : ssh connection is broken`

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

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

type PtyConfig added in v1.9.3

type PtyConfig struct {
	Term   string `json:"term"   yaml:"term"`   // 终端类型
	Height int    `json:"height" yaml:"height"` // 行数
	Width  int    `json:"width"  yaml:"width"`  // 列数 会影响输出的内容是否换行
	// 把常用的 TerminalModes 单独拆字段,零值即“不设置”
	Echo        uint32 `json:"echo"           yaml:"echo"`       // 把用户敲的命令回显 0 关闭,1 开启
	RawMode     bool   `json:"raw_mode"       yaml:"raw_mode"`   // true 时把 ECHO、ICANON 等全部关掉
	InputSpeed  uint32 `json:"input_speed"  yaml:"input_speed"`  // 波特率
	OutputSpeed uint32 `json:"output_speed" yaml:"output_speed"` // 波特率
}

type SshConfig

type SshConfig struct {
	Name     string `json:"name"` //自定义名称
	Host     string `json:"host"`
	Port     string `json:"port"`
	UserName string `json:"username"`
	Password string `json:"password"`
	GsSlog   *gstool.GsSlog

	RunType      int       //执行类型
	MaxRunSecond int       //最大执行时间 不超过40秒
	PtyConfig    PtyConfig //终端配置
	// contains filtered or unexported fields
}

func NewSshAuthPassword

func NewSshAuthPassword(host, port, user, password string) *SshConfig

NewSshAuthPassword ssh auth password 一个本地端口只允许做一次桥接

func (*SshConfig) Close

func (h *SshConfig) Close()

Close 释放所有资源

func (*SshConfig) CloseBridge

func (h *SshConfig) CloseBridge()

func (*SshConfig) CloseFirstReceiveMsg

func (h *SshConfig) CloseFirstReceiveMsg()

func (*SshConfig) CloseTerminal

func (h *SshConfig) CloseTerminal()

CloseTerminal 主动关闭

func (*SshConfig) ConnectAuthPassword

func (h *SshConfig) ConnectAuthPassword() error

ConnectAuthPassword ssh auth password

func (*SshConfig) Debugf

func (h *SshConfig) Debugf(msg string, params ...interface{})

func (*SshConfig) Errof

func (h *SshConfig) Errof(msg string, params ...interface{})

func (*SshConfig) RunBridge

func (h *SshConfig) RunBridge(targetHostPort string) (string, error)

RunBridge execute and forward to the local port Local listening port, all connections to this port will be forwarded to the destination address

func (*SshConfig) RunCommand added in v1.9.1

func (h *SshConfig) RunCommand(command string) error

RunCommand 通过终端一次性执行命令 不等待完成

func (*SshConfig) RunCommandOnce

func (h *SshConfig) RunCommandOnce(shell string) string

RunCommandOnce 建立一个临时session执行一次

func (*SshConfig) RunCommandWait

func (h *SshConfig) RunCommandWait(command string) (string, error)

RunCommandWait 通过终端一次性执行命令 等待完成

func (*SshConfig) RunWaitTimeout added in v1.9.5

func (h *SshConfig) RunWaitTimeout(ctx context.Context)

RunWaitTimeout 运行超时处理

func (*SshConfig) SetCombineNum

func (h *SshConfig) SetCombineNum(combineNum int)

func (*SshConfig) SetFuncBefore

func (h *SshConfig) SetFuncBefore(before func(string) string)

func (*SshConfig) SetFuncBroken

func (h *SshConfig) SetFuncBroken(broken func())

func (*SshConfig) SetFuncEndCommand

func (h *SshConfig) SetFuncEndCommand(f func())

func (*SshConfig) SetFuncReceiveMsg

func (h *SshConfig) SetFuncReceiveMsg(receive func(string) string)

func (*SshConfig) SetFuncStartCommand

func (h *SshConfig) SetFuncStartCommand(f func())

func (*SshConfig) SetFuncStreamReceive

func (h *SshConfig) SetFuncStreamReceive(receive func(string))

func (*SshConfig) SetMaxBufferSize added in v1.9.8

func (h *SshConfig) SetMaxBufferSize(maxBuffer int)

func (*SshConfig) SetMaxRunSecond

func (h *SshConfig) SetMaxRunSecond(maxRnuSecond int)

SetMaxRunSecond 设置最大执行超时时间 不能超过40秒

func (*SshConfig) SetPtyConfig added in v1.9.3

func (h *SshConfig) SetPtyConfig(ptyConfig PtyConfig)

func (*SshConfig) UploadFile

func (h *SshConfig) UploadFile(remoteFilePath, fileContent, filePath string) error

UploadFile 上传文件到远程

func (*SshConfig) UploadFileProcess

func (h *SshConfig) UploadFileProcess(remoteFilePath, localFilePath string, progressCallback func(bytesWritten, totalBytes int64)) error

UploadFileProcess 上传文件到远程,支持进度回调

func (*SshConfig) UploadFileProcessScp

func (h *SshConfig) UploadFileProcessScp(remoteFilePath, localFilePath string, progressCallback func(bytesWritten, totalBytes int64)) error

func (*SshConfig) UploadFileSCP

func (h *SshConfig) UploadFileSCP(remoteFilePath, localFilePath string, expired time.Duration) error

type Terminal

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

Jump to

Keyboard shortcuts

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