Documentation
¶
Overview ¶
Package remote defines the protocol-agnostic interface for remote file operations and provides a factory that returns the right implementation (SFTP or FTP) based on host.Protocol.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseOnContextDone ¶
CloseOnContextDone closes client if ctx ends before detach is called. detach waits for a close already in progress, so returning from an operation cannot race a late cancellation that closes a connection handed back to its owner.
Types ¶
type Client ¶
type Client interface {
Stat(path string) (os.FileInfo, error)
ReadDir(path string) ([]*fs.FileEntry, error)
Open(path string) (io.ReadCloser, error)
ReadFile(path string) ([]byte, error)
Upload(remotePath string, src io.Reader) error
WalkFiles(root string, fn func(string) error) error
// WalkFilesWithActivity also reports visited directories, including empty ones.
// activity must be concurrency-safe and may return an error to stop the walk.
WalkFilesWithActivity(root string, fn func(string) error, activity func() error) error
DeleteFile(path string) error
// Done closes when the connection is closed or its keep-alive monitor fails.
Done() <-chan struct{}
// Err returns the terminal monitor error; normal Close leaves it nil.
Err() error
Close() error
}
Client abstracts all remote file operations needed by drift. Both *sftp.Client and *ftp.Client satisfy this interface.
No method takes a local path: the local side of a transfer belongs to fs.Root, which confines it to the project. A download is Open plus fs.Root.WriteAtomic, an upload is fs.Root.Open plus Upload.
func Connect ¶
func Connect(ctx context.Context, host config.Host, trust *tlstrust.Manager, required *tlstrust.Challenge) (Client, error)
Connect dials the host using the protocol specified in host.Protocol. An empty or "sftp" protocol uses SSH/SFTP; "ftp" uses plain FTP; "ftps" uses FTP over explicit TLS.