sftp

package
v1.2.3-fred.6 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package sftp handles file transfers client-side via SFTP

Index

Constants

This section is empty.

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 {

	// ProgressWriter is a callback to return a writer for printing the progress
	// (used only on the client)
	ProgressWriter func(fileInfo os.FileInfo) io.Writer
	// 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

func CreateUploadConfig

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

CreateUploadConfig returns a Config ready to upload files

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

type FileSystem

type FileSystem interface {
	// Type returns whether the filesystem is "local" or "remote"
	Type() string
	// 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) (io.ReadCloser, error)
	// Create creates a new file
	Create(ctx context.Context, path string, mode os.FileMode) (io.WriteCloser, error)
	// MkDir creates a directory
	// sftp.Client.Mkdir does not take an os.FileMode, so this can't either
	Mkdir(ctx context.Context, path string, mode os.FileMode) 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 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