sshclient

package
v0.0.0-...-1dbb744 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapCommand

func WrapCommand(cmd, activeCwd, sudoPassword string) (fullShellCmd, markerExit, markerCwd string)

WrapCommand prepares a shell command to execute inside a POSIX subshell (/bin/sh or sh) safely from ANY remote login shell (including fish, zsh, csh, tcsh, bash, ash, dash). It encodes the command via Base64 to guarantee complete character/quote/variable safety across all remote login shells. If sudoPassword is provided, it automatically configures a secure SUDO_ASKPASS wrapper so that any sudo invocation runs non-interactively without requiring a TTY or manual password prompts.

Types

type Client

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

func NewClient

func NewClient(cfg *config.Config) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) ConnectTo

func (c *Client) ConnectTo(host string, port int, user, keyPath, password, sudoPassword string) error

func (*Client) DownloadFile

func (c *Client) DownloadFile(remotePath, localPath string, overwrite bool) (int64, error)

func (*Client) EnsureConnected

func (c *Client) EnsureConnected() error

func (*Client) ExecRaw

func (c *Client) ExecRaw(cmd string) (string, string, int, error)

ExecRaw executes a remote command directly over an SSH session without wrappers. It returns stdout, stderr, exit code, and any transport error.

func (*Client) GetCwd

func (c *Client) GetCwd() string

func (*Client) GetSudoPassword

func (c *Client) GetSudoPassword() string

func (*Client) HasSudoPassword

func (c *Client) HasSudoPassword() bool

func (*Client) Herdr

func (c *Client) Herdr() *herdr.Manager

func (*Client) Host

func (c *Client) Host() string

func (*Client) IsConnected

func (c *Client) IsConnected() bool

func (*Client) ListDir

func (c *Client) ListDir(remotePath string) ([]DirEntryInfo, error)

func (*Client) ReplaceFileContent

func (c *Client) ReplaceFileContent(remotePath string, targetContent, replacementContent string, startLine, endLine int, allowMultiple bool) (*ReplaceResult, error)

func (*Client) ResolvePath

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

func (*Client) RunCommand

func (c *Client) RunCommand(cmd string, targetCwd string, isDaemon bool, waitMs int, opts ...CommandOptions) (*ExecResult, error)

func (*Client) SFTP

func (c *Client) SFTP() (*sftp.Client, error)

func (*Client) SSH

func (c *Client) SSH() (*ssh.Client, error)

func (*Client) SetCwd

func (c *Client) SetCwd(newCwd string)

func (*Client) SetSudoPassword

func (c *Client) SetSudoPassword(password string)

func (*Client) TaskManager

func (c *Client) TaskManager() *TaskManager

func (*Client) TunnelManager

func (c *Client) TunnelManager() *TunnelManager

func (*Client) UploadFile

func (c *Client) UploadFile(localPath, remotePath string, overwrite bool) (int64, error)

func (*Client) User

func (c *Client) User() string

func (*Client) ViewFile

func (c *Client) ViewFile(remotePath string, startLine, endLine int, offset int, maxBytes int) (*ViewResult, error)

func (*Client) WriteFile

func (c *Client) WriteFile(remotePath string, content []byte, overwrite bool) error

type CommandOptions

type CommandOptions struct {
	SudoPassword string
	RunAsSudo    bool
}

type DirEntryInfo

type DirEntryInfo struct {
	Name    string `json:"name"`
	IsDir   bool   `json:"is_dir"`
	Size    int64  `json:"size"`
	Mode    string `json:"mode"`
	ModTime string `json:"mod_time"`
}

type ExecResult

type ExecResult struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exit_code"`
	Cwd      string `json:"cwd"`
	IsAsync  bool   `json:"is_async,omitempty"`
	TaskID   string `json:"task_id,omitempty"`
}

type ReplaceResult

type ReplaceResult struct {
	Path         string `json:"path"`
	Replacements int    `json:"replacements"`
	TotalLines   int    `json:"total_lines"`
	Message      string `json:"message"`
}

type Task

type Task struct {
	ID        string
	Command   string
	Cwd       string
	StartTime time.Time
	Session   *ssh.Session
	Stdin     io.WriteCloser
	Stdout    *syncBuffer
	Stderr    *syncBuffer
	DoneChan  chan struct{}
	ExitCode  int
	Completed atomic.Bool
	ErrorMsg  string
}

func (*Task) Tail

func (t *Task) Tail(lines int) (stdoutTail, stderrTail string)

type TaskManager

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

func NewTaskManager

func NewTaskManager() *TaskManager

func (*TaskManager) Get

func (tm *TaskManager) Get(id string) (*Task, bool)

func (*TaskManager) Kill

func (tm *TaskManager) Kill(id string) error

func (*TaskManager) List

func (tm *TaskManager) List() []*Task

func (*TaskManager) Register

func (tm *TaskManager) Register(cmd, cwd string, sess *ssh.Session, stdin io.WriteCloser, stdout, stderr *syncBuffer) *Task

type Tunnel

type Tunnel struct {
	ID         string `json:"id"`
	LocalPort  int    `json:"local_port"`
	RemoteHost string `json:"remote_host"`
	RemotePort int    `json:"remote_port"`
	CreatedAt  string `json:"created_at"`
	// contains filtered or unexported fields
}

type TunnelManager

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

func NewTunnelManager

func NewTunnelManager(sshClientGetter func() (*ssh.Client, error)) *TunnelManager

func (*TunnelManager) Close

func (tm *TunnelManager) Close(id string) error

func (*TunnelManager) CloseAll

func (tm *TunnelManager) CloseAll()

func (*TunnelManager) List

func (tm *TunnelManager) List() []*Tunnel

func (*TunnelManager) Open

func (tm *TunnelManager) Open(localPort int, remoteHost string, remotePort int) (*Tunnel, error)

type ViewResult

type ViewResult struct {
	Path        string `json:"path"`
	TotalLines  int    `json:"total_lines"`
	StartLine   int    `json:"start_line"`
	EndLine     int    `json:"end_line"`
	Content     string `json:"content"`
	IsTruncated bool   `json:"is_truncated"`
}

Jump to

Keyboard shortcuts

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