ssh

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 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 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
	LocalFilePath  string
	RemoteFilePath 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) CopyFromRemote

func (scp *Scp) CopyFromRemote(localPath string, remotePath string) error

func (*Scp) CopyFromRemoteByWriter

func (scp *Scp) CopyFromRemoteByWriter(w io.Writer, remotePath string) error

CopyFromRemoteByWriter 下载

func (*Scp) CopyToRemote

func (scp *Scp) CopyToRemote(id int, localPath string, remotePath string, permissions string) *Result

CopyToRemote 上传

func (*Scp) CopyToRemoteByReader

func (scp *Scp) CopyToRemoteByReader(r io.Reader, size int64, remotePath string, permissions string) error

func (*Scp) Session

func (scp *Scp) Session() (*ssh.Session, error)

func (*Scp) WithRemoteCmd

func (scp *Scp) WithRemoteCmd(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