sftp

package
v0.0.0-...-9bd0860 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package sftp provides high-performance SFTP and SCP file transfer services over SSH sessions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidTargetFile is returned when a target SCP filename contains control characters (\r, \n, \x00).
	ErrInvalidTargetFile = errors.New("aoni/ssh/sftp: invalid control characters in target filename")

	// ErrInvalidChunkSize is returned when parallel transfer chunkSize is less than or equal to zero.
	ErrInvalidChunkSize = errors.New("aoni/ssh/sftp: parallel chunk size must be greater than zero")

	// ErrParallelTransferFailed is returned when one or more chunks fail during parallel file transfer.
	ErrParallelTransferFailed = errors.New("aoni/ssh/sftp: parallel file transfer failed")

	// ErrClientClosed is returned when operations are attempted on an inactive or nil SSH client.
	ErrClientClosed = errors.New("aoni/ssh/sftp: ssh client session is closed")
)

Functions

func Download

func Download(sshClient *ssh.Client, remotePath, localPath string, maxPacketSize uint32) error

Download transfers a remote file to localPath over SFTP using pooled buffers and flushes disk writes.

func DownloadParallel

func DownloadParallel(
	ctx context.Context,
	sshClient *ssh.Client,
	remotePath, localPath string,
	workers int,
	chunkSize int64,
	maxPacketSize uint32,
) error

DownloadParallel downloads a remote file to localPath over SFTP using multiple parallel worker threads reading at calculated offsets.

func NewClient

func NewClient(sshClient *ssh.Client, maxPacketSize uint32, opts ...pkgsftp.ClientOption) (*pkgsftp.Client, error)

NewClient initializes a new SFTP client over the active SSH connection using asynchronous write/read pipelining.

func Scp

func Scp(ctx context.Context, sshClient *ssh.Client, localFilePath, remoteFilePath string) error

Scp uploads localFilePath to remoteFilePath on the remote machine using native SCP protocol with zero-alloc buffer pooling.

func Upload

func Upload(sshClient *ssh.Client, localPath, remotePath string, maxPacketSize uint32) error

Upload transfers a local file to remotePath over SFTP using pooled buffers.

func UploadParallel

func UploadParallel(
	ctx context.Context,
	sshClient *ssh.Client,
	localPath, remotePath string,
	workers int,
	chunkSize int64,
	maxPacketSize uint32,
) error

UploadParallel uploads a local file to remotePath over SFTP using multiple parallel worker threads writing at calculated offsets.

func WriteFile

func WriteFile(ctx context.Context, sshClient *ssh.Client, r io.Reader, size int64, remoteFilePath string) error

WriteFile streams size bytes from r into remoteFilePath on the target server using native SCP protocol and zero-alloc buffer pooling.

Types

This section is empty.

Jump to

Keyboard shortcuts

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