gssh

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExecSuccess 执行成功标记字符
	ExecSuccess = "successful execution, exit 0\n"

	// Separator 分隔符号
	Separator = "\n\n"
)

Variables

This section is empty.

Functions

func CRLF2LF

func CRLF2LF(file string) error

CRLF2LF 把windows文本\r\n转为unix的\n

func ExecShell

func ExecShell(ctx context.Context, servers []*RemoteServerInfo, fileParams *FileParams, outMsg chan string)

ExecShell 在远程服务器执行shell脚本,支持多个服务器

func GenMd5File

func GenMd5File(file string) (string, error)

GenMd5File 在相同目录下生成标准md5文件,文件名:原文件名.md5

func Md5Sum

func Md5Sum(file string) (string, error)

Md5Sum 计算文件哈希值

Types

type FileParams

type FileParams struct {
	// 本地文件参数
	ShellFile      string `json:"shellFile"`      // 脚本文件,执行程序入口
	CompressedFile string `json:"compressedFile"` // zip或tar.gz压缩文件

	// 目标服务器路径
	UploadPath string `json:"uploadPath"` // 上传文件到目标服务器的文件路径,默认路径为/tmp/upload
}

FileParams 文件参数

type RemoteServerInfo

type RemoteServerInfo struct {
	Host     string
	Port     int
	User     string
	Password string
}

RemoteServerInfo 远程服务器信息

func (*RemoteServerInfo) CheckConnect

func (r *RemoteServerInfo) CheckConnect() error

CheckConnect 检查是否可以连接到远程服务器

func (*RemoteServerInfo) String

func (r *RemoteServerInfo) String() string

type Result

type Result struct {
	StdOut chan string
	Err    error
	// contains filtered or unexported fields
}

Result 执行命令的结果

type SSHClient

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

SSHClient 远程服务器信息

func NewKeySSHClient

func NewKeySSHClient(host string, port int, user string, sshKey []byte) (*SSHClient, error)

NewKeySSHClient 连接远程服务器,key方式

func NewPwdSSHClient

func NewPwdSSHClient(host string, port int, user string, password string) (*SSHClient, error)

NewPwdSSHClient 连接远程服务器,密码方式

func (*SSHClient) Close

func (s *SSHClient) Close() error

Close 关闭ssh连接

func (*SSHClient) CloseSftp

func (s *SSHClient) CloseSftp() error

CloseSftp 关闭sftp连接

func (*SSHClient) CreateSftp

func (s *SSHClient) CreateSftp() error

CreateSftp 创建sftp会话

func (*SSHClient) Exec

func (s *SSHClient) Exec(ctx context.Context, cmd string, result *Result)

Exec 执行命令,实时信息返回在result对象中

func (*SSHClient) Execs

func (s *SSHClient) Execs(ctx context.Context, cmds []string, result *Result)

Execs 批量执行命令,按顺序执行,如果前面命令执行失败,不会执行后面命令,实时信息返回在result对象中

func (*SSHClient) SendContent

func (s *SSHClient) SendContent(ctx context.Context, filename string, content []byte, remoteDir string) error

SendContent 发送文件内容到远程服务器

func (*SSHClient) SendFile

func (s *SSHClient) SendFile(ctx context.Context, localFile string, remoteDir string) error

SendFile 发送文件到远程服务器

Jump to

Keyboard shortcuts

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