Documentation
¶
Index ¶
- func Connect(ws *websocket.Conn, opt *SSHClientOption) error
- func NewSSHClient(option *SSHClientOption) (*ssh.Client, error)
- func NewSSHClientWithPassword(option *SSHClientOption) (*ssh.Client, error)
- func NewSSHClientWithPrivateKey(option *SSHClientOption) (*ssh.Client, error)
- type AuthModel
- type FileInfo
- type ListResult
- type SFTPClient
- func (c *SFTPClient) Chmod(opt *SSHClientOption, path string, mode os.FileMode) error
- func (c *SFTPClient) Chown(opt *SSHClientOption, path string, uid, gid int) error
- func (c *SFTPClient) Chtimes(opt *SSHClientOption, path string, atime, mtime time.Time) error
- func (c *SFTPClient) Close()
- func (c *SFTPClient) DirSize(opt *SSHClientOption, dirPath string) (int64, error)
- func (c *SFTPClient) Download(opt *SSHClientOption, filePath string, dst io.Writer) error
- func (c *SFTPClient) Glob(opt *SSHClientOption, pattern string) ([]string, error)
- func (c *SFTPClient) IsTextFile(opt *SSHClientOption, filePath string) (bool, error)
- func (c *SFTPClient) Link(opt *SSHClientOption, oldname, newname string) error
- func (c *SFTPClient) List(opt *SSHClientOption, dirPath string) (*ListResult, error)
- func (c *SFTPClient) Lstat(opt *SSHClientOption, p string) (os.FileInfo, error)
- func (c *SFTPClient) Mkdir(opt *SSHClientOption, dirPath string) error
- func (c *SFTPClient) Move(opt *SSHClientOption, srcPath, dstPath string, overwrite bool) error
- func (c *SFTPClient) PosixRename(opt *SSHClientOption, oldname, newname string) error
- func (c *SFTPClient) ReadLink(opt *SSHClientOption, p string) (string, error)
- func (c *SFTPClient) RealPath(opt *SSHClientOption, path string) (string, error)
- func (c *SFTPClient) Remove(opt *SSHClientOption, targetPath string, recursive bool) error
- func (c *SFTPClient) Rename(opt *SSHClientOption, oldPath, newPath string) error
- func (c *SFTPClient) Stat(opt *SSHClientOption, p string) (os.FileInfo, error)
- func (c *SFTPClient) StatVFS(opt *SSHClientOption, path string) (*sftp.StatVFS, error)
- func (c *SFTPClient) Symlink(opt *SSHClientOption, oldname, newname string) error
- func (c *SFTPClient) Truncate(opt *SSHClientOption, path string, size int64) error
- func (c *SFTPClient) Upload(opt *SSHClientOption, destPath string, src io.Reader) error
- type SSHClientOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
func Connect(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 FileInfo ¶
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 ¶
ListResult 目录列表结果(含实际路径)
type SFTPClient ¶
type SFTPClient struct {
// contains filtered or unexported fields
}
SFTPClient SFTP 客户端,内置连接池,按 user@addr 复用连接
func NewSFTPClient ¶
func NewSFTPClient(idleTimeout time.Duration) *SFTPClient
NewSFTPClient 创建 SFTP 客户端,idleTimeout 为 0 时使用默认值 30s
func (*SFTPClient) Chmod ¶
func (c *SFTPClient) Chmod(opt *SSHClientOption, path string, mode os.FileMode) error
Chmod 修改文件权限
func (*SFTPClient) Chown ¶
func (c *SFTPClient) Chown(opt *SSHClientOption, path string, uid, gid int) error
Chown 修改文件所有者和组
func (*SFTPClient) Chtimes ¶
func (c *SFTPClient) Chtimes(opt *SSHClientOption, path string, atime, mtime time.Time) error
Chtimes 修改文件访问时间和修改时间
func (*SFTPClient) DirSize ¶
func (c *SFTPClient) DirSize(opt *SSHClientOption, dirPath string) (int64, error)
DirSize 递归计算目录大小(包含所有子目录和文件)
func (*SFTPClient) Download ¶
func (c *SFTPClient) Download(opt *SSHClientOption, filePath string, dst io.Writer) error
Download 下载远程文件到 dst(使用 WriteTo 优化传输)
func (*SFTPClient) Glob ¶
func (c *SFTPClient) Glob(opt *SSHClientOption, pattern string) ([]string, error)
Glob 根据模式匹配文件路径(如 *.txt, /path/*.log) 返回匹配的文件路径列表
func (*SFTPClient) IsTextFile ¶
func (c *SFTPClient) IsTextFile(opt *SSHClientOption, filePath string) (bool, error)
IsTextFile 判断远程文件是否为文本文件 通过读取文件的前 512 字节,检查是否包含非文本字符(如 null 字节)
func (*SFTPClient) Link ¶
func (c *SFTPClient) Link(opt *SSHClientOption, oldname, newname string) error
Link 创建硬链接,newname 指向 oldname 的同一个 inode
func (*SFTPClient) List ¶
func (c *SFTPClient) List(opt *SSHClientOption, dirPath string) (*ListResult, error)
List 列出目录内容,dirPath 为空或 "~" 时使用远程 home 目录
func (*SFTPClient) Lstat ¶
func (c *SFTPClient) Lstat(opt *SSHClientOption, p string) (os.FileInfo, error)
Lstat 获取文件信息(不跟随符号链接,返回链接本身的信息)
func (*SFTPClient) Mkdir ¶
func (c *SFTPClient) Mkdir(opt *SSHClientOption, dirPath string) error
Mkdir 递归创建目录
func (*SFTPClient) Move ¶
func (c *SFTPClient) Move(opt *SSHClientOption, srcPath, dstPath string, overwrite bool) error
Move 移动文件或目录(实际上是重命名的封装,支持跨目录移动) 如果目标路径已存在,根据 overwrite 参数决定是否覆盖
func (*SFTPClient) PosixRename ¶
func (c *SFTPClient) PosixRename(opt *SSHClientOption, oldname, newname string) error
PosixRename 重命名文件,如果目标存在则替换(使用 posix-rename@openssh.com 扩展)
func (*SFTPClient) ReadLink ¶
func (c *SFTPClient) ReadLink(opt *SSHClientOption, p string) (string, error)
ReadLink 读取符号链接的目标路径
func (*SFTPClient) RealPath ¶
func (c *SFTPClient) RealPath(opt *SSHClientOption, path string) (string, error)
RealPath 规范化路径(解析 ".."、相对路径等)
func (*SFTPClient) Remove ¶
func (c *SFTPClient) Remove(opt *SSHClientOption, targetPath string, recursive bool) error
Remove 删除文件或目录;recursive=true 时递归删除目录
func (*SFTPClient) Rename ¶
func (c *SFTPClient) Rename(opt *SSHClientOption, oldPath, newPath string) error
Rename 重命名/移动文件或目录
func (*SFTPClient) Stat ¶
func (c *SFTPClient) Stat(opt *SSHClientOption, p string) (os.FileInfo, error)
Stat 获取文件/目录信息(跟随符号链接)
func (*SFTPClient) StatVFS ¶
func (c *SFTPClient) StatVFS(opt *SSHClientOption, path string) (*sftp.StatVFS, error)
StatVFS 获取文件系统统计信息(需要服务器支持 statvfs@openssh.com 扩展)
func (*SFTPClient) Symlink ¶
func (c *SFTPClient) Symlink(opt *SSHClientOption, oldname, newname string) error
Symlink 创建符号链接,newname 指向 oldname
func (*SFTPClient) Truncate ¶
func (c *SFTPClient) Truncate(opt *SSHClientOption, path string, size int64) error
Truncate 截断文件到指定大小
func (*SFTPClient) Upload ¶
func (c *SFTPClient) Upload(opt *SSHClientOption, destPath string, src io.Reader) error
Upload 上传 src 到远程 destPath(使用 ReadFrom 优化传输)
Source Files
¶
- session.go
- sftp_client.go
- ssh_client.go