webssh

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultResizeControlPrefix = "\x00webssh:resize:"

Variables

This section is empty.

Functions

func Connect

func Connect(ws *websocket.Conn, opt *SSHClientOption) error

func ConnectWithOptions added in v0.20.0

func ConnectWithOptions(ws *websocket.Conn, opt *SSHClientOption, connectOpt ConnectOptions) error

func ConnectWithResize added in v0.20.0

func ConnectWithResize(ws *websocket.Conn, opt *SSHClientOption) error

func NewSSHClient

func NewSSHClient(option *SSHClientOption) (*ssh.Client, error)

func NewSSHClientWithPassword

func NewSSHClientWithPassword(option *SSHClientOption) (*ssh.Client, error)

func NewSSHClientWithPrivateKey

func NewSSHClientWithPrivateKey(option *SSHClientOption) (*ssh.Client, error)

Types

type AuthModel

type AuthModel int8

type ConnectOptions added in v0.20.0

type ConnectOptions struct {
	ResizeControlPrefix string
	InitialWidth        int
	InitialHeight       int
}

type FileInfo added in v0.16.0

type FileInfo struct {
	Name       string `json:"name"`
	Size       int64  `json:"size"`
	Mode       string `json:"mode"`
	ModTime    int64  `json:"modTime"`
	IsDir      bool   `json:"isDir"`
	IsLink     bool   `json:"isLink"`
	LinkTarget string `json:"linkTarget,omitempty"`
}

FileInfo SFTP 文件/目录信息

type ListResult added in v0.16.0

type ListResult struct {
	Path  string      `json:"path"`
	Files []*FileInfo `json:"files"`
}

ListResult 目录列表结果(含实际路径)

type SFTPClient added in v0.16.0

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

SFTPClient SFTP 客户端,内置连接池,按 user@addr 复用连接

func NewSFTPClient added in v0.16.0

func NewSFTPClient(idleTimeout time.Duration) *SFTPClient

NewSFTPClient 创建 SFTP 客户端,idleTimeout 为 0 时使用默认值 30s

func (*SFTPClient) Chmod added in v0.16.1

func (c *SFTPClient) Chmod(opt *SSHClientOption, path string, mode os.FileMode) error

Chmod 修改文件权限

func (*SFTPClient) Chown added in v0.16.1

func (c *SFTPClient) Chown(opt *SSHClientOption, path string, uid, gid int) error

Chown 修改文件所有者和组

func (*SFTPClient) Chtimes added in v0.16.1

func (c *SFTPClient) Chtimes(opt *SSHClientOption, path string, atime, mtime time.Time) error

Chtimes 修改文件访问时间和修改时间

func (*SFTPClient) Close added in v0.16.0

func (c *SFTPClient) Close()

Close 关闭客户端,释放所有连接

func (*SFTPClient) DirSize added in v0.16.1

func (c *SFTPClient) DirSize(opt *SSHClientOption, dirPath string) (int64, error)

DirSize 递归计算目录大小(包含所有子目录和文件)

func (*SFTPClient) Download added in v0.16.0

func (c *SFTPClient) Download(opt *SSHClientOption, filePath string, dst io.Writer) error

Download 下载远程文件到 dst(使用 WriteTo 优化传输)

func (*SFTPClient) Glob added in v0.16.1

func (c *SFTPClient) Glob(opt *SSHClientOption, pattern string) ([]string, error)

Glob 根据模式匹配文件路径(如 *.txt, /path/*.log) 返回匹配的文件路径列表

func (*SFTPClient) IsTextFile added in v0.16.1

func (c *SFTPClient) IsTextFile(opt *SSHClientOption, filePath string) (bool, error)

IsTextFile 判断远程文件是否为文本文件(判断规则同 filer.IsTextBytes)

func (c *SFTPClient) Link(opt *SSHClientOption, oldname, newname string) error

Link 创建硬链接,newname 指向 oldname 的同一个 inode

func (*SFTPClient) List added in v0.16.0

func (c *SFTPClient) List(opt *SSHClientOption, dirPath string) (*ListResult, error)

List 列出目录内容,dirPath 为空或 "~" 时使用远程 home 目录

func (*SFTPClient) Lstat added in v0.16.1

func (c *SFTPClient) Lstat(opt *SSHClientOption, p string) (os.FileInfo, error)

Lstat 获取文件信息(不跟随符号链接,返回链接本身的信息)

func (*SFTPClient) Mkdir added in v0.16.0

func (c *SFTPClient) Mkdir(opt *SSHClientOption, dirPath string) error

Mkdir 递归创建目录

func (*SFTPClient) Move added in v0.16.1

func (c *SFTPClient) Move(opt *SSHClientOption, srcPath, dstPath string, overwrite bool) error

Move 移动文件或目录(实际上是重命名的封装,支持跨目录移动) 如果目标路径已存在,根据 overwrite 参数决定是否覆盖

func (*SFTPClient) PosixRename added in v0.16.1

func (c *SFTPClient) PosixRename(opt *SSHClientOption, oldname, newname string) error

PosixRename 重命名文件,如果目标存在则替换(使用 posix-rename@openssh.com 扩展)

func (c *SFTPClient) ReadLink(opt *SSHClientOption, p string) (string, error)

ReadLink 读取符号链接的目标路径

func (*SFTPClient) RealPath added in v0.16.1

func (c *SFTPClient) RealPath(opt *SSHClientOption, path string) (string, error)

RealPath 规范化路径(解析 ".."、相对路径等)

func (*SFTPClient) Remove added in v0.16.0

func (c *SFTPClient) Remove(opt *SSHClientOption, targetPath string, recursive bool) error

Remove 删除文件或目录;recursive=true 时递归删除目录

func (*SFTPClient) Rename added in v0.16.0

func (c *SFTPClient) Rename(opt *SSHClientOption, oldPath, newPath string) error

Rename 重命名/移动文件或目录

func (*SFTPClient) Stat added in v0.16.1

func (c *SFTPClient) Stat(opt *SSHClientOption, p string) (os.FileInfo, error)

Stat 获取文件/目录信息(跟随符号链接)

func (*SFTPClient) StatVFS added in v0.16.1

func (c *SFTPClient) StatVFS(opt *SSHClientOption, path string) (*sftp.StatVFS, error)

StatVFS 获取文件系统统计信息(需要服务器支持 statvfs@openssh.com 扩展)

func (c *SFTPClient) Symlink(opt *SSHClientOption, oldname, newname string) error

Symlink 创建符号链接,newname 指向 oldname

func (*SFTPClient) Truncate added in v0.16.1

func (c *SFTPClient) Truncate(opt *SSHClientOption, path string, size int64) error

Truncate 截断文件到指定大小

func (*SFTPClient) Upload added in v0.16.0

func (c *SFTPClient) Upload(opt *SSHClientOption, destPath string, src io.Reader) error

Upload 上传 src 到远程 destPath(使用 ReadFrom 优化传输)

type SSHClientOption

type SSHClientOption struct {
	Addr       string `note:"地址" json:"addr"`
	User       string `note:"用户名" json:"user"`
	Password   string `note:"密码" json:"password"`
	PrivateKey string `note:"私钥" json:"privateKey"`
}

Jump to

Keyboard shortcuts

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