ssh

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SSHClient

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

SSHClient manages SSH connections.

func NewSSHClient

func NewSSHClient(config *SSHConfig) *SSHClient

NewSSHClient creates a new SSH client.

func (*SSHClient) Close

func (c *SSHClient) Close() error

Close closes the SSH connection.

func (*SSHClient) Connect

func (c *SSHClient) Connect(ctx context.Context) error

Connect establishes SSH connection.

func (*SSHClient) Download

func (c *SSHClient) Download(ctx context.Context, remotePath, localPath string) error

Download copies a remote file to local host via SFTP.

func (*SSHClient) Execute

func (c *SSHClient) Execute(ctx context.Context, command string) (string, int, error)

Execute runs a command on the remote host.

func (*SSHClient) IsConnected

func (c *SSHClient) IsConnected() bool

IsConnected checks if connection is alive.

func (*SSHClient) LastUse

func (c *SSHClient) LastUse() time.Time

LastUse returns the time of last activity.

func (*SSHClient) SessionKey

func (c *SSHClient) SessionKey() string

SessionKey returns a unique key for this session.

func (*SSHClient) Upload

func (c *SSHClient) Upload(ctx context.Context, localPath, remotePath string) error

Upload copies a local file to remote host via SFTP.

type SSHConfig

type SSHConfig struct {
	Host           string
	Port           int
	User           string
	KeyPath        string
	KeyPassphrase  string
	Password       string // Fallback if no key
	Timeout        time.Duration
	KnownHostsPath string
}

SSHConfig holds connection configuration.

func DefaultSSHConfig

func DefaultSSHConfig() *SSHConfig

DefaultSSHConfig returns a configuration with sensible defaults.

type SessionInfo

type SessionInfo struct {
	Key       string // "user@host:port"
	Host      string
	Port      int
	User      string
	Connected bool
	LastUse   time.Time
	IdleTime  time.Duration
}

SessionInfo represents information about an active SSH session.

type SessionManager

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

SessionManager manages persistent SSH sessions with connection pooling.

func NewSessionManager

func NewSessionManager() *SessionManager

NewSessionManager creates a session manager.

func (*SessionManager) CleanupIdle

func (m *SessionManager) CleanupIdle() int

CleanupIdle closes sessions idle longer than maxIdle.

func (*SessionManager) Close

func (m *SessionManager) Close(key string) error

Close closes a specific session.

func (*SessionManager) CloseAll

func (m *SessionManager) CloseAll()

CloseAll closes all sessions.

func (*SessionManager) Count

func (m *SessionManager) Count() int

Count returns the number of active sessions.

func (*SessionManager) Get

func (m *SessionManager) Get(key string) (*SSHClient, bool)

Get returns an existing session if it exists and is connected.

func (*SessionManager) GetOrCreate

func (m *SessionManager) GetOrCreate(ctx context.Context, config *SSHConfig) (*SSHClient, error)

GetOrCreate returns existing session or creates new one.

func (*SessionManager) List

func (m *SessionManager) List() []SessionInfo

List returns all active sessions.

func (*SessionManager) SetMaxIdle

func (m *SessionManager) SetMaxIdle(d time.Duration)

SetMaxIdle sets the maximum idle time before a session is closed.

func (*SessionManager) Stop

func (m *SessionManager) Stop()

Stop stops the cleanup goroutine and closes all sessions.

Jump to

Keyboard shortcuts

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