ssh

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: Zlib Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const KRemoteCmd = "scp"

Variables

This section is empty.

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 FileInfos

type FileInfos struct {
	Message     string
	Filename    string
	Permissions string
	Size        int64
}

type Option added in v1.1.11

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

type Path added in v1.1.11

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

type Response

type Response struct {
	Type    ResponseType
	Message string
}

func ParseResponse

func ParseResponse(reader io.Reader) (Response, error)

func (*Response) GetMessage

func (r *Response) GetMessage() string

GetMessage returns the message the remote sent back.

func (*Response) IsError

func (r *Response) IsError() bool

IsError returns true when the remote responded with an error.

func (*Response) IsFailure

func (r *Response) IsFailure() bool

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

func (*Response) IsOk

func (r *Response) IsOk() bool

func (*Response) IsWarning

func (r *Response) IsWarning() bool

func (*Response) ParseFileInfos

func (r *Response) ParseFileInfos() (*FileInfos, error)

type ResponseType

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

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) ReceiveFromByWriter added in v1.1.11

func (scp *Scp) ReceiveFromByWriter(dst io.Writer, opt *Option) error

ReceiveFromByWriter 下载

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 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

Jump to

Keyboard shortcuts

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