sftp

package
v0.2.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package sftp provides an SFTP client that wraps SSH connection + SFTP session.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host config.Host
	// contains filtered or unexported fields
}

Client holds an SSH connection and an SFTP session on top of it.

func Connect

func Connect(ctx context.Context, host config.Host) (*Client, error)

Connect dials SSH and opens an SFTP subsystem session.

func (*Client) Close

func (c *Client) Close() error

Close stops all monitoring and closes the transport, SFTP and auth resources. Concurrent calls wait for the same cleanup, including any in-flight probe.

func (*Client) DeleteFile

func (c *Client) DeleteFile(remotePath string) error

DeleteFile removes a file on the remote host.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done closes once the connection has terminated and its monitor and resources have been released. All observers see the same terminal Err.

func (*Client) Err

func (c *Client) Err() error

Err returns the first terminal connection error, or nil after normal Close.

func (*Client) Open

func (c *Client) Open(remotePath string) (io.ReadCloser, error)

Open opens a remote file for streaming reads.

func (*Client) ReadDir

func (c *Client) ReadDir(remotePath string) ([]*fs.FileEntry, error)

ReadDir reads one remote directory level. Directories are returned before files; both groups sorted alphabetically.

func (*Client) ReadFile

func (c *Client) ReadFile(remotePath string) ([]byte, error)

ReadFile reads the full content of a remote file.

func (*Client) Stat

func (c *Client) Stat(remotePath string) (os.FileInfo, error)

Stat returns file info for a remote path.

func (*Client) Upload

func (c *Client) Upload(remotePath string, src io.Reader) error

Upload atomically writes everything src yields to a remote path, creating parent directories as needed. The existing target is replaced only after the staged file has been written and closed successfully, and keeps its permission bits. A target that is not a regular file is refused.

func (*Client) WalkFiles

func (c *Client) WalkFiles(remoteRoot string, fn func(path string) error) error

WalkFiles calls fn for every regular file under remoteRoot, recursively. Symlinks, FIFOs, sockets and devices are skipped, matching the local walker. A listing error on any directory is propagated rather than skipped: swallowing it would silently drop that subtree from the walk, so its files would never be compared or synced.

func (*Client) WalkFilesWithActivity

func (c *Client) WalkFilesWithActivity(remoteRoot string, fn func(string) error, activity func() error) error

WalkFilesWithActivity reports every visited entry, including empty directories.

Jump to

Keyboard shortcuts

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