Documentation
¶
Index ¶
- Variables
- type BatchError
- type Client
- func (c *Client) Close() error
- func (c *Client) Delete(ctx context.Context, remotePath string) error
- func (c *Client) DeleteBatch(ctx context.Context, remotePaths []string) error
- func (c *Client) Download(ctx context.Context, remotePath string) error
- func (c *Client) DownloadBatch(ctx context.Context, remotePaths []string, options ...Option) (*Result, error)
- func (c *Client) Exists(ctx context.Context, remotePath string) bool
- func (c *Client) Host() string
- func (c *Client) List(ctx context.Context, remotePath string) ([]string, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Size(ctx context.Context, remotePath string) (int64, error)
- func (c *Client) Upload(ctx context.Context, localPath, remotePath string) error
- func (c *Client) UploadBatch(ctx context.Context, localPaths []string, options ...Option) (*Result, error)
- type Mode
- type Option
- func WithCompress(compress bool) Option
- func WithControlMaster(enable bool) Option
- func WithControlPersist(duration time.Duration) Option
- func WithKeyFile(path string) Option
- func WithLocalBase(path string) Option
- func WithMode(mode Mode) Option
- func WithPort(port int) Option
- func WithProgress(fn func(Progress)) Option
- func WithRemoteBase(path string) Option
- func WithRetryAttempts(attempts int) Option
- func WithRetryDelay(delay time.Duration) Option
- func WithStrictHostKey(strict bool) Option
- func WithTimeout(timeout time.Duration) Option
- type Options
- type Progress
- type Result
- type RetryError
- type TransferError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConnectionFailed is returned when SSH connection fails. ErrConnectionFailed = errors.New("ssh connection failed") // ErrAuthFailed is returned when authentication fails. ErrAuthFailed = errors.New("ssh authentication failed") // ErrFileNotFound is returned when a remote file doesn't exist. ErrFileNotFound = errors.New("file not found") // ErrPermissionDenied is returned when permission is denied. ErrPermissionDenied = errors.New("permission denied") // ErrTimeout is returned when an operation times out. ErrTimeout = errors.New("operation timed out") // ErrNoFiles is returned when no files are provided for batch operation. ErrNoFiles = errors.New("no files provided") // ErrRsyncNotFound is returned when rsync is not installed. ErrRsyncNotFound = errors.New("rsync not found on system") // ErrTarNotFound is returned when tar is not installed. ErrTarNotFound = errors.New("tar not found on system") )
Common errors returned by the package.
Functions ¶
This section is empty.
Types ¶
type BatchError ¶
type BatchError struct {
// Errors is a map of file paths to their errors.
Errors map[string]error
}
BatchError contains errors from a batch operation.
func (*BatchError) HasErrors ¶
func (e *BatchError) HasErrors() bool
HasErrors returns true if there are any errors.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an SSH file transfer client.
func New ¶
New creates a new SSH transfer client.
The host should be in the format "user@hostname" or just "hostname".
func (*Client) Close ¶
Close closes the SSH connection. If ControlMaster is enabled, this terminates the master connection.
func (*Client) DeleteBatch ¶
DeleteBatch deletes multiple files on the remote server.
func (*Client) DownloadBatch ¶
func (c *Client) DownloadBatch(ctx context.Context, remotePaths []string, options ...Option) (*Result, error)
DownloadBatch downloads multiple files through a single SSH connection. This is more efficient than calling Download multiple times.
func (*Client) Ping ¶
Ping checks if the remote host is reachable. It attempts to connect and will retry according to the retry settings.
type Option ¶
type Option func(*Options)
Option is a function that modifies Options.
func WithCompress ¶
WithCompress enables or disables compression.
func WithControlMaster ¶
WithControlMaster enables or disables SSH connection reuse.
func WithControlPersist ¶
WithControlPersist sets how long to keep the master connection alive.
func WithKeyFile ¶
WithKeyFile sets the path to the SSH private key.
func WithProgress ¶
WithProgress sets the progress callback function.
func WithRemoteBase ¶
WithRemoteBase sets the base path on the remote server.
func WithRetryAttempts ¶
WithRetryAttempts sets the number of retry attempts.
func WithRetryDelay ¶
WithRetryDelay sets the delay between retry attempts.
func WithStrictHostKey ¶
WithStrictHostKey enables or disables strict host key checking.
func WithTimeout ¶
WithTimeout sets the connection timeout.
type Options ¶
type Options struct {
// RemoteBase is the base path on the remote server.
// All remote paths will be relative to this.
RemoteBase string
// LocalBase is the base path on the local system.
// All local paths will be relative to this.
LocalBase string
// KeyFile is the path to the SSH private key.
// Supports ~ for home directory.
KeyFile string
// Port is the SSH port.
Port int
// Mode is the transfer mode (rsync or tar).
Mode Mode
// Compress enables data compression during transfer.
Compress bool
// Timeout is the SSH connection timeout.
Timeout time.Duration
// RetryAttempts is the number of retry attempts on failure.
RetryAttempts int
// RetryDelay is the delay between retry attempts.
RetryDelay time.Duration
// ControlMaster enables SSH connection reuse.
ControlMaster bool
// ControlPersist is how long to keep the master connection alive.
ControlPersist time.Duration
// StrictHostKey enables strict host key checking.
StrictHostKey bool
// ProgressFn is called with progress updates during transfers.
ProgressFn func(Progress)
}
Options holds the client configuration.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns the default configuration.
type Progress ¶
type Progress struct {
// FilesTotal is the total number of files to transfer.
FilesTotal int
// FilesDone is the number of files completed.
FilesDone int
// BytesTotal is the total number of bytes to transfer (if known).
BytesTotal int64
// BytesDone is the number of bytes transferred.
BytesDone int64
// CurrentFile is the name of the file currently being transferred.
CurrentFile string
// StartTime is when the transfer started.
StartTime time.Time
// LastUpdate is when progress was last updated.
LastUpdate time.Time
}
Progress holds information about transfer progress.
func (Progress) BytesHuman ¶
BytesHuman returns the bytes transferred in human-readable format.
func (Progress) SpeedHuman ¶
SpeedHuman returns the transfer speed in human-readable format.
func (Progress) TotalHuman ¶
TotalHuman returns the total bytes in human-readable format.
type Result ¶
type Result struct {
// Success is the number of successfully transferred files.
Success int
// Failed is the number of failed transfers.
Failed int
// Bytes is the total bytes transferred.
Bytes int64
// Duration is how long the transfer took.
Duration time.Duration
// Errors contains any errors that occurred.
Errors []error
}
Result holds the result of a transfer operation.
type RetryError ¶
type RetryError struct {
// Attempts is the number of attempts made.
Attempts int
// LastErr is the last error encountered.
LastErr error
}
RetryError is returned when all retry attempts fail.
func (*RetryError) Unwrap ¶
func (e *RetryError) Unwrap() error
Unwrap returns the underlying error.
type TransferError ¶
type TransferError struct {
// Op is the operation that failed (download, upload, delete).
Op string
// Path is the file path that caused the error.
Path string
// Host is the remote host.
Host string
// Err is the underlying error.
Err error
}
TransferError represents an error during file transfer.
func (*TransferError) Error ¶
func (e *TransferError) Error() string
Error returns the error message.
func (*TransferError) Unwrap ¶
func (e *TransferError) Unwrap() error
Unwrap returns the underlying error.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Example: Basic file download and upload operations
|
Example: Basic file download and upload operations |
|
batch
command
Example: Batch file transfer operations
|
Example: Batch file transfer operations |
|
progress
command
Example: Download with progress tracking
|
Example: Download with progress tracking |