scp

package
v4.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package scp handles file uploads and downloads via scp command

Index

Constants

View Source
const (
	// OKByte is scp OK message bytes
	OKByte = 0x0
	// WarnByte tells that next goes a warning string
	WarnByte = 0x1
	// ErrByte tells that next goes an error string
	ErrByte = 0x2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	// Execute processes SCP traffic
	Execute(ch io.ReadWriter) error
	// GetRemoteShellCmd returns a remote shell command that
	// has to be executed on the remove server (handled by Teleport)
	GetRemoteShellCmd() (string, error)
}

Command is an API that describes command operations

func CreateCommand

func CreateCommand(cfg Config) (Command, error)

CreateCommand creates and returns a new Command

func CreateDownloadCommand

func CreateDownloadCommand(cfg Config) (Command, error)

CreateDownloadCommand configures and returns a command used to download a file

func CreateHTTPDownload

func CreateHTTPDownload(req HTTPTransferRequest) (Command, error)

CreateHTTPDownload creates HTTP upload command

func CreateHTTPUpload

func CreateHTTPUpload(req HTTPTransferRequest) (Command, error)

CreateHTTPUpload creates HTTP download command

func CreateUploadCommand

func CreateUploadCommand(cfg Config) (Command, error)

CreateUploadCommand configures and returns a command used to upload a file

type Config

type Config struct {
	// Flags is a set of SCP command line flags
	Flags Flags
	// User is a user who runs SCP command
	User string
	// AuditLog is AuditLog log
	AuditLog events.IAuditLog
	// ProgressWriter is a writer for printing the progress
	// (used only on the client)
	ProgressWriter io.Writer
	// FileSystem is a source file system abstraction for the SCP command
	FileSystem FileSystem
	// RemoteLocation is a destination location of the file
	RemoteLocation string
	// RunOnServer is low level API flag that indicates that
	// this command will be run on the server
	RunOnServer bool
}

Config describes Command configuration settings

func (*Config) CheckAndSetDefaults

func (c *Config) CheckAndSetDefaults() error

CheckAndSetDefaults checks and sets default values

type Destination

type Destination struct {
	// Login is an optional login username
	Login string
	// Host is a host to copy to/from
	Host utils.NetAddr
	// Path is a path to copy to/from
	Path string
}

Destination is scp destination to copy to or from

func ParseSCPDestination

func ParseSCPDestination(s string) (*Destination, error)

ParseSCPDestination takes a string representing a remote resource for SCP to download/upload, like "user@host:/path/to/resource.txt" and returns 3 components of it

type FileInfo

type FileInfo interface {
	// IsDir returns true if a file is a directory
	IsDir() bool
	// ReadDir returns information of directory files
	ReadDir() ([]FileInfo, error)
	// GetName returns a file name
	GetName() string
	// GetPath returns a file path
	GetPath() string
	// GetModePerm returns file permissions
	GetModePerm() os.FileMode
	// GetSize returns file size
	GetSize() int64
}

FileInfo is an API that describes methods that provide file information

type FileSystem

type FileSystem interface {
	// IsDir returns true if a given file path is a directory
	IsDir(path string) bool
	// GetFileInfo returns FileInfo for a given file path
	GetFileInfo(filePath string) (FileInfo, error)
	// MkDir creates a directory
	MkDir(path string, mode int) error
	// OpenFile opens a file and returns its Reader
	OpenFile(filePath string) (io.ReadCloser, error)
	// CreateFile creates a new file
	CreateFile(filePath string, length uint64) (io.WriteCloser, error)
	// SetChmod sets file permissions
	SetChmod(path string, mode int) error
}

FileSystem is an interface that abstracts file system methods used in SCP command functions

type Flags

type Flags struct {
	// Source indicates upload mode
	Source bool
	// Sink indicates receive mode
	Sink bool
	// Verbose sets a logging mode
	Verbose bool
	// Target sets targeted files to be transferred
	Target []string
	// Recursive indicates recursive file transfer
	Recursive bool
	// RemoteAddr is a remote host address
	RemoteAddr string
	// LocalAddr is a local host address
	LocalAddr string
	// DirectoryMode indicates that a directory is being sent.
	DirectoryMode bool
}

Flags describes SCP command line flags

type HTTPTransferRequest

type HTTPTransferRequest struct {
	// RemoteLocation is a destination location of the file
	RemoteLocation string
	// FileName is a file name
	FileName string
	// HTTPRequest is HTTP request
	HTTPRequest *http.Request
	// HTTPRequest is HTTP request
	HTTPResponse http.ResponseWriter
	// ProgressWriter is a writer for printing the progress
	Progress io.Writer
	// User is a user name
	User string
	// AuditLog is AuditLog log
	AuditLog events.IAuditLog
}

HTTPTransferRequest describes HTTP file transfer request

Jump to

Keyboard shortcuts

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