sshx

package module
v0.0.0-...-4b973a4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 18 Imported by: 0

README

sshx

sshx 是一个 Golang 的 SSH 库,封装了 ssh 和 sftp,简化了操作接口

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFileFingerNotMatch = errors.New("file finger not match")

ErrFileFingerNotMatch 文件指纹不匹配

View Source
var ErrLocalFileExisted = errors.New("local file already exist")

ErrLocalFileExisted 本地已经存在该文件

View Source
var ErrRemoteFileExisted = errors.New("remote file already exist")

ErrRemoteFileExisted 远程服务器已经存在该文件

View Source
var ErrSessionCanceled = errors.New("session canceled because context canceled")

ErrSessionCanceled 会话因为上下文对象的取消而被取消

Functions

This section is empty.

Types

type Client

type Client interface {
	ReceiveFile(dest string, src string, override bool, consistencyCheck bool) (written int64, err error)
	ReceiveFileOverride(destFilepath string, srcFilepath string) (written int64, err error)
	ReadFile(src string) ([]byte, error)

	SendFile(destFilepath string, srcFilepath string, override bool, consistencyCheck bool) (written int64, err error)
	SendFileOverride(destFilepath string, srcFilepath string) (written int64, err error)

	WriteFile(destFilepath string, dataReader io.Reader, override bool) (written int64, err error)
	WriteFileOverride(destFilepath string, dataReader io.Reader) (written int64, err error)

	Command(ctx context.Context, cmd string, opts ...SessionOption) ([]byte, error)
	Handle(handler Handler) error
}

func NewClient

func NewClient(serverAddr string, credential Credential, opts ...Option) (Client, error)

NewClient 创建一个 sshClient 对象

type Credential

type Credential struct {
	User                 string
	Password             string
	PrivateKey           string
	PrivateKeyPath       string
	PrivateKeyPassphrase string
}

Credential Command 连接配置 优先级: Password > PrivateKey > PrivateKeyPath

type DefaultLogger

type DefaultLogger struct{}

DefaultLogger is a default logger

func (DefaultLogger) DebugEnabled

func (DefaultLogger) DebugEnabled() bool

func (DefaultLogger) Debugf

func (DefaultLogger) Debugf(format string, v ...interface{})

type EnhanceClient

type EnhanceClient interface {
	ReceiveFile(dest string, src string, override bool, consistencyCheck bool) (written int64, err error)
	ReceiveFileOverride(destFilepath string, srcFilepath string) (written int64, err error)
	ReadFile(src string) ([]byte, error)

	SendFile(destFilepath string, srcFilepath string, override bool, consistencyCheck bool) (written int64, err error)
	SendFileOverride(destFilepath string, srcFilepath string) (written int64, err error)

	WriteFile(destFilepath string, dataReader io.Reader, override bool) (written int64, err error)
	WriteFileOverride(destFilepath string, dataReader io.Reader) (written int64, err error)

	SendDirectory(destDirectory string, srcDirectory string) error
	SendFiles(destDirectory string, srcFiles ...string) error
	TempWriteFile(dataReader io.Reader, fn func(tempFilepath string) error) error
	TempSendFile(srcFilepath string, fn func(tempFilepath string) error) error

	Command(ctx context.Context, cmd string, opts ...SessionOption) ([]byte, error)

	Create(path string) (*sftp.File, error)
	Walk(root string) *fs.Walker
	ReadDir(p string) ([]os.FileInfo, error)
	Stat(p string) (os.FileInfo, error)
	Lstat(p string) (os.FileInfo, error)
	ReadLink(p string) (string, error)
	Link(oldname, newname string) error
	Symlink(oldname, newname string) error
	Chtimes(path string, atime time.Time, mtime time.Time) error
	Chown(path string, uid, gid int) error
	Chmod(path string, mode os.FileMode) error
	Truncate(path string, size int64) error
	Open(path string) (*sftp.File, error)
	OpenFile(path string, f int) (*sftp.File, error)
	StatVFS(path string) (*sftp.StatVFS, error)
	Join(elem ...string) string
	Remove(path string) error
	RemoveDirectory(path string) error
	Rename(oldname, newname string) error
	PosixRename(oldname, newname string) error
	Getwd() (string, error)
	Mkdir(path string) error
	MkdirAll(path string) error
	Glob(pattern string) (matches []string, err error)
}

type Handler

type Handler func(sub EnhanceClient) error

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
	DebugEnabled() bool
}

Logger is a log interface

type Option

type Option func(server *sshClient) error

Option 用于设置连接配置

func SetEstablishTimeout

func SetEstablishTimeout(timeout time.Duration) Option

SetEstablishTimeout 设置 ssh 连接建立超时时间

func SetLogger

func SetLogger(logger Logger) Option

SetLogger 设置日志实现

func SetMd5sumBinInServer

func SetMd5sumBinInServer(cmd string) Option

SetMd5sumBinInServer 设置远端用于检查文件校验值的命令

type SessionOption

type SessionOption func(session *ssh.Session) error

func RequestPty

func RequestPty(width int, height int, terminalModes ...ssh.TerminalModes) SessionOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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