scp

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

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 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.AuditLogSessionStreamer
	// 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 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

Jump to

Keyboard shortcuts

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