Documentation
¶
Overview ¶
Package transfer 实现文件传输的协议细节(SFTP/SCP)与完整性辅助,由根包封装为 Shell 能力。
Index ¶
- Variables
- func RenameRemote(cli *sftp.Client, oldPath, newPath string) error
- func ScpDownload(ctx context.Context, client *ssh.Client, remotePath, localPath string, ...) error
- func ScpUpload(ctx context.Context, client *ssh.Client, localPath, remotePath string, ...) error
- func SftpDownload(cli *sftp.Client, remotePath, localPath string, opt Options) error
- func SftpRemove(cli *sftp.Client, remotePath string) error
- func SftpUpload(cli *sftp.Client, localPath, remotePath string, opt Options) error
- type Options
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 ¶
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 ¶
SftpDownload 经 SFTP 下载远端文件到本地。
本地路径为目录时下载到目录下(以远端文件名命名);已存在且未指定 Force 时返回 os.ErrExist。
func SftpRemove ¶
SftpRemove 删除远端文件/目录(目录递归删除)
func SftpUpload ¶
SftpUpload 经 SFTP 上传本地文件/目录到远端(目录递归上传)。
目标为目录时上传到目录下(以本地文件名命名);目标文件已存在且未指定 Force 时返回 os.ErrExist。 单文件写入临时文件后重命名,避免中途失败留下不完整的文件。 远程路径必须用 path 包拼接:远程是类Unix系统用 '/' 分隔, filepath 在 Windows 上会用 '\',会被远程当成文件名字符。
Types ¶
Click to show internal directories.
Click to hide internal directories.