ssh

package
v1.20.95 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: Zlib Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const KRemoteCmd = "scp"

Variables

View Source
var ErrAck = errors.New("failed to write ack buffer")
View Source
var ErrCopy = errors.New("failed to copy file")

Functions

func AuthKey

func AuthKey(username string, auths []ssh.AuthMethod, keyCallBack ssh.HostKeyCallback) (ssh.ClientConfig, error)

func PublicKey

func PublicKey(file string) ssh.AuthMethod

func PublicKeys

func PublicKeys(filenames []string) []ssh.AuthMethod

func WithAgent

func WithAgent(username string, keyCallBack ssh.HostKeyCallback) (ssh.ClientConfig, error)

func WithKey

func WithKey(username string, path string, keyCallBack ssh.HostKeyCallback) (ssh.ClientConfig, error)

func WithPassphrase

func WithPassphrase(path string, passpharase []byte, username string, keyCallBack ssh.HostKeyCallback) (ssh.ClientConfig, error)

func WithPassword

func WithPassword(username string, password string, keyCallBack ssh.HostKeyCallback) (ssh.ClientConfig, error)

Types

type DirHeader added in v1.4.23

type DirHeader struct {
	FileInfo
}

type EndDirHeader added in v1.4.23

type EndDirHeader struct {
}

type FileHeader added in v1.4.23

type FileHeader struct {
	FileInfo
}

type FileInfo added in v1.4.23

type FileInfo struct {
	Name string
	Size int64
	Mode os.FileMode
}

func (*FileInfo) CreateFile added in v1.4.23

func (fi *FileInfo) CreateFile(opt *Option) (io.WriteCloser, error)

func (*FileInfo) Receive added in v1.4.23

func (fi *FileInfo) Receive(opt *Option, src io.Reader) error
type Header struct {
	Type ReplyType
}

type Option added in v1.1.11

type Option struct {
	Cmd              string
	Local            Path
	Remote           Path
	UpdatePermission bool //-p 保留原文件的修改时间,访问时间和访问权限。
	Recursive        bool //-r
}

type Path added in v1.1.11

type Path struct {
	Mode  os.FileMode
	Name  string
	IsDir bool
}

type Receiver added in v1.4.23

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

func (*Receiver) Do added in v1.4.23

func (rf *Receiver) Do(reply io.Reader, ack io.Writer) (err error)

type Reply added in v1.4.23

type Reply struct {
	Type    ReplyType
	Message string
}

func ParseReply added in v1.4.23

func ParseReply(reader io.Reader) (Reply, error)

func (Reply) Error added in v1.4.23

func (r Reply) Error() string

func (Reply) GetMessage added in v1.4.23

func (r Reply) GetMessage() string

GetMessage returns the message the remote sent back.

func (Reply) IsError added in v1.4.23

func (r Reply) IsError() bool

IsError returns true when the remote responded with an error.

func (Reply) IsFailure added in v1.4.23

func (r Reply) IsFailure() bool

IsFailure returns true when the remote answered with a warning or an error.

func (Reply) IsOk added in v1.4.23

func (r Reply) IsOk() bool

func (Reply) IsWarning added in v1.4.23

func (r Reply) IsWarning() bool

func (Reply) Parse added in v1.4.23

func (r Reply) Parse() (interface{}, error)

type ReplyType added in v1.4.23

type ReplyType uint8
const (
	Ok      ReplyType = 0
	Warning ReplyType = 1
	Error   ReplyType = 2
)

func (ReplyType) String added in v1.4.23

func (rt ReplyType) String() string

type Result

type Result struct {
	Id         int
	Host       string
	Command    string
	LocalPath  string
	RemotePath string
	Result     string
	StartTime  time.Time
	EndTime    time.Time
	Error      error
}

type Scp

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

func NewScp

func NewScp(session *Session) *Scp

func (*Scp) Close added in v1.1.11

func (scp *Scp) Close()

func (*Scp) ReceiveFrom added in v1.1.11

func (scp *Scp) ReceiveFrom(opt *Option) error

func (*Scp) SendTo added in v1.1.11

func (scp *Scp) SendTo(id int, opt *Option) *Result

SendTo 上传

func (*Scp) SendToByReader added in v1.1.11

func (scp *Scp) SendToByReader(src io.Reader, size int64, opt *Option, remoteFilename string) error

func (*Scp) WithCmd added in v1.1.11

func (scp *Scp) WithCmd(cmd string) *Scp

type Sender added in v1.4.23

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

func (*Sender) Do added in v1.4.23

func (wf *Sender) Do(reply io.Reader, src io.Reader) (err error)

type Session

type Session struct {
	Host    string //ip:port
	Session *ssh.Session
	Client  *ssh.Client
	// contains filtered or unexported fields
}

func NewSession

func NewSession(host string, conf *ssh.ClientConfig) *Session

func (*Session) Close

func (s *Session) Close()

func (*Session) Connect

func (s *Session) Connect() error

func (*Session) Exec

func (s *Session) Exec(id int, command string) *Result

type Sftp

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

func NewSftp

func NewSftp(session *Session) *Sftp

func (*Sftp) Exec

func (sf *Sftp) Exec(id int, localFilePath string, remoteFilePath string) *Result

type TimeHeader added in v1.4.23

type TimeHeader struct {
	Mtime time.Time
	Atime time.Time
}

Jump to

Keyboard shortcuts

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