scp

package
v1.2.3-fred.12 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: Apache-2.0 Imports: 17 Imported by: 72

Documentation

Overview

Package scp handles file uploads and downloads via SCP command. See https://web.archive.org/web/20170215184048/https://blogs.oracle.com/janp/entry/how_the_scp_protocol_works for the high-level protocol overview.

Authoritative source for the protocol is the source code for OpenSSH scp: https://github.com/openssh/openssh-portable/blob/add926dd1bbe3c4db06e27cab8ab0f9a3d00a0c2/scp.c

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 GetAtime

func GetAtime(fi os.FileInfo) time.Time

Source: os/stat_linux.go

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 SCP command with specified configuration.

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 an HTTP download command

func CreateHTTPUpload

func CreateHTTPUpload(req HTTPTransferRequest) (Command, error)

CreateHTTPUpload creates an HTTP upload 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
	// Log optionally specifies the logger
	Log log.FieldLogger
}

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.
	// An empty path name is valid, and it refers to the user's default directory (usually
	// the user's home directory).
	// See https://tools.ietf.org/html/draft-ietf-secsh-filexfer-09#page-14, 'File Names'
	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 parses it into a structured form.

See https://tools.ietf.org/html/draft-ietf-secsh-filexfer-09#page-14, 'File Names' section about details on file names.

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
	// GetModTime returns file modification time
	GetModTime() time.Time
	// GetAccessTime returns file last access time
	GetAccessTime() time.Time
}

FileInfo provides access to file metadata

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)
	// Chmod sets file permissions
	Chmod(path string, mode int) error
	// Chtimes sets file access and modification time
	Chtimes(path string, atime, mtime time.Time) 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
	// PreserveAttrs preserves access and modification times
	// from the original file
	PreserveAttrs 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