scp

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// the client config to use
	ClientConfig *ssh.ClientConfig
	// stores the SSH session while the connection is running
	Session *ssh.Session
	// stores the SSH connection itself in order to close it after transfer
	Conn ssh.Conn

	// the clients waits for the given timeout until given up the connection
	Timeout time.Duration
	// the absolute path to the remote SCP binary
	RemoteBinary string
}

Client represents a client of scp session.

func (*Client) Close

func (a *Client) Close() error

Close closes the client.

func (*Client) Connect

func (a *Client) Connect(addr string, clientConfig *ssh.ClientConfig) (err error)

Connect connects to the remote SSH server, returns error if it couldn't establish a session to the SSH server

func (*Client) Copy

func (a *Client) Copy(r io.Reader, remotePath, permissions string, size int64) error

Copy copies the contents of an io.Reader to a remote location

func (*Client) CopyFile

func (a *Client) CopyFile(fileReader io.Reader, remotePath string, permissions string) error

CopyFile copies the contents of an io.Reader to a remote location, the length is determined by reading the io.Reader until EOF if the file length in know in advance please use "Copy" instead

func (*Client) CopyFromFile

func (a *Client) CopyFromFile(file os.File, remotePath string, permissions string) error

CopyFromFile copies the contents of an os.File to a remote location, it will get the length of the file by looking it up from the filesystem

type ClientConf

type ClientConf struct {
	Timeout      time.Duration
	RemoteBinary string
}

ClientConf is a struct containing all the configuration options used by an scp client.

func NewConf

func NewConf() *ClientConf

NewConf creates a new client configurer. It takes the required parameters: the addr and the ssh.ClientConfig and returns a configurer populated with the default values for the optional parameters.

These optional parameters can be set by using the methods provided on the ClientConf struct.

func (*ClientConf) CreateClient

func (c *ClientConf) CreateClient() *Client

CreateClient builds a client with the configuration stored within the ClientConf

type Response

type Response struct {
	Type    ResponseType
	Message string
}

Response has tree types of responses that the remote can send back: ok, warning and error

The difference between warning and error is that the connection is not closed by the remote, however, a warning can indicate a file transfer failure (such as invalid destination directory) and such be handled as such.

All responses except for the `OK` type always have a message (although these can be empty)

The remote sends a confirmation after every SCP command, because a failure can occur after every command, the response should be read and checked after sending them.

func ParseResponse

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

ParseResponse reads from the given reader (assuming it is the output of the remote) and parses it into a Response structure

func (*Response) GetMessage

func (r *Response) GetMessage() string

GetMessage returns the detailed message.

func (*Response) IsError

func (r *Response) IsError() bool

IsError tells if there is error in the response.

func (*Response) IsFailure

func (r *Response) IsFailure() bool

IsFailure tells if the response if none OK or not.

func (*Response) IsOK

func (r *Response) IsOK() bool

IsOK tells the response is OK or not.

func (*Response) IsWarning

func (r *Response) IsWarning() bool

IsWarning tells the response has warning or not.

type ResponseType

type ResponseType = uint8

ResponseType represents the type of the response.

const (
	// OK represents everything is OK
	OK ResponseType = iota + 1
	// Warning represents there is warning.
	Warning
	// Error means there is error.
	Error
)

Jump to

Keyboard shortcuts

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