Documentation
¶
Index ¶
- func GetLocalIPAddr() (string, error)
- type RichSSHClient
- func (c *RichSSHClient) Close()
- func (c *RichSSHClient) Connect(ctx context.Context) error
- func (c *RichSSHClient) DownloadFile(ctx context.Context, remotePath, localPath string, progressWriter io.Writer) error
- func (c *RichSSHClient) Run(ctx context.Context, cmd string) (*RichSSHClientResponse, error)
- func (c *RichSSHClient) RunStream(ctx context.Context, cmd string, outWriter, errWriter io.Writer) error
- func (c *RichSSHClient) UploadFile(ctx context.Context, localPath, remotePath string, progressWriter io.Writer) error
- type RichSSHClientOption
- func WithDialTimeout(d time.Duration) RichSSHClientOption
- func WithJumpHost(host string, port int) RichSSHClientOption
- func WithPTY(enable bool) RichSSHClientOption
- func WithPassword(pw string) RichSSHClientOption
- func WithPrivateKeyFile(path string) RichSSHClientOption
- func WithPrivateKeyPEM(pem []byte) RichSSHClientOption
- func WithProxyURL(proxyURL string) RichSSHClientOption
- type RichSSHClientResponse
- type SSHClient
- func (s *SSHClient) Close() error
- func (s *SSHClient) Connect() error
- func (s *SSHClient) Download(src, dst string) error
- func (s *SSHClient) Run(command string) (int, error)
- func (s *SSHClient) RunWithWriter(command string, w io.Writer) (int, error)
- func (s *SSHClient) Upload(src, dst string) error
- type SSHClientOption
- func SSHOptionWithChunkSize(chunkSize uint16) SSHClientOption
- func SSHOptionWithLogger(logger glog.Logger) SSHClientOption
- func SSHOptionWithPassword(password string) SSHClientOption
- func SSHOptionWithProxy(proxyURL string) SSHClientOption
- func SSHOptionWithTimeout(timeout time.Duration) SSHClientOption
- func SSHOptionWithTunnel(tunnel *SSHTunnel) SSHClientOption
- type SSHTunnel
- type SSHTunnelEndpoint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type RichSSHClient ¶ added in v1.0.5
type RichSSHClient struct {
Host string
Port int
User string
Password string
PrivateKeyFile string
PrivateKey []byte // PEM bytes; if both Password and PrivateKey provided, use PrivateKey
JumpSSHHost string
JumpSSHPort int
ProxyURL string
EnablePTY bool // default false
// contains filtered or unexported fields
}
func NewRichSSHClient ¶ added in v1.0.5
func NewRichSSHClient(host string, port int, user string, opts ...RichSSHClientOption) *RichSSHClient
NewRichSSHClient builds client with defaults and options.
func (*RichSSHClient) Close ¶ added in v1.0.5
func (c *RichSSHClient) Close()
Close closes everything.
func (*RichSSHClient) Connect ¶ added in v1.0.5
func (c *RichSSHClient) Connect(ctx context.Context) error
Connect establishes SSH connection (handles jump/proxy).
func (*RichSSHClient) DownloadFile ¶ added in v1.0.5
func (c *RichSSHClient) DownloadFile(ctx context.Context, remotePath, localPath string, progressWriter io.Writer) error
DownloadFile downloads remotePath -> localPath. If progressWriter != nil, it will be written with bytes transferred.
func (*RichSSHClient) Run ¶ added in v1.0.5
func (c *RichSSHClient) Run(ctx context.Context, cmd string) (*RichSSHClientResponse, error)
Run executes a command and returns output and exit code.
func (*RichSSHClient) RunStream ¶ added in v1.0.5
func (c *RichSSHClient) RunStream(ctx context.Context, cmd string, outWriter, errWriter io.Writer) error
RunStream runs command, piping stdout/stderr to the provided writers in real time. outWriter and errWriter can be nil. PTY respects EnablePTY.
func (*RichSSHClient) UploadFile ¶ added in v1.0.5
func (c *RichSSHClient) UploadFile(ctx context.Context, localPath, remotePath string, progressWriter io.Writer) error
UploadFile uploads localPath -> remotePath. If progressWriter != nil, it will be written with bytes transferred.
type RichSSHClientOption ¶ added in v1.0.5
type RichSSHClientOption func(c *RichSSHClient)
func WithDialTimeout ¶ added in v1.0.5
func WithDialTimeout(d time.Duration) RichSSHClientOption
func WithJumpHost ¶ added in v1.0.5
func WithJumpHost(host string, port int) RichSSHClientOption
func WithPTY ¶ added in v1.0.5
func WithPTY(enable bool) RichSSHClientOption
func WithPassword ¶ added in v1.0.5
func WithPassword(pw string) RichSSHClientOption
func WithPrivateKeyFile ¶ added in v1.0.5
func WithPrivateKeyFile(path string) RichSSHClientOption
func WithPrivateKeyPEM ¶ added in v1.0.5
func WithPrivateKeyPEM(pem []byte) RichSSHClientOption
func WithProxyURL ¶ added in v1.0.5
func WithProxyURL(proxyURL string) RichSSHClientOption
type RichSSHClientResponse ¶ added in v1.0.5
type SSHClient ¶
type SSHClient struct {
// RSA 私钥证书路径或全文内容
PrivateKey string
// 主机 Domain/IP 地址
Host string
// SSH 端口
Port int
// SSH 登录用户名
User string
// SSH 登录密码
Password string
// 静默方式: 不输出 Stdout 信息
Quiet bool
// 是否已连接?
Connected bool
// SSH 客户端实例
Client *ssh.Client
// 代理服务器地址 (支持 http,https,socks5,socks5h, 例如: http://127.0.0.1:3128, socks5://127.0.0.1:1080)
Proxy string
// 超时时间 (默认不超时)
Timeout time.Duration
// 开启 TTY 终端模式
TTY bool
// 缓冲区大小 (默认: 8192 bytes)
ChunkSize uint16
// SSH 隧道
Tunnel *SSHTunnel
// Logger 接口对象
Logger glog.Logger
}
SSHClient SSH 客户端。
func NewSSHClient ¶
func (*SSHClient) RunWithWriter ¶
type SSHClientOption ¶
type SSHClientOption func(*SSHClient)
func SSHOptionWithChunkSize ¶
func SSHOptionWithChunkSize(chunkSize uint16) SSHClientOption
func SSHOptionWithLogger ¶
func SSHOptionWithLogger(logger glog.Logger) SSHClientOption
func SSHOptionWithPassword ¶
func SSHOptionWithPassword(password string) SSHClientOption
func SSHOptionWithProxy ¶
func SSHOptionWithProxy(proxyURL string) SSHClientOption
SSHOptionWithProxy 支持 http/https/socks5/socks5h 代理协议。
func SSHOptionWithTimeout ¶
func SSHOptionWithTimeout(timeout time.Duration) SSHClientOption
func SSHOptionWithTunnel ¶
func SSHOptionWithTunnel(tunnel *SSHTunnel) SSHClientOption
type SSHTunnel ¶
type SSHTunnel struct {
// 本地
Local *SSHTunnelEndpoint
// 隧道主机
Server *SSHTunnelEndpoint
// 目标主机
Remote *SSHTunnelEndpoint
// SSH 客户端配置
Config *ssh.ClientConfig
// contains filtered or unexported fields
}
type SSHTunnelEndpoint ¶
func (*SSHTunnelEndpoint) String ¶
func (endpoint *SSHTunnelEndpoint) String() string
Click to show internal directories.
Click to hide internal directories.