starssh

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExecPoolClosed = errors.New("exec pool is closed")
View Source
var ErrHostFingerprintRequired = errors.New("host key fingerprint is required")
View Source
var ErrHostKeyCallbackRequired = errors.New("host key callback is required; use DefaultAllowHostKeyCallback to explicitly allow any host key")
View Source
var ErrKnownHostsFileRequired = errors.New("known_hosts file is required")
View Source
var ErrSSHAgentTimeout = errors.New("ssh-agent timeout")

Functions

func AcceptNewHostKeyCallback

func AcceptNewHostKeyCallback(file string) (func(string, net.Addr, ssh.PublicKey) error, error)

func AcceptNewHostKeyCallbackWithOptions

func AcceptNewHostKeyCallbackWithOptions(options AcceptNewHostKeyOptions) (func(string, net.Addr, ssh.PublicKey) error, error)

func DefaultAllowHostKeyCallback

func DefaultAllowHostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error

func FingerprintHostKeyCallback

func FingerprintHostKeyCallback(fingerprints ...string) (func(string, net.Addr, ssh.PublicKey) error, error)

func KnownHostsHostKeyCallback

func KnownHostsHostKeyCallback(files ...string) (func(string, net.Addr, ssh.PublicKey) error, error)

func NewExecSession

func NewExecSession(client *ssh.Client) (*ssh.Session, error)

func NewPTYSession

func NewPTYSession(client *ssh.Client, config *TerminalConfig) (*ssh.Session, error)

func NewSession

func NewSession(client *ssh.Client) (*ssh.Session, error)

func NewTransferSession

func NewTransferSession(client *ssh.Client) (*ssh.Session, error)

func SFTPBool

func SFTPBool(value bool) *bool

func SFTPDuration

func SFTPDuration(value time.Duration) *time.Duration

func SFTPInt

func SFTPInt(value int) *int

func SedColor

func SedColor(str string) string

func SftpTransferIn

func SftpTransferIn(src, dst string, sftpClient *sftp.Client) error

func SftpTransferInByte

func SftpTransferInByte(remotePath string, sftpClient *sftp.Client) ([]byte, error)

func SftpTransferInByteWithContext

func SftpTransferInByteWithContext(ctx context.Context, remotePath string, sftpClient *sftp.Client, options *SFTPTransferOptions) ([]byte, error)

func SftpTransferInFunc

func SftpTransferInFunc(src, dst string, bufcap int, rtefunc func(float64), sftpClient *sftp.Client) error

func SftpTransferInWithContext

func SftpTransferInWithContext(ctx context.Context, src, dst string, sftpClient *sftp.Client, options *SFTPTransferOptions) error

func SftpTransferOut

func SftpTransferOut(localFilePath, remotePath string, sftpClient *sftp.Client) error

func SftpTransferOutByte

func SftpTransferOutByte(localData []byte, remotePath string, sftpClient *sftp.Client) error

func SftpTransferOutByteWithContext

func SftpTransferOutByteWithContext(ctx context.Context, localData []byte, remotePath string, sftpClient *sftp.Client, options *SFTPTransferOptions) error

func SftpTransferOutFunc

func SftpTransferOutFunc(localFilePath, remotePath string, bufcap int, rtefunc func(float64), sftpClient *sftp.Client) error

func SftpTransferOutWithContext

func SftpTransferOutWithContext(ctx context.Context, localFilePath, remotePath string, sftpClient *sftp.Client, options *SFTPTransferOptions) error

Types

type AcceptNewHostKeyOptions

type AcceptNewHostKeyOptions struct {
	KnownHostsFile       string
	HashHosts            bool
	IncludeRemoteAddress bool
	FileMode             os.FileMode
}

type AuthMethodKind

type AuthMethodKind string
const (
	AuthMethodPrivateKey          AuthMethodKind = "private_key"
	AuthMethodPassword            AuthMethodKind = "password"
	AuthMethodKeyboardInteractive AuthMethodKind = "keyboard_interactive"
	AuthMethodSSHAgent            AuthMethodKind = "ssh_agent"
)

type DialContextFunc

type DialContextFunc func(ctx context.Context, network, address string) (net.Conn, error)

type DynamicForwardRequest

type DynamicForwardRequest struct {
	ListenAddr string
}

type ExecExitError

type ExecExitError struct {
	Status  int
	Signal  string
	Message string
	Stderr  string
}

func (*ExecExitError) Error

func (e *ExecExitError) Error() string

func (*ExecExitError) ExitStatus

func (e *ExecExitError) ExitStatus() int

type ExecPool

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

func NewExecPool

func NewExecPool(config ExecPoolConfig) *ExecPool

func (*ExecPool) Acquire

func (p *ExecPool) Acquire(ctx context.Context) (*StarSSH, error)

func (*ExecPool) Close

func (p *ExecPool) Close() error

func (*ExecPool) CloseIdle

func (p *ExecPool) CloseIdle() error

func (*ExecPool) Discard

func (p *ExecPool) Discard(client *StarSSH)

func (*ExecPool) Exec

func (p *ExecPool) Exec(ctx context.Context, req ExecRequest) (*ExecResult, error)

func (*ExecPool) ExecStream

func (p *ExecPool) ExecStream(ctx context.Context, req ExecRequest, onChunk func(ExecStreamChunk)) (*ExecResult, error)

func (*ExecPool) ExecString

func (p *ExecPool) ExecString(ctx context.Context, command string) (*ExecResult, error)

func (*ExecPool) Release

func (p *ExecPool) Release(client *StarSSH) error

func (*ExecPool) Stats

func (p *ExecPool) Stats() ExecPoolStats

func (*ExecPool) WarmUp

func (p *ExecPool) WarmUp(ctx context.Context, targetIdle int) error

type ExecPoolConfig

type ExecPoolConfig struct {
	Login              LoginInput
	MaxOpenConns       int
	MaxIdleConns       int
	MaxIdleTime        time.Duration
	DisableHealthCheck bool
	HealthCheckTimeout time.Duration
}

type ExecPoolStats

type ExecPoolStats struct {
	MaxOpenConns int
	MaxIdleConns int
	MaxIdleTime  time.Duration
	OpenConns    int
	IdleConns    int
	InUseConns   int
}

type ExecRequest

type ExecRequest struct {
	Command                string
	Stdin                  []byte
	Env                    map[string]string
	Dir                    string
	ShellDialect           ExecShellDialect
	Timeout                time.Duration
	PTY                    *TerminalConfig
	DiscardOutput          bool
	MaxOutputBytes         int
	StreamMaxPendingChunks int
	StreamMaxPendingBytes  int
	StreamOverflowStrategy ExecStreamOverflowStrategy
}

type ExecResult

type ExecResult struct {
	Command             string
	Stdout              []byte
	Stderr              []byte
	Combined            []byte
	StdoutTruncated     bool
	StderrTruncated     bool
	CombinedTruncated   bool
	StreamDroppedChunks int
	StreamDroppedBytes  int
	ExitCode            int
	ExitSignal          string
	ExitMessage         string
	Duration            time.Duration
}

func (*ExecResult) CombinedString

func (r *ExecResult) CombinedString() string

func (*ExecResult) CommandError

func (r *ExecResult) CommandError() error

func (*ExecResult) OutputTruncated

func (r *ExecResult) OutputTruncated() bool

func (*ExecResult) StderrString

func (r *ExecResult) StderrString() string

func (*ExecResult) StdoutString

func (r *ExecResult) StdoutString() string

func (*ExecResult) StreamOutputDropped

func (r *ExecResult) StreamOutputDropped() bool

func (*ExecResult) StreamOverflowError

func (r *ExecResult) StreamOverflowError() error

func (*ExecResult) Success

func (r *ExecResult) Success() bool

type ExecShellDialect

type ExecShellDialect string
const (
	ExecShellDialectPOSIX      ExecShellDialect = "posix"
	ExecShellDialectPowerShell ExecShellDialect = "powershell"
	ExecShellDialectCMD        ExecShellDialect = "cmd"
	ExecShellDialectRaw        ExecShellDialect = "raw"
)

type ExecStreamChunk

type ExecStreamChunk struct {
	Data   []byte
	Stderr bool
}

type ExecStreamOverflowError

type ExecStreamOverflowError struct {
	DroppedChunks int
	DroppedBytes  int
}

func (*ExecStreamOverflowError) Error

func (e *ExecStreamOverflowError) Error() string

type ExecStreamOverflowStrategy

type ExecStreamOverflowStrategy string
const (
	ExecStreamOverflowDropOldest ExecStreamOverflowStrategy = "drop_oldest"
	ExecStreamOverflowDropNewest ExecStreamOverflowStrategy = "drop_newest"
	ExecStreamOverflowFail       ExecStreamOverflowStrategy = "fail"
)

type ForwardRequest

type ForwardRequest struct {
	// Keep the exported shape compatible with older positional literals:
	// ForwardRequest{listenAddr, targetAddr, dialContext}.
	//
	// Non-default networks can be encoded with an explicit scheme-like prefix:
	// "tcp4://127.0.0.1:22", "tcp6://[::1]:22", "unix:///tmp/socket".
	// Bare values default to the "tcp" network.
	ListenAddr  string
	TargetAddr  string
	DialContext DialContextFunc
}

type HostKeyFingerprintMismatchError

type HostKeyFingerprintMismatchError struct {
	Expected        []string
	ActualSHA256    string
	ActualLegacyMD5 string
}

func (*HostKeyFingerprintMismatchError) Error

type LoginInput

type LoginInput struct {
	KeyExchanges                []string
	Ciphers                     []string
	MACs                        []string
	User                        string
	Password                    string
	PasswordCallback            func() (string, error)
	KeyboardInteractiveCallback ssh.KeyboardInteractiveChallenge
	Prikey                      string
	PrikeyPwd                   string
	DisableSSHAgent             bool
	ForwardSSHAgent             bool
	AuthOrder                   []AuthMethodKind
	// IdentityAgent overrides the local ssh-agent endpoint used for authentication
	// and agent forwarding. Empty uses SSH_AUTH_SOCK, or the platform default where
	// one exists.
	IdentityAgent string
	Addr          string
	Port          int
	// Timeout limits the SSH handshake/authentication phase after a TCP connection has
	// already been established. Zero means no authentication timeout.
	Timeout time.Duration
	// DialTimeout limits outbound dial steps such as TCP connect, proxy connect, and
	// local ssh-agent socket connect. Zero falls back to Timeout when set, otherwise
	// uses the package default dial timeout. Negative disables the default dial timeout.
	DialTimeout time.Duration
	// SSHAgentTimeout limits ssh-agent protocol operations such as listing keys and
	// signing challenges. Zero uses the package default, and negative disables the
	// per-operation deadline. This is intentionally separate from Timeout and
	// DialTimeout because hardware-backed agents may require a PIN or touch confirmation.
	SSHAgentTimeout time.Duration
	// SSHAgentForwardTimeout limits idle reads and writes on forwarded agent
	// channels. Zero or negative leaves forwarded channels without an idle deadline.
	SSHAgentForwardTimeout time.Duration
	// SSHAgentDebug receives structured ssh-agent dial/protocol events. It is nil by
	// default and must not log private key material.
	SSHAgentDebug     SSHAgentDebugFunc
	DialContext       DialContextFunc
	Proxy             *ProxyConfig
	Jump              *LoginInput
	KeepAliveInterval time.Duration
	KeepAliveTimeout  time.Duration
	HostKeyCallback   func(string, net.Addr, ssh.PublicKey) error
	BannerCallback    func(string) error
}

type PortForwarder

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

func (*PortForwarder) Addr

func (f *PortForwarder) Addr() net.Addr

func (*PortForwarder) Close

func (f *PortForwarder) Close() error

func (*PortForwarder) Err

func (f *PortForwarder) Err() error

func (*PortForwarder) Wait

func (f *PortForwarder) Wait() error

type ProxyConfig

type ProxyConfig struct {
	Type     ProxyType
	Addr     string
	Username string
	Password string
	Timeout  time.Duration
}

type ProxyType

type ProxyType string
const (
	ProxyTypeSOCKS5      ProxyType = "socks5"
	ProxyTypeHTTPConnect ProxyType = "http_connect"
)

type SFTPClientOptions added in v0.1.4

type SFTPClientOptions struct {
	MaxPacketSize                int
	MaxConcurrentRequestsPerFile int
	ConcurrentReads              *bool
	ConcurrentWrites             *bool
}

SFTPClientOptions controls the underlying SFTP protocol client.

These options only apply when StarSSH creates the SFTP client internally. They are intentionally separate from BufferSize, which only controls the local copy buffer used by transfer progress reporting.

type SFTPErrorCategory

type SFTPErrorCategory string
const (
	SFTPErrorRetryable SFTPErrorCategory = "retryable"
	SFTPErrorPermanent SFTPErrorCategory = "permanent"
)

type SFTPFileSystem

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

func (*SFTPFileSystem) MkdirAll

func (fs *SFTPFileSystem) MkdirAll(ctx context.Context, remotePath string) error

func (*SFTPFileSystem) ReadDir

func (fs *SFTPFileSystem) ReadDir(ctx context.Context, remotePath string) ([]os.FileInfo, error)

func (*SFTPFileSystem) ReadFile

func (fs *SFTPFileSystem) ReadFile(ctx context.Context, remotePath string, options *SFTPTransferOptions) ([]byte, error)

func (*SFTPFileSystem) Remove

func (fs *SFTPFileSystem) Remove(ctx context.Context, remotePath string) error

func (*SFTPFileSystem) RemoveAll

func (fs *SFTPFileSystem) RemoveAll(ctx context.Context, remotePath string) error

func (*SFTPFileSystem) Rename

func (fs *SFTPFileSystem) Rename(ctx context.Context, oldPath string, newPath string) error

func (*SFTPFileSystem) Stat

func (fs *SFTPFileSystem) Stat(ctx context.Context, remotePath string) (os.FileInfo, error)

func (*SFTPFileSystem) WriteFile

func (fs *SFTPFileSystem) WriteFile(ctx context.Context, remotePath string, data []byte, options *SFTPTransferOptions) error

type SFTPTransferError

type SFTPTransferError struct {
	Operation  string
	LocalPath  string
	RemotePath string
	Attempt    int
	Category   SFTPErrorCategory
	Err        error
}

func (*SFTPTransferError) Error

func (e *SFTPTransferError) Error() string

func (*SFTPTransferError) Unwrap

func (e *SFTPTransferError) Unwrap() error

type SFTPTransferOptions

type SFTPTransferOptions struct {
	BufferSize          int
	Progress            func(float64)
	RetryCount          *int
	RetryInitialBackoff *time.Duration
	AtomicUpload        *bool
	AtomicDownload      *bool
	VerifySize          *bool
	VerifyChecksum      *bool
	TempSuffix          string
	Client              SFTPClientOptions
}

func DefaultSFTPTransferOptions

func DefaultSFTPTransferOptions() SFTPTransferOptions

func ThroughputSFTPTransferOptions added in v0.1.4

func ThroughputSFTPTransferOptions() SFTPTransferOptions

type SSHAgentDebugEvent added in v0.1.3

type SSHAgentDebugEvent struct {
	Step     string
	Source   string
	Endpoint string
	Network  string
	Phase    string
	Status   string
	Duration time.Duration
	KeyCount int
	Err      error
}

type SSHAgentDebugFunc added in v0.1.3

type SSHAgentDebugFunc func(SSHAgentDebugEvent)

type ShellExitError

type ShellExitError = ExecExitError

type ShellRequest

type ShellRequest struct {
	Command        string
	Timeout        time.Duration
	Keyword        string
	UseWaitDefault *bool
}

type StarSSH

type StarSSH struct {
	Client       *ssh.Client
	PublicKey    ssh.PublicKey
	PubkeyBase64 string
	Hostname     string
	RemoteAddr   net.Addr
	Banner       string
	LoginInfo    LoginInput
	// contains filtered or unexported fields
}

func Login

func Login(info LoginInput) (*StarSSH, error)

func LoginContext

func LoginContext(ctx context.Context, info LoginInput) (*StarSSH, error)

func LoginSimple

func LoginSimple(host string, user string, passwd string, prikeyPath string, port int, timeout time.Duration) (*StarSSH, error)

func (*StarSSH) Close

func (s *StarSSH) Close() error

func (*StarSSH) CreateSftpClient

func (star *StarSSH) CreateSftpClient() (*sftp.Client, error)

func (*StarSSH) DialTCP

func (s *StarSSH) DialTCP(network string, address string) (net.Conn, error)

func (*StarSSH) DialTCPContext

func (s *StarSSH) DialTCPContext(ctx context.Context, network string, address string) (net.Conn, error)

func (*StarSSH) DialTCPContextCloseOnCancel

func (s *StarSSH) DialTCPContextCloseOnCancel(ctx context.Context, network string, address string) (net.Conn, error)

func (*StarSSH) Exec

func (s *StarSSH) Exec(ctx context.Context, req ExecRequest) (*ExecResult, error)

func (*StarSSH) ExecStream

func (s *StarSSH) ExecStream(ctx context.Context, req ExecRequest, onChunk func(ExecStreamChunk)) (*ExecResult, error)

func (*StarSSH) ExecString

func (s *StarSSH) ExecString(ctx context.Context, command string) (*ExecResult, error)

func (*StarSSH) Exists

func (s *StarSSH) Exists(filepath string) bool

func (*StarSSH) FS

func (star *StarSSH) FS() *SFTPFileSystem

func (*StarSSH) GetGid

func (s *StarSSH) GetGid() string

func (*StarSSH) GetGroup

func (s *StarSSH) GetGroup() string

func (*StarSSH) GetUid

func (s *StarSSH) GetUid() string

func (*StarSSH) GetUser

func (s *StarSSH) GetUser() string

func (*StarSSH) IsFile

func (s *StarSSH) IsFile(filepath string) bool

func (*StarSSH) IsFolder

func (s *StarSSH) IsFolder(filepath string) bool

func (*StarSSH) MkdirAll

func (star *StarSSH) MkdirAll(remotePath string) error

func (*StarSSH) MkdirAllContext

func (star *StarSSH) MkdirAllContext(ctx context.Context, remotePath string) error

func (*StarSSH) NewExecSession

func (s *StarSSH) NewExecSession() (*ssh.Session, error)

func (*StarSSH) NewPTYSession

func (s *StarSSH) NewPTYSession(config *TerminalConfig) (*ssh.Session, error)

func (*StarSSH) NewSession

func (s *StarSSH) NewSession() (*ssh.Session, error)

func (*StarSSH) NewShell

func (s *StarSSH) NewShell() (shell *StarShell, err error)

NewShell creates the legacy prompt-driven POSIX shell helper. For raw interactive terminal flows, prefer NewTerminal.

func (*StarSSH) NewTerminal

func (s *StarSSH) NewTerminal(config *TerminalConfig) (*TerminalSession, error)

func (*StarSSH) Ping

func (s *StarSSH) Ping() error

func (*StarSSH) PingContext

func (s *StarSSH) PingContext(ctx context.Context) error

func (*StarSSH) PingContextCloseOnCancel

func (s *StarSSH) PingContextCloseOnCancel(ctx context.Context) error

func (*StarSSH) ReadDir

func (star *StarSSH) ReadDir(remotePath string) ([]os.FileInfo, error)

func (*StarSSH) ReadDirContext

func (star *StarSSH) ReadDirContext(ctx context.Context, remotePath string) ([]os.FileInfo, error)

func (*StarSSH) ReadFile

func (star *StarSSH) ReadFile(remotePath string) ([]byte, error)

func (*StarSSH) ReadFileContext

func (star *StarSSH) ReadFileContext(ctx context.Context, remotePath string, options *SFTPTransferOptions) ([]byte, error)

func (*StarSSH) Remove

func (star *StarSSH) Remove(remotePath string) error

func (*StarSSH) RemoveAll

func (star *StarSSH) RemoveAll(remotePath string) error

func (*StarSSH) RemoveAllContext

func (star *StarSSH) RemoveAllContext(ctx context.Context, remotePath string) error

func (*StarSSH) RemoveContext

func (star *StarSSH) RemoveContext(ctx context.Context, remotePath string) error

func (*StarSSH) Rename

func (star *StarSSH) Rename(oldPath string, newPath string) error

func (*StarSSH) RenameContext

func (star *StarSSH) RenameContext(ctx context.Context, oldPath string, newPath string) error

func (*StarSSH) RequestAgentForwarding added in v0.1.1

func (s *StarSSH) RequestAgentForwarding(session *ssh.Session) error

func (*StarSSH) SftpTransferIn

func (star *StarSSH) SftpTransferIn(src, dst string) error

func (*StarSSH) SftpTransferInByte

func (star *StarSSH) SftpTransferInByte(remotePath string) ([]byte, error)

func (*StarSSH) SftpTransferInByteContext

func (star *StarSSH) SftpTransferInByteContext(ctx context.Context, remotePath string, options *SFTPTransferOptions) ([]byte, error)

func (*StarSSH) SftpTransferInContext

func (star *StarSSH) SftpTransferInContext(ctx context.Context, src, dst string, options *SFTPTransferOptions) error

func (*StarSSH) SftpTransferInFunc

func (star *StarSSH) SftpTransferInFunc(src, dst string, bufcap int, rtefunc func(float64)) error

func (*StarSSH) SftpTransferOut

func (star *StarSSH) SftpTransferOut(localFilePath, remotePath string) error

func (*StarSSH) SftpTransferOutByte

func (star *StarSSH) SftpTransferOutByte(localData []byte, remotePath string) error

func (*StarSSH) SftpTransferOutByteContext

func (star *StarSSH) SftpTransferOutByteContext(ctx context.Context, localData []byte, remotePath string, options *SFTPTransferOptions) error

func (*StarSSH) SftpTransferOutContext

func (star *StarSSH) SftpTransferOutContext(ctx context.Context, localFilePath, remotePath string, options *SFTPTransferOptions) error

func (*StarSSH) SftpTransferOutFunc

func (star *StarSSH) SftpTransferOutFunc(localFilePath, remotePath string, bufcap int, rtefunc func(float64)) error

func (*StarSSH) ShellOne

func (s *StarSSH) ShellOne(cmd string) (string, error)

func (*StarSSH) ShellOneShowScreen

func (s *StarSSH) ShellOneShowScreen(cmd string) (string, error)

func (*StarSSH) ShellOneShowScreenResult

func (s *StarSSH) ShellOneShowScreenResult(cmd string) (*ExecResult, error)

func (*StarSSH) ShellOneToFunc

func (s *StarSSH) ShellOneToFunc(cmd string, callback func(string)) (string, error)

func (*StarSSH) ShellOneToFuncResult

func (s *StarSSH) ShellOneToFuncResult(cmd string, callback func(string)) (*ExecResult, error)

func (*StarSSH) StartDynamicForward

func (s *StarSSH) StartDynamicForward(req DynamicForwardRequest) (*PortForwarder, error)

func (*StarSSH) StartDynamicForwardDetached

func (s *StarSSH) StartDynamicForwardDetached(req DynamicForwardRequest) (*PortForwarder, error)

func (*StarSSH) StartLocalForward

func (s *StarSSH) StartLocalForward(req ForwardRequest) (*PortForwarder, error)

func (*StarSSH) StartLocalForwardDetached

func (s *StarSSH) StartLocalForwardDetached(req ForwardRequest) (*PortForwarder, error)

func (*StarSSH) StartLocalTCPForward added in v0.1.1

func (s *StarSSH) StartLocalTCPForward(listenAddr string, targetAddr string) (*PortForwarder, error)

func (*StarSSH) StartLocalTCPForwardDetached added in v0.1.1

func (s *StarSSH) StartLocalTCPForwardDetached(listenAddr string, targetAddr string) (*PortForwarder, error)

func (*StarSSH) StartLocalTCPToUnixForward added in v0.1.1

func (s *StarSSH) StartLocalTCPToUnixForward(listenAddr string, targetPath string) (*PortForwarder, error)

func (*StarSSH) StartLocalTCPToUnixForwardDetached added in v0.1.1

func (s *StarSSH) StartLocalTCPToUnixForwardDetached(listenAddr string, targetPath string) (*PortForwarder, error)

func (*StarSSH) StartLocalUnixForward added in v0.1.1

func (s *StarSSH) StartLocalUnixForward(listenPath string, targetAddr string) (*PortForwarder, error)

func (*StarSSH) StartLocalUnixForwardDetached added in v0.1.1

func (s *StarSSH) StartLocalUnixForwardDetached(listenPath string, targetAddr string) (*PortForwarder, error)

func (*StarSSH) StartLocalUnixToUnixForward added in v0.1.1

func (s *StarSSH) StartLocalUnixToUnixForward(listenPath string, targetPath string) (*PortForwarder, error)

func (*StarSSH) StartLocalUnixToUnixForwardDetached added in v0.1.1

func (s *StarSSH) StartLocalUnixToUnixForwardDetached(listenPath string, targetPath string) (*PortForwarder, error)

func (*StarSSH) StartRemoteForward

func (s *StarSSH) StartRemoteForward(req ForwardRequest) (*PortForwarder, error)

func (*StarSSH) StartRemoteTCPForward added in v0.1.1

func (s *StarSSH) StartRemoteTCPForward(listenAddr string, targetAddr string) (*PortForwarder, error)

func (*StarSSH) StartRemoteTCPToUnixForward added in v0.1.1

func (s *StarSSH) StartRemoteTCPToUnixForward(listenAddr string, targetPath string) (*PortForwarder, error)

func (*StarSSH) StartRemoteUnixForward added in v0.1.1

func (s *StarSSH) StartRemoteUnixForward(listenPath string, targetAddr string) (*PortForwarder, error)

func (*StarSSH) StartRemoteUnixToUnixForward added in v0.1.1

func (s *StarSSH) StartRemoteUnixToUnixForward(listenPath string, targetPath string) (*PortForwarder, error)

func (*StarSSH) Stat

func (star *StarSSH) Stat(remotePath string) (os.FileInfo, error)

func (*StarSSH) StatContext

func (star *StarSSH) StatContext(ctx context.Context, remotePath string) (os.FileInfo, error)

func (*StarSSH) WriteFile

func (star *StarSSH) WriteFile(remotePath string, data []byte) error

func (*StarSSH) WriteFileContext

func (star *StarSSH) WriteFileContext(ctx context.Context, remotePath string, data []byte, options *SFTPTransferOptions) error

type StarShell

type StarShell struct {
	Keyword        string
	UseWaitDefault bool
	WaitTimeout    time.Duration
	Session        *ssh.Session
	// contains filtered or unexported fields
}

StarShell keeps the legacy prompt-driven helper for POSIX-style scripted shell interactions. It is not a generic cross-shell abstraction; for product-grade interactive terminals, prefer TerminalSession.

func (*StarShell) Clear

func (s *StarShell) Clear()

func (*StarShell) Close

func (s *StarShell) Close() error

func (*StarShell) GetGid

func (s *StarShell) GetGid() string

func (*StarShell) GetGroup

func (s *StarShell) GetGroup() string

func (*StarShell) GetResult

func (s *StarShell) GetResult(sleep int) ([]byte, []byte, error)

func (*StarShell) GetUid

func (s *StarShell) GetUid() string

func (*StarShell) GetUser

func (s *StarShell) GetUser() string

func (*StarShell) Run

func (s *StarShell) Run(ctx context.Context, req ShellRequest) (*ExecResult, error)

func (*StarShell) RunString

func (s *StarShell) RunString(ctx context.Context, command string) (*ExecResult, error)

func (*StarShell) SetFunc

func (s *StarShell) SetFunc(funcs func(string))

func (*StarShell) Shell

func (s *StarShell) Shell(cmd string, sleep int) (string, string, error)

func (*StarShell) ShellClear

func (s *StarShell) ShellClear(cmd string, sleep int) (string, string, error)

func (*StarShell) ShellWait

func (s *StarShell) ShellWait(cmd string) (string, string, error)

func (*StarShell) SwitchEcho

func (s *StarShell) SwitchEcho(run bool)

func (*StarShell) SwitchFunc

func (s *StarShell) SwitchFunc(run bool)

本函数控制是否立即处理远程Shell输出每一行内容[true|false]

func (*StarShell) SwitchNoColor

func (s *StarShell) SwitchNoColor(run bool)

func (*StarShell) SwitchPrint

func (s *StarShell) SwitchPrint(run bool)

本函数控制是否在本地屏幕上打印远程Shell的输出内容[true|false]

func (*StarShell) TrimColor

func (s *StarShell) TrimColor(str string) string

func (*StarShell) Write

func (s *StarShell) Write(bstr []byte) error

func (*StarShell) WriteCommand

func (s *StarShell) WriteCommand(cmd string) error

type TerminalCloseReason

type TerminalCloseReason string
const (
	TerminalCloseReasonUnknown          TerminalCloseReason = ""
	TerminalCloseReasonExit             TerminalCloseReason = "exit"
	TerminalCloseReasonSignal           TerminalCloseReason = "signal"
	TerminalCloseReasonClosed           TerminalCloseReason = "closed"
	TerminalCloseReasonContextCanceled  TerminalCloseReason = "context_canceled"
	TerminalCloseReasonDeadlineExceeded TerminalCloseReason = "deadline_exceeded"
	TerminalCloseReasonTransportError   TerminalCloseReason = "transport_error"
)

type TerminalConfig

type TerminalConfig struct {
	Term    string
	Rows    int
	Columns int
	Modes   ssh.TerminalModes
}

type TerminalControl

type TerminalControl byte
const (
	TerminalControlInterrupt    TerminalControl = 0x03
	TerminalControlEOF          TerminalControl = 0x04
	TerminalControlBell         TerminalControl = 0x07
	TerminalControlBackspace    TerminalControl = 0x08
	TerminalControlLineKill     TerminalControl = 0x15
	TerminalControlQuit         TerminalControl = 0x1c
	TerminalControlSuspend      TerminalControl = 0x1a
	TerminalControlPauseOutput  TerminalControl = 0x13
	TerminalControlResumeOutput TerminalControl = 0x11
)

type TerminalExitInfo

type TerminalExitInfo struct {
	ExitCode    int
	ExitSignal  string
	ExitMessage string
	Reason      TerminalCloseReason
}

func (TerminalExitInfo) CommandError

func (info TerminalExitInfo) CommandError() error

func (TerminalExitInfo) Success

func (info TerminalExitInfo) Success() bool

type TerminalInputAdapter

type TerminalInputAdapter struct {
	Reader io.Reader
	Source io.Reader
	Cancel func() error
}

TerminalInputAdapter adapts wrapper readers into a cancelable terminal input source. Reader is what TerminalSession consumes, Source is the closer-friendly underlying reader when available.

func (TerminalInputAdapter) Read

func (a TerminalInputAdapter) Read(p []byte) (int, error)

func (TerminalInputAdapter) TerminalInputCancel

func (a TerminalInputAdapter) TerminalInputCancel() error

func (TerminalInputAdapter) TerminalInputSource

func (a TerminalInputAdapter) TerminalInputSource() io.Reader

type TerminalInputCanceler

type TerminalInputCanceler interface {
	TerminalInputCancel() error
}

TerminalInputCanceler lets wrapper readers expose an explicit cancellation hook. It is useful for line editors or custom buffered readers that cannot safely expose a raw io.ReadCloser.

type TerminalInputSourceProvider

type TerminalInputSourceProvider interface {
	TerminalInputSource() io.Reader
}

TerminalInputSourceProvider lets wrapper readers expose a closer-friendly source reader. Implementations that buffer data should return a source that already includes any prefetched bytes.

type TerminalSession

type TerminalSession struct {
	Session  *ssh.Session
	ID       string
	Label    string
	Metadata map[string]string
	// contains filtered or unexported fields
}

func (*TerminalSession) AttachIO

func (t *TerminalSession) AttachIO(stdin io.Reader, stdout io.Writer, stderr io.Writer)

func (*TerminalSession) Close

func (t *TerminalSession) Close() error

func (*TerminalSession) ExitInfo

func (t *TerminalSession) ExitInfo() TerminalExitInfo

func (*TerminalSession) Interrupt

func (t *TerminalSession) Interrupt() error

func (*TerminalSession) Resize

func (t *TerminalSession) Resize(columns int, rows int) error

func (*TerminalSession) Run

func (t *TerminalSession) Run(ctx context.Context) error

func (*TerminalSession) SendControl

func (t *TerminalSession) SendControl(control TerminalControl) error

func (*TerminalSession) Signal

func (t *TerminalSession) Signal(sig ssh.Signal) error

func (*TerminalSession) StderrReader

func (t *TerminalSession) StderrReader() io.Reader

func (*TerminalSession) StdinWriter

func (t *TerminalSession) StdinWriter() io.Writer

func (*TerminalSession) StdoutReader

func (t *TerminalSession) StdoutReader() io.Reader

func (*TerminalSession) Wait

func (t *TerminalSession) Wait() error

func (*TerminalSession) WaitResult

func (t *TerminalSession) WaitResult() (TerminalExitInfo, error)

func (*TerminalSession) Write

func (t *TerminalSession) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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