Documentation
¶
Index ¶
- Constants
- type Client
- func (c *Client) Close() error
- func (c *Client) Config() TransferConfig
- func (c *Client) Cwd(ctx context.Context) (cwd string, retErr error)
- func (c *Client) Do(ctx context.Context, operation func(*sftp.Client) error) error
- func (c *Client) Download(ctx context.Context, remotePath, localPath string, progress ProgressCallback) error
- func (c *Client) DownloadDirectory(ctx context.Context, remoteDir, localDir string, progress ProgressCallback) error
- func (c *Client) DownloadFile(ctx context.Context, remotePath, localPath string, size int64, ...) (retErr error)
- func (c *Client) JoinPath(elem ...string) string
- func (c *Client) RemoteCopy(ctx context.Context, src, dst string) (retErr error)
- func (c *Client) RemoveAll(ctx context.Context, remotePath string) error
- func (c *Client) Rename(ctx context.Context, src, dst string) error
- func (c *Client) ReplaceRemoteFile(ctx context.Context, tempPath, remotePath string) error
- func (c *Client) SFTPClient() *sftp.Client
- func (c *Client) StreamTransfer(ctx context.Context, source *Client, r io.Reader, w io.Writer, size int64, ...) error
- func (c *Client) Upload(ctx context.Context, localPath, remotePath string, progress ProgressCallback) error
- func (c *Client) UploadDirectory(ctx context.Context, localDir, remoteDir string, progress ProgressCallback) error
- func (c *Client) UploadFile(ctx context.Context, localPath, remotePath string, size int64, ...) (retErr error)
- func (c *Client) WithForce(force bool) *Client
- type Option
- type ProgressCallback
- type TransferConfig
Constants ¶
const ( DefaultConcurrentFiles = 5 DefaultThreadsPerFile = 64 DefaultChunkSize = 32 * 1024 DefaultResumeMinSize = 1024 * 1024 DefaultTempSuffix = ".xops-tmp" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
NewClient creates an SFTP subsystem on an existing SSH connection. Setup is bounded by ctx and an internal maximum timeout, including subsystem and protocol handshakes.
func (*Client) Close ¶
Close closes this SFTP subsystem. A blocked subsystem close may close the shared SSH transport as a bounded last-resort interrupt.
func (*Client) Cwd ¶
Cwd returns the remote working directory using the caller's cancellation boundary.
func (*Client) Do ¶ added in v0.12.0
Do runs a low-level SFTP operation with context cancellation. It deliberately adds no command policy or presentation concerns; callers retain ownership of operation-specific error context. Cancellation interrupts this SFTP subsystem, so the client must not be reused afterwards.
func (*Client) Download ¶
func (c *Client) Download(ctx context.Context, remotePath, localPath string, progress ProgressCallback) error
Download 下载入口:支持文件或目录
func (*Client) DownloadDirectory ¶
func (*Client) DownloadFile ¶
func (*Client) RemoteCopy ¶ added in v0.12.0
RemoteCopy copies a remote file, directory, or symbolic link through SFTP. Symbolic links are copied as links and are never followed during traversal.
func (*Client) RemoveAll ¶ added in v0.12.0
RemoveAll removes a remote file, directory tree, or symbolic link through SFTP. Symbolic links are removed as links and are never followed.
func (*Client) ReplaceRemoteFile ¶ added in v0.12.0
ReplaceRemoteFile promotes a temporary remote file to its destination while preserving an existing destination when the replacement fails. Cancellation interrupts this SFTP subsystem, so the client must not be reused afterwards.
func (*Client) SFTPClient ¶
SFTPClient returns the underlying *sftp.Client.
func (*Client) StreamTransfer ¶
func (c *Client) StreamTransfer(ctx context.Context, source *Client, r io.Reader, w io.Writer, size int64, progress ProgressCallback) error
StreamTransfer copies exactly size bytes between two SFTP clients. The caller retains ownership of r and w. Cancellation interrupts both clients' SFTP subsystems, so both SFTP clients become unusable afterwards. Shared SSH transports remain open unless a subsystem close itself blocks and requires the bounded transport fallback documented on Client.
func (*Client) Upload ¶
func (c *Client) Upload(ctx context.Context, localPath, remotePath string, progress ProgressCallback) error
Upload 上传入口:支持文件或目录
func (*Client) UploadDirectory ¶
func (*Client) UploadFile ¶
type Option ¶
type Option func(*Client)
func WithChunkSize ¶
func WithConcurrentFiles ¶
func WithResume ¶ added in v0.6.0
func WithResumeMinSize ¶ added in v0.6.0
func WithThreadsPerFile ¶
type ProgressCallback ¶
type ProgressCallback func(n int64)
ProgressCallback 进度回调,n 为本次增量传输的字节数 此函数必须是并发安全的
type TransferConfig ¶
type TransferConfig struct {
ConcurrentFiles int // 同时传输的文件数
ThreadsPerFile int // 单个文件的并发分块数
ChunkSize int64 // 分块大小
EnableResume bool
ResumeMinSize int64
TempSuffix string
Force bool
}
TransferConfig 定义传输配置
func DefaultConfig ¶
func DefaultConfig() TransferConfig