file

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDirIfNotExists

func CreateDirIfNotExists(dir string)

func DirIsEmpty

func DirIsEmpty(dirPath string) bool

func DownloadFile

func DownloadFile(client *sftp.Client, remoteFilePath, localFilePath string) error

DownloadFile 下载远程文件到本地

func ExtractDir

func ExtractDir(embedFiles embed.FS, source string, destination string) error

ExtractDir extracts a directory from the embedded filesystem.

func NormalizedPath

func NormalizedPath(path string) string

NormalizedPath 归一化处理路径,去除路径中错误的 \\ //

func NormalizedRemotePath

func NormalizedRemotePath(remotePath string) string

NormalizedRemotePath 归一化远程路径处理

func ReadFileSafely

func ReadFileSafely(path string, maxSize int64) (string, error)

ReadFileSafely 安全文本文件读取方法

func ReadRemoteFileSafely

func ReadRemoteFileSafely(client *sftp.Client, filePath string, maxSize int64) (string, error)

ReadRemoteFileSafely 安全读取远程文本文件

func RemoteRemoveAll

func RemoteRemoveAll(sftpClient *sftp.Client, path string) error

RemoteRemoveAll 递归删除远程目录及其中的所有内容

func SaveFile

func SaveFile(client *sftp.Client, filePath, content string) error

func UploadFile

func UploadFile(client *sftp.Client, localFilePath, remoteFilePath string)

UploadFile 上传文件

Types

type FileTransfer

type FileTransfer struct {
	Path     string  `json:"path"`     // 文件名
	Size     int64   `json:"size"`     // 文件大小
	Progress float64 `json:"progress"` // 进度
	Status   string  `json:"status"`
	Error    string  `json:"error"`
}

type Node

type Node struct {
	Name       string    `json:"name"`
	Path       string    `json:"path"`
	ParentPath string    `json:"parentPath"`
	IsDir      bool      `json:"isDir"`
	Children   []*Node   `json:"children,omitempty"`
	Size       int64     `json:"size"`
	SizeInfo   string    `json:"sizeInfo"`
	ModTime    time.Time `json:"modTime"`
	IsSymlink  bool      `json:"isSymlink"`
}

func GetFolderChild

func GetFolderChild(client *sftp.Client, fullPath string) (*Node, error)

GetFolderChild 读取远程目录结构

func ReadDirTree

func ReadDirTree(rootPath string, maxLevel int) (*Node, error)

ReadDirTree 读取目录结构 rootPath: 根路径 maxLevel: 最大遍历层级(0表示不限制)

func (*Node) HumanSize

func (ft *Node) HumanSize() string

type TransferInfo

type TransferInfo struct {
	LocalPath  string `json:"localPath"`
	RemotePath string `json:"remotePath"`
}

func GetFiles

func GetFiles(client *sftp.Client, localPath, remotePath string) ([]TransferInfo, error)

递归获取所有文件

func RecursiveGetFolderFiles

func RecursiveGetFolderFiles(client *sftp.Client, remotePath, localPath string) ([]TransferInfo, error)

RecursiveGetFolderFiles 递归获取文件夹中的所有文件

Source Files

  • file.go
  • file_embed.go
  • sftp_file.go
  • types.go

Jump to

Keyboard shortcuts

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