client

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BufferSize 传输缓冲区大小 (512KB)
	BufferSize = 512 * 1024
	// MaxConcurrentTransfers 最大并发传输数
	MaxConcurrentTransfers = 4
	// DirCacheTimeout 目录列表缓存超时时间
	DirCacheTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func FormatSize added in v0.10.1

func FormatSize(bytes int64) string

FormatSize formats bytes into human-readable form (binary units, 1 decimal).

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client SFTP 客户端封装

func NewClient

func NewClient(addr string, config *ssh.ClientConfig) (*Client, error)

NewClient 创建 SFTP 客户端

func (*Client) Chdir

func (c *Client) Chdir(dir string) error

Chdir 切换工作目录

func (*Client) ClearDirCache

func (c *Client) ClearDirCache()

ClearDirCache 清除所有目录缓存

func (*Client) Close

func (c *Client) Close() error

Close 关闭连接

func (*Client) Download

func (c *Client) Download(remotePath, localPath string) error

Download 下载文件

func (*Client) DownloadDir

func (c *Client) DownloadDir(remoteDir, localDir string, opts *DownloadOptions) (int, error)

DownloadDir 递归下载整个目录 使用统一的任务收集+执行模式,避免并发嵌套

func (*Client) DownloadGlob

func (c *Client) DownloadGlob(pattern, localPath string, opts *DownloadOptions) (int, error)

DownloadGlob 使用 glob 模式匹配下载远程文件

func (*Client) DownloadSources added in v0.10.0

func (c *Client) DownloadSources(remoteSources []string, localDir string, opts *DownloadOptions) (int, error)

DownloadSources 下载一个或多个远程 source(显式路径或 glob)

func (*Client) DownloadWithProgress

func (c *Client) DownloadWithProgress(remotePath, localPath string, globalBar *progressbar.ProgressBar) error

DownloadWithProgress 下载文件(支持进度条)

func (*Client) ExecuteRemote

func (c *Client) ExecuteRemote(command string, stdin io.Reader, stdout, stderr io.Writer) error

ExecuteRemote 在远程服务器执行命令(交互式)

func (*Client) GetLocalwd

func (c *Client) GetLocalwd() string

GetLocalwd 获取本地当前工作目录

func (*Client) Getwd

func (c *Client) Getwd() string

Getwd 获取远程当前工作目录

func (*Client) List

func (c *Client) List(dir string) ([]os.FileInfo, error)

List 列出目录内容

func (*Client) ListCompletion

func (c *Client) ListCompletion(prefix string) []string

ListCompletion 获取路径补全候选列表 返回基于用户输入prefix的完整候选路径(保持prefix的格式:绝对/相对)

func (*Client) LocalChdir

func (c *Client) LocalChdir(dir string) error

LocalChdir 切换本地工作目录

func (*Client) LocalList

func (c *Client) LocalList(dir string) ([]os.FileInfo, error)

LocalList 列出本地目录内容

func (*Client) LocalMkdir

func (c *Client) LocalMkdir(dir string) error

LocalMkdir 创建本地目录

func (*Client) Mkdir

func (c *Client) Mkdir(dir string) error

Mkdir 创建目录

func (*Client) Remove

func (c *Client) Remove(remotePath string) error

Remove 删除文件或目录

func (*Client) RemoveDir added in v0.10.1

func (c *Client) RemoveDir(remotePath string) error

RemoveDir removes an empty remote directory.

func (*Client) Rename

func (c *Client) Rename(oldPath, newPath string) error

Rename 重命名文件或目录

func (*Client) ResolveLocalPath added in v0.8.0

func (c *Client) ResolveLocalPath(p string) string

ResolveLocalPath 解析本地路径(相对路径转绝对路径) 返回路径统一使用 / 分隔符(SFTP 兼容格式),避免 Windows \ 不被远程服务器识别

func (*Client) ResolveRemotePath added in v0.8.0

func (c *Client) ResolveRemotePath(p string) string

ResolveRemotePath 解析远程路径(相对路径转绝对路径)

func (*Client) Stat

func (c *Client) Stat(remotePath string) (os.FileInfo, error)

Stat 获取文件信息

func (*Client) Upload

func (c *Client) Upload(localPath, remotePath string) error

Upload 上传文件

func (*Client) UploadDir

func (c *Client) UploadDir(localDir, remoteDir string, opts *UploadOptions) (int, error)

UploadDir 递归上传整个目录 使用统一的任务收集+执行模式,避免并发嵌套

func (*Client) UploadGlob

func (c *Client) UploadGlob(pattern, remotePath string, opts *UploadOptions) (int, error)

UploadGlob 使用 glob 模式匹配上传文件

func (*Client) UploadSources added in v0.10.0

func (c *Client) UploadSources(localSources []string, remoteDir string, opts *UploadOptions) (int, error)

UploadSources 上传一个或多个本地 source(显式路径或 glob)

func (*Client) UploadWithProgress

func (c *Client) UploadWithProgress(localPath, remotePath string, globalBar *progressbar.ProgressBar) error

UploadWithProgress 上传文件(支持进度条)

type DownloadOptions

type DownloadOptions struct {
	Recursive    bool // 递归下载目录
	ShowProgress bool // 显示进度条
	Concurrency  int  // 并发数
	Flatten      bool // 扁平化目标路径
	MaxDepth     int  // 最大递归深度:-1=无限, 0=仅当前目录, 1=一层子目录...
}

DownloadOptions 下载选项

type TransferOptions added in v0.8.0

type TransferOptions struct {
	Recursive    bool // 递归处理目录
	ShowProgress bool // 显示进度条
	Concurrency  int  // 并发数
	MaxDepth     int  // 最大递归深度:-1=无限, 0=仅当前目录, 1=一层子目录...
}

TransferOptions 统一的传输选项

func DefaultTransferOptions added in v0.8.0

func DefaultTransferOptions() *TransferOptions

DefaultTransferOptions 返回默认传输选项

type UploadOptions

type UploadOptions struct {
	Recursive    bool // 递归上传目录
	ShowProgress bool // 显示进度条
	Concurrency  int  // 并发数
	Flatten      bool // 扁平化目标路径
	MaxDepth     int  // 最大递归深度:-1=无限, 0=仅当前目录, 1=一层子目录...
}

UploadOptions 上传选项

Jump to

Keyboard shortcuts

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