Documentation ¶
Overview ¶
Package scp. Simple scp package to copy files over SSH.
Index ¶
- func Ack(writer io.Writer) error
- func CopyN(writer io.Writer, src io.Reader, size int64) (int64, error)
- func ParseFileInfos(message string, fileInfos *FileInfos) error
- func ParseFileTime(message string, fileInfos *FileInfos) error
- type Client
- func (a *Client) Close()
- func (a *Client) Connect() error
- func (a *Client) Copy(ctx context.Context, r io.Reader, remotePath string, permissions string, ...) error
- func (a *Client) CopyFile(ctx context.Context, fileReader io.Reader, remotePath string, ...) error
- func (a *Client) CopyFilePassThru(ctx context.Context, fileReader io.Reader, remotePath string, ...) error
- func (a *Client) CopyFromFile(ctx context.Context, file os.File, remotePath string, permissions string) error
- func (a *Client) CopyFromFilePassThru(ctx context.Context, file os.File, remotePath string, permissions string, ...) error
- func (a *Client) CopyFromRemote(ctx context.Context, file *os.File, remotePath string) error
- func (a *Client) CopyFromRemoteFileInfos(ctx context.Context, w io.Writer, remotePath string, passThru PassThru, ...) (*FileInfos, error)
- func (a *Client) CopyFromRemotePassThru(ctx context.Context, w io.Writer, remotePath string, passThru PassThru, ...) error
- func (a *Client) CopyPassThru(ctx context.Context, r io.Reader, remotePath string, permissions string, ...) error
- func (a *Client) SSHClient() *ssh.Client
- type ClientConfigurer
- func (c *ClientConfigurer) ClientConfig(config *ssh.ClientConfig) *ClientConfigurer
- func (c *ClientConfigurer) Create() Client
- func (c *ClientConfigurer) Host(host string) *ClientConfigurer
- func (c *ClientConfigurer) RemoteBinary(path string) *ClientConfigurer
- func (c *ClientConfigurer) SSHClient(sshClient *ssh.Client) *ClientConfigurer
- func (c *ClientConfigurer) Timeout(timeout time.Duration) *ClientConfigurer
- type CloseSSHCLient
- type EmptyHandler
- type FileInfos
- type ICloseHandler
- type PassThru
- type ProgressWriter
- type ProxyInterface
- type ResponseType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ack ¶
Ack writes an `Ack` message to the remote, does not await its response, a seperate call to ParseResponse is therefore required to check if the acknowledgement succeeded.
func CopyN ¶
CopyN an adaptation of io.CopyN that keeps reading if it did not return a sufficient amount of bytes.
func ParseFileInfos ¶
func ParseFileTime ¶
Types ¶
type Client ¶
type Client struct { // Host the host to connect to. Host string // ClientConfig the client config to use. ClientConfig *ssh.ClientConfig // Timeout the maximal amount of time to wait for a file transfer to complete. // Deprecated: use context.Context for each function instead. Timeout time.Duration // RemoteBinary the absolute path to the remote SCP binary. RemoteBinary string // contains filtered or unexported fields }
func NewClient ¶
func NewClient(host string, config *ssh.ClientConfig) Client
NewClient returns a new scp.Client with provided host and ssh.clientConfig.
func NewClientBySSH ¶
NewClientBySSH returns a new scp.Client using an already existing established SSH connection.
func NewClientBySSHWithTimeout ¶
NewClientBySSHWithTimeout same as NewClientWithTimeout but uses an existing SSH client. Deprecated: provide meaningful context to each "Copy*" function instead.
func NewClientWithTimeout ¶
NewClientWithTimeout returns a new scp.Client with provides host, ssh.ClientConfig and timeout. Deprecated: provide meaningful context to each "Copy*" function instead.
func (*Client) Connect ¶
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( ctx context.Context, r io.Reader, remotePath string, permissions string, size int64, ) error
Copy copies the contents of an io.Reader to a remote location.
func (*Client) CopyFile ¶
func (a *Client) CopyFile( ctx context.Context, 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) CopyFilePassThru ¶
func (a *Client) CopyFilePassThru( ctx context.Context, fileReader io.Reader, remotePath string, permissions string, passThru PassThru, proxy ProxyInterface, ) error
CopyFilePassThru 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. Access copied bytes by providing a PassThru reader factory. Proxy allows Intercepting the IoWriter as it is written for progress reporting or any other stream modification/monitoring reason and can be set to nil to disable this behaviour.
func (*Client) CopyFromFile ¶
func (a *Client) CopyFromFile( ctx context.Context, 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.
func (*Client) CopyFromFilePassThru ¶
func (a *Client) CopyFromFilePassThru( ctx context.Context, file os.File, remotePath string, permissions string, passThru PassThru, ) error
CopyFromFilePassThru 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. Access copied bytes by providing a PassThru reader factory.
func (*Client) CopyFromRemote ¶
CopyFromRemote copies a file from the remote to the local file given by the `file` parameter. Use `CopyFromRemotePassThru` if a more generic writer is desired instead of writing directly to a file on the file system.
func (*Client) CopyFromRemoteFileInfos ¶
func (a *Client) CopyFromRemoteFileInfos( ctx context.Context, w io.Writer, remotePath string, passThru PassThru, proxy ProxyInterface, ) (*FileInfos, error)
CopyFroRemoteFileInfos copies a file from the remote to a given writer and return a FileInfos struct containing information about the file such as permissions, the file size, modification time and access time Proxy allows Intercepting the IoReader as it is written for progress reporting or any other stream modification/monitoring reason and can be set to nil to disable this behaviour.
func (*Client) CopyFromRemotePassThru ¶
func (a *Client) CopyFromRemotePassThru( ctx context.Context, w io.Writer, remotePath string, passThru PassThru, proxy ProxyInterface, ) error
CopyFromRemotePassThru copies a file from the remote to the given writer. The passThru parameter can be used to keep track of progress and how many bytes that were download from the remote. `passThru` can be set to nil to disable this behaviour. Proxy allows Intercepting the IoReader as it is written for progress reporting or any other stream modification/monitoring reason and can be set to nil to disable this behaviour.
func (*Client) CopyPassThru ¶
func (a *Client) CopyPassThru( ctx context.Context, r io.Reader, remotePath string, permissions string, size int64, passThru PassThru, proxy ProxyInterface, ) error
CopyPassThru copies the contents of an io.Reader to a remote location. Access copied bytes by providing a PassThru reader factory Proxy allows Intercepting the IoWriter as it is written for progress reporting or any other stream modification/monitoring reason and can be set to nil to disable this behaviour.
type ClientConfigurer ¶
type ClientConfigurer struct {
// contains filtered or unexported fields
}
ClientConfigurer a struct containing all the configuration options used by an scp client.
func NewConfigurer ¶
func NewConfigurer(host string, config *ssh.ClientConfig) *ClientConfigurer
NewConfigurer creates a new client configurer. It takes the required parameters: the host 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 ClientConfigurer struct.
func (*ClientConfigurer) ClientConfig ¶
func (c *ClientConfigurer) ClientConfig(config *ssh.ClientConfig) *ClientConfigurer
ClientConfig alters the ssh.ClientConfig.
func (*ClientConfigurer) Create ¶
func (c *ClientConfigurer) Create() Client
Create builds a client with the configuration stored within the ClientConfigurer.
func (*ClientConfigurer) Host ¶
func (c *ClientConfigurer) Host(host string) *ClientConfigurer
Host alters the host of the client connects to.
func (*ClientConfigurer) RemoteBinary ¶
func (c *ClientConfigurer) RemoteBinary(path string) *ClientConfigurer
RemoteBinary sets the path of the location of the remote scp binary Defaults to: /usr/bin/scp.
func (*ClientConfigurer) SSHClient ¶
func (c *ClientConfigurer) SSHClient(sshClient *ssh.Client) *ClientConfigurer
func (*ClientConfigurer) Timeout ¶
func (c *ClientConfigurer) Timeout(timeout time.Duration) *ClientConfigurer
Timeout Changes the connection timeout. Defaults to one minute.
type CloseSSHCLient ¶
type CloseSSHCLient struct {
// contains filtered or unexported fields
}
Close handler to close an SSH client
func (CloseSSHCLient) Close ¶
func (scp CloseSSHCLient) Close()
type EmptyHandler ¶
type EmptyHandler struct{}
Close handler equivalent to a no-op. Used by default when no resources have to be cleaned.
func (EmptyHandler) Close ¶
func (EmptyHandler) Close()
type FileInfos ¶
type FileInfos struct { Message string Filename string Permissions uint32 Size int64 Atime int64 Mtime int64 }
func NewFileInfos ¶
func NewFileInfos() *FileInfos
func ParseResponse ¶
ParseResponse reads from the given reader (assuming it is the output of the remote) and parses it into a Response structure.
type ICloseHandler ¶
type ICloseHandler interface {
Close()
}
Callback for freeing managed resources
type ProgressWriter ¶
type ProxyInterface ¶
type ResponseType ¶
type ResponseType = byte
const ( Ok ResponseType = 0 Warning ResponseType = 1 Error ResponseType = 2 Create ResponseType = 'C' Time ResponseType = 'T' )
Directories ¶
Path | Synopsis |
---|---|
Copyright (c) 2020 Bram Vandenbogaerde * You may use, distribute or modify this code under the * terms of the Mozilla Public License 2.0, which is distributed * along with the source code.
|
Copyright (c) 2020 Bram Vandenbogaerde * You may use, distribute or modify this code under the * terms of the Mozilla Public License 2.0, which is distributed * along with the source code. |