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 ¶
const ( DefaultMaxBytes int64 = 256 << 20 MaxTransferBytes int64 = 1 << 30 )
Variables ¶
var ErrTransferLimit = errors.New("sftp transfer exceeded the configured byte limit")
Functions ¶
func ValidateMaxBytes ¶
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.