sftp

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sftp provides bounded SSH-based file upload and download operations.

Typical use:

result, err := sftp.Download(ctx, profile, "/srv/report.csv", "./report.csv", 0, 2*time.Minute)

Transfers use SSH profiles and strict known_hosts checking from the sibling ssh package.

Index

Constants

View Source
const (
	DefaultMaxBytes  int64 = 256 << 20
	MaxTransferBytes int64 = 1 << 30
)

Variables

View Source
var ErrTransferLimit = errors.New("sftp transfer exceeded the configured byte limit")

Functions

func ValidateMaxBytes

func ValidateMaxBytes(maxBytes int64) error

ValidateMaxBytes validates a configured transfer cap. Zero selects DefaultMaxBytes.

Types

type TransferResult

type TransferResult struct {
	Direction  string        `json:"direction"`
	LocalPath  string        `json:"local_path"`
	RemotePath string        `json:"remote_path"`
	Bytes      int64         `json:"bytes"`
	Duration   time.Duration `json:"duration"`
}

TransferResult reports one completed SFTP transfer.

func Download

func Download(ctx context.Context, profile sshx.Profile, remotePath, localPath string, maxBytes int64, timeout time.Duration) (TransferResult, error)

Download writes a bounded remote file to a private temporary file beside the destination and replaces the destination only after the transfer is complete.

func Upload

func Upload(ctx context.Context, profile sshx.Profile, localPath, remotePath string, maxBytes int64, timeout time.Duration) (TransferResult, error)

Upload atomically stages a local regular file on the remote server and renames it into place only after the bounded upload completes. Existing targets are replaced only when the server supports OpenSSH's posix-rename extension.

Jump to

Keyboard shortcuts

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