Documentation
¶
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) Download(remotePath, localPath string, opt *UploadOption) error
- func (c *Client) DownloadWriter(remotePath string, dst io.Writer, opt *UploadOption) error
- func (c *Client) Mkdir(remotePath string) error
- func (c *Client) NewSession(opts *ShellOptions) (*Session, error)
- func (c *Client) ReadDir(remotePath string) ([]os.FileInfo, error)
- func (c *Client) Remove(remotePath string) error
- func (c *Client) Run(command string) (string, error)
- func (c *Client) Shell(opts *ShellOptions) error
- func (c *Client) Stat(remotePath string) (os.FileInfo, error)
- func (c *Client) Upload(localPath, remotePath string, opt *UploadOption) error
- func (c *Client) UploadReader(src io.Reader, remotePath string, opt *UploadOption) error
- type Config
- type PTYOptions
- type ResizeOption
- type Session
- type ShellOptions
- type UploadOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v1.0.10
type Client struct {
// contains filtered or unexported fields
}
Client SSH 客户端
func (*Client) Download ¶ added in v1.0.10
func (c *Client) Download(remotePath, localPath string, opt *UploadOption) error
Download 下载远程文件到本地路径。 localPath 可以是目录(自动取远程文件名)或完整文件路径。
func (*Client) DownloadWriter ¶ added in v1.0.10
DownloadWriter 下载远程文件写入 io.Writer。
func (*Client) NewSession ¶ added in v1.0.10
func (c *Client) NewSession(opts *ShellOptions) (*Session, error)
NewSession 创建可手动控制的交互会话。 适合需要动态 resize(如 WebSocket 终端代理)的场景。
func (*Client) Run ¶ added in v1.0.10
Run 执行非交互命令,返回合并后的 stdout+stderr 输出。 不支持 vim/top 等需要 PTY 的程序,请使用 Shell。
func (*Client) Shell ¶ added in v1.0.10
func (c *Client) Shell(opts *ShellOptions) error
Shell 开启交互式 Shell,支持 vim/top 等需要 PTY 的程序。 调用方负责将本地终端切换为 raw 模式(见示例)。 函数阻塞直到 Shell 退出。
func (*Client) Upload ¶ added in v1.0.10
func (c *Client) Upload(localPath, remotePath string, opt *UploadOption) error
Upload 上传本地文件到远程路径。 remotePath 可以是目录(自动取本地文件名)或完整文件路径。
func (*Client) UploadReader ¶ added in v1.0.10
UploadReader 从 io.Reader 上传到远程完整文件路径。
type Config ¶ added in v1.0.10
type Config struct {
// 用户名
User string
// 密码(与 KeyPath/KeyPEM 三选一)
Password string
// 私钥文件路径
KeyPath string
// 私钥 PEM 内容(字符串形式,与 KeyPath 二选一)
KeyPEM string
// 服务器地址,格式 host:port
Addr string
// 连接超时,默认 10s
Timeout time.Duration
}
Config SSH 连接配置
type PTYOptions ¶ added in v1.0.10
type PTYOptions struct {
// 终端类型,默认 xterm-256color
Term string
// 宽度(列),默认 220
Width int
// 高度(行),默认 50
Height int
}
PTYOptions PTY 终端参数
type ResizeOption ¶ added in v1.0.10
ResizeOption 用于 WindowChange
type Session ¶ added in v1.0.10
type Session struct {
// contains filtered or unexported fields
}
Session 可控制的交互会话(支持动态调整窗口大小)
type ShellOptions ¶ added in v1.0.10
type ShellOptions struct {
PTY PTYOptions
// 标准输入,默认 os.Stdin
Stdin io.Reader
// 标准输出,默认 os.Stdout
Stdout io.Writer
// 标准错误,默认 os.Stderr
Stderr io.Writer
}
ShellOptions Shell 会话选项
type UploadOption ¶ added in v1.0.10
type UploadOption struct {
// 上传进度回调,参数为本次写入字节数;为 nil 时不回调
OnProgress func(written int64)
// 进度回调间隔,默认 500ms
ProgressInterval time.Duration
}
UploadOption 上传选项
Click to show internal directories.
Click to hide internal directories.