transfer

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLocalPathForGet

func DefaultLocalPathForGet(remote string) string

DefaultLocalPathForGet returns the default local destination for a get when omitted.

func DefaultRemotePathForPut

func DefaultRemotePathForPut(local string) string

DefaultRemotePathForPut returns the default remote destination for a put when omitted.

func Get

func Get(ctx context.Context, conn *ssh.Client, remotePath, localPath string) error

Get downloads remotePath from conn to localPath (single regular file). ctx cancels the transfer. conn must be a live golang.org/x/crypto/ssh client. Errors: ctx.Err; SFTP/stat/open failures on remotePath; directory or non-regular remote paths; local write errors.

func GetWithProgress

func GetWithProgress(ctx context.Context, conn *ssh.Client, remotePath, localPath string, progress CopyProgress) error

GetWithProgress is like Get but reports copy progress via progress when non-nil.

func GetWithProgressClosing

func GetWithProgressClosing(
	ctx context.Context, conn *ssh.Client, remotePath, localPath string,
	progress CopyProgress, onClosing func(),
) error

GetWithProgressClosing is like GetWithProgress and invokes onClosing after copy, before file close.

func LocalBaseName

func LocalBaseName(localPath string) string

LocalBaseName returns the final path element of a local file path.

func LocalPathWithDirDefault

func LocalPathWithDirDefault(remote, local string, localIsDir func(string) bool) string

LocalPathWithDirDefault appends the remote basename when local names an existing directory.

func ParseRemoteDest

func ParseRemoteDest(dst string) (user, host, path string, err error)

ParseRemoteDest parses user@host:/path and user@[ipv6]:/path forms. Returns an error when host or path cannot be determined.

func Put

func Put(ctx context.Context, conn *ssh.Client, localPath, remotePath string) error

Put uploads localPath to remotePath on conn (single regular file). Creates missing parent directories on the remote host before writing the file. ctx cancels the transfer. conn must be a live golang.org/x/crypto/ssh client. Errors: ctx.Err; local open/stat errors; SFTP mkdir/create/write errors; directory paths.

func PutWithProgress

func PutWithProgress(ctx context.Context, conn *ssh.Client, localPath, remotePath string, progress CopyProgress) error

PutWithProgress is like Put but reports copy progress via progress when non-nil.

func PutWithProgressClosing

func PutWithProgressClosing(
	ctx context.Context, conn *ssh.Client, localPath, remotePath string,
	progress CopyProgress, onClosing func(),
) error

PutWithProgressClosing is like PutWithProgress and invokes onClosing after copy, before file close.

func RemoteBaseName

func RemoteBaseName(remotePath string) string

RemoteBaseName returns the final path element of a remote file path.

func RemotePathWithDirDefault

func RemotePathWithDirDefault(local, remote string, remoteIsDir func(string) bool) string

RemotePathWithDirDefault appends the local basename when remote names a directory.

Types

type CopyProgress

type CopyProgress func(written, total int64)

CopyProgress reports bytes copied during SFTP transfer. total is 0 when unknown.

type Direction

type Direction int

Direction selects download (Get) or upload (Put) for transferFile.

const (
	// DirGet downloads remote to local.
	DirGet Direction = iota
	// DirPut uploads local to remote.
	DirPut
)

Directories

Path Synopsis
Package route selects get/put backends (ZMODEM vs SFTP) for in-session transfer.
Package route selects get/put backends (ZMODEM vs SFTP) for in-session transfer.
Package zmodem wraps the vendored xiwh ZMODEM stack for lrzsz-compatible PTY file transfer.
Package zmodem wraps the vendored xiwh ZMODEM stack for lrzsz-compatible PTY file transfer.

Jump to

Keyboard shortcuts

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