scp

package
v2.7.0-alpha.6+incompa... Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 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

func ParseSCPDestination

func ParseSCPDestination(s string) (login, host, dest string)

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

Types

type Command

type Command interface {
	// Execute processes SCP traffic
	Execute(ch io.ReadWriter) error
	// GetRemoteShellCmd returns a remove 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(params Config) Command

CreateCommand creates and returns a new Command

func CreateDownloadCommand

func CreateDownloadCommand(config Config) (Command, error)

CreateDownloadCommand configures and returns a command used to download a file

func CreateHTTPDownloadCommand

func CreateHTTPDownloadCommand(remoteLocation string, w http.ResponseWriter, progress io.Writer) (Command, error)

CreateHTTPDownloadCommand creates HTTP upload command

func CreateHTTPUploadCommand

func CreateHTTPUploadCommand(remoteLocation string, httpReq *http.Request, progress io.Writer) (Command, error)

CreateHTTPUploadCommand creates HTTP download command

func CreateUploadCommand

func CreateUploadCommand(config Config) (Command, error)

CreateUploadCommand configures and returns a command used to upload a file

type Config

type Config struct {
	// Flags is SCP command line flags
	Flags Flags
	// User is a user who runs SCP command
	User *user.User
	// AuditLog is AuditLog log
	AuditLog events.IAuditLog
	// ProgressWriter is a writer to for printing the progress
	// (used only on the client for printing the progress)
	ProgressWriter io.Writer
	// FileSystem is a file system on which SCP command is ran
	FileSystem FileSystem
	// RemoteLocation is the file remote destination
	RemoteLocation string
}

Config describes Command configuration settings

type FileInfo

type FileInfo interface {
	// IsDir tells if this is a directory
	IsDir() bool
	// ReadDir returns information of directory files
	ReadDir() ([]FileInfo, error)
	// GetName returns file name
	GetName() string
	// GetPath returns 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 tells if given 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 API that describes file methods

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 transfered
	Target []string
	// Recursive indicates recursive file transfer
	Recursive bool
	// RemoteAddr is remote host address
	RemoteAddr string
	// LocalAddr is local host address
	LocalAddr string
}

Flags describes SCP command line flags

Jump to

Keyboard shortcuts

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