transfer

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package transfer 实现文件传输的协议细节(SFTP/SCP)与完整性辅助,由根包封装为 Shell 能力。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRemoteIsDir 远端目标路径是目录
	ErrRemoteIsDir = errors.New("transfer: remote path is a directory")
	// ErrLocalIsDir 本地目标路径是目录
	ErrLocalIsDir = errors.New("transfer: local path is a directory")
)

Functions

func RenameRemote

func RenameRemote(cli *sftp.Client, oldPath, newPath string) error

RenameRemote 远端重命名:Posix-Rename → Rename(目标存在则先删) 两级回退

func ScpDownload

func ScpDownload(ctx context.Context, client *ssh.Client, remotePath, localPath string, opt Options) error

ScpDownload 经 SCP 协议下载远端文件到本地。ctx 取消时中止传输。

func ScpUpload

func ScpUpload(ctx context.Context, client *ssh.Client, localPath, remotePath string, opt Options) error

ScpUpload 经 SCP 协议上传本地文件到远端(exec 通道,远端需安装 scp)。

远端路径以 / 结尾时视为目录(自动拼接本地文件名)。
ctx 取消时中止传输(关闭会话解除阻塞)。

func SftpDownload

func SftpDownload(cli *sftp.Client, remotePath, localPath string, opt Options) error

SftpDownload 经 SFTP 下载远端文件到本地。

本地路径为目录时下载到目录下(以远端文件名命名);已存在且未指定 Force 时返回 os.ErrExist。

func SftpRemove

func SftpRemove(cli *sftp.Client, remotePath string) error

SftpRemove 删除远端文件/目录(目录递归删除)

func SftpUpload

func SftpUpload(cli *sftp.Client, localPath, remotePath string, opt Options) error

SftpUpload 经 SFTP 上传本地文件/目录到远端(目录递归上传)。

目标为目录时上传到目录下(以本地文件名命名);目标文件已存在且未指定 Force 时返回 os.ErrExist。
单文件写入临时文件后重命名,避免中途失败留下不完整的文件。
远程路径必须用 path 包拼接:远程是类Unix系统用 '/' 分隔,
filepath 在 Windows 上会用 '\',会被远程当成文件名字符。

Types

type Options

type Options struct {
	// Force 目标文件已存在时是否覆盖(目录拼接文件名后重新判断)
	Force bool
	// Progress 传输进度回调(已传输字节数, 总字节数)。可为nil
	Progress func(transferred, total int64)
}

Options 传输的可选参数

Jump to

Keyboard shortcuts

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