Documentation
¶
Overview ¶
Package ssh provides SSH operations for remote system management.
Index ¶
- func Ping(host string, port int, timeout time.Duration) bool
- type Client
- func (c *Client) CheckPort(ctx context.Context, port int) bool
- func (c *Client) Close() error
- func (c *Client) Connect() error
- func (c *Client) CopyFile(ctx context.Context, localPath, remotePath string) error
- func (c *Client) DirExists(ctx context.Context, remotePath string) bool
- func (c *Client) FileExists(ctx context.Context, remotePath string) bool
- func (c *Client) GetHost() string
- func (c *Client) GetSystemInfo(ctx context.Context) (*models.SystemInfo, error)
- func (c *Client) IsConnected() bool
- func (c *Client) MkdirAll(ctx context.Context, remotePath string) error
- func (c *Client) ReadFile(ctx context.Context, remotePath string) ([]byte, error)
- func (c *Client) Run(ctx context.Context, command string) (string, string, error)
- func (c *Client) RunWithSudo(ctx context.Context, command string) (string, string, error)
- func (c *Client) WriteFile(ctx context.Context, remotePath string, content []byte, mode os.FileMode) error
- type ClientOption
- func WithAutoAddHostKeys(auto bool) ClientOption
- func WithHost(host string) ClientOption
- func WithKeyPath(keyPath string) ClientOption
- func WithKnownHostsPath(path string) ClientOption
- func WithPort(port int) ClientOption
- func WithSSHTimeout(timeout time.Duration) ClientOption
- func WithStrictHostKey(strict bool) ClientOption
- func WithUser(user string) ClientOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles SSH connections
func (*Client) FileExists ¶
FileExists checks if a file exists on the remote host
func (*Client) GetSystemInfo ¶
GetSystemInfo retrieves system information from the remote host
func (*Client) IsConnected ¶
IsConnected returns whether the client is connected
func (*Client) RunWithSudo ¶
RunWithSudo runs a command with sudo. Multi-line commands are wrapped in sudo bash -c to ensure all lines run with elevated privileges.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures the SSH client
func WithAutoAddHostKeys ¶
func WithAutoAddHostKeys(auto bool) ClientOption
WithAutoAddHostKeys automatically adds unknown host keys
func WithKnownHostsPath ¶
func WithKnownHostsPath(path string) ClientOption
WithKnownHostsPath sets custom known_hosts file path
func WithSSHTimeout ¶
func WithSSHTimeout(timeout time.Duration) ClientOption
WithSSHTimeout sets the connection timeout
func WithStrictHostKey ¶
func WithStrictHostKey(strict bool) ClientOption
WithStrictHostKey enables strict host key checking
Click to show internal directories.
Click to hide internal directories.