sftp

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: 24 Imported by: 0

Documentation

Overview

Package sftp handles file transfers client-side via SFTP.

Index

Constants

View Source
const (
	// FileTransferDstPath is the dstPath (location) for the requested file transfer. This would be equal
	// to the file to be downloaded, or location for a file to be uploaded.
	FileTransferDstPath string = "TELEPORT_FILE_TRANSFER_DST_PATH"
	// FileTransferRequestID is an optional parameter id of an file transfer request that has gone through
	// an approval process during a moderated session to allow a file transfer scp command to be executed
	// used as a value in the file transfer context and env var for exec session
	FileTransferRequestID contextKey = "TELEPORT_FILE_TRANSFER_REQUEST_ID"

	// ModeratedSessionID is an optional parameter sent during SCP requests to specify which moderated session
	// to check for valid FileTransferRequests
	// used as a value in the file transfer context and env var for exec session
	ModeratedSessionID contextKey = "TELEPORT_MODERATED_SESSION_ID"
)

Variables

This section is empty.

Functions

func NewProgressBar

func NewProgressBar(size int64, desc string, writer io.Writer) *progressbar.ProgressBar

NewProgressBar returns a new progress bar that writes to writer.

Types

type Config

type Config struct {

	// ProgressStream is a callback to return a read/writer for printing the progress
	// (used only on the client)
	ProgressStream func(fileInfo os.FileInfo) io.ReadWriter
	// Log optionally specifies the logger
	Log log.FieldLogger
	// contains filtered or unexported fields
}

Config describes the settings of a file transfer

func CreateDownloadConfig

func CreateDownloadConfig(src, dst string, opts Options) (*Config, error)

CreateDownloadConfig returns a Config ready to download files over SFTP.

func CreateHTTPDownloadConfig

func CreateHTTPDownloadConfig(req HTTPTransferRequest) (*Config, error)

CreateHTTPDownloadConfig returns a Config ready to download a file from over SFTP and write it to a HTTP response.

func CreateHTTPUploadConfig

func CreateHTTPUploadConfig(req HTTPTransferRequest) (*Config, error)

CreateHTTPUploadConfig returns a Config ready to upload a file from a HTTP request over SFTP.

func CreateUploadConfig

func CreateUploadConfig(src []string, dst string, opts Options) (*Config, error)

CreateUploadConfig returns a Config ready to upload files over SFTP.

func (*Config) TransferFiles

func (c *Config) TransferFiles(ctx context.Context, sshClient *ssh.Client) error

TransferFiles transfers files from the configured source paths to the configured destination path over SFTP or HTTP depending on the Config.

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 a remote SFTP destination to copy to or from.

func ParseDestination

func ParseDestination(input string) (*Destination, error)

ParseDestination takes a string representing a remote resource for SFTP to download/upload in the form "[user@]host:path" 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 FileSystem

type FileSystem interface {
	// Type returns whether the filesystem is "local" or "remote"
	Type() string
	// Glob returns matching files of a glob pattern
	Glob(ctx context.Context, pattern string) ([]string, error)
	// Stat returns info about a file
	Stat(ctx context.Context, path string) (os.FileInfo, error)
	// ReadDir returns information about files contained within a directory
	ReadDir(ctx context.Context, path string) ([]os.FileInfo, error)
	// Open opens a file
	Open(ctx context.Context, path string) (fs.File, error)
	// Create creates a new file
	Create(ctx context.Context, path string, size int64) (io.WriteCloser, error)
	// Mkdir creates a directory
	Mkdir(ctx context.Context, path string) error
	// Chmod sets file permissions
	Chmod(ctx context.Context, path string, mode os.FileMode) error
	// Chtimes sets file access and modification time
	Chtimes(ctx context.Context, path string, atime, mtime time.Time) error
}

FileSystem describes file operations to be done either locally or over SFTP

type HTTPTransferRequest

type HTTPTransferRequest struct {
	// Src is the source file name
	Src string
	// Dst is the destination file name
	Dst string
	// HTTPRequest is where the source file will be read from for
	// file upload transfers
	HTTPRequest *http.Request
	// HTTPResponse is where the destination file will be written to for
	// file download transfers
	HTTPResponse http.ResponseWriter
}

HTTPTransferRequest describes file transfer request over HTTP.

type Options

type Options struct {
	// Recursive indicates recursive file transfer
	Recursive bool
	// PreserveAttrs preserves access and modification times
	// from the original file
	PreserveAttrs bool
}

Options control aspects of a file transfer

Jump to

Keyboard shortcuts

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