Documentation
¶
Overview ¶
Package sshcommands provides SSH/SFTP operations (upload, list, delete, download, fetch host key) with parameter-based API, no config dependency.
Index ¶
- Constants
- Variables
- func Delete(opts *Opts, remoteDir string, names []string, log Logger) error
- func Download(opts *Opts, pattern, destDir, remoteDir, aesPassword string, log Logger) ([]string, error)
- func FetchServerHostKey(opts *Opts) (keyLine string, err error)
- func HostKeyAlreadyPresent(currentValue, newKeyLine string) (bool, error)
- func NewSFTPClient(opts *Opts, log Logger) (*sftp.Client, *ssh.Client, error)
- func Sync(opts *Opts, localFiles []LocalFile, remoteDir, aesPassword string, log Logger) error
- func ValidDownloadPattern(pattern string) bool
- func ValidRemoteFileName(name string) bool
- type LocalFile
- type Logger
- type Opts
- type RemoteEntry
Constants ¶
const DefaultSSHTimeout = 30 * time.Second
DefaultSSHTimeout is used when Opts.Timeout is zero.
const EncryptionOverhead = saltLen + nonceLen
EncryptionOverhead is the number of bytes added to an encrypted stream (salt + nonce).
Variables ¶
var ( Version = "1.0.1.7" // Major, Minor, Patch, Build BuildTime = "2026-02-27 13:45:04" )
Functions ¶
func Download ¶
func Download(opts *Opts, pattern, destDir, remoteDir, aesPassword string, log Logger) ([]string, error)
Download downloads files matching pattern from remoteDir into destDir. Pattern may be a literal filename or contain wildcards (*, ?). No path components. aesPassword empty = no decryption. Returns the list of local paths written.
func FetchServerHostKey ¶
FetchServerHostKey connects to the SSH server without host key verification, captures the server's host key, and returns it as a single line (key-type base64…). The client is closed immediately. Use for initial setup (e.g. -setup-ssh).
func HostKeyAlreadyPresent ¶
HostKeyAlreadyPresent returns true if newKeyLine is already among the keys in currentValue (inline " || "-separated keys or path to a file with one key per line).
func NewSFTPClient ¶
NewSFTPClient returns an SFTP client; caller must call Close().
func Sync ¶
Sync uploads local files that are missing or newer on the remote, and deletes remote files that are not in localFiles. remoteDir is created if needed. aesPassword empty = no encryption.
func ValidDownloadPattern ¶
ValidDownloadPattern returns false if pattern contains path components (no /, \, ..).
func ValidRemoteFileName ¶
ValidRemoteFileName returns false if name contains path components or "..". Use for any remote or local filename that is joined to a base directory.
Types ¶
type Opts ¶
type Opts struct {
Host string // SSH host
Port int // 0 => 22
User string // SSH user
KeyFile string // path to private key (optional)
Password string // plaintext password (optional); at least KeyFile or Password required
HostKey string // path to known_hosts file or inline key(s), separated by " || "
Timeout time.Duration // SSH connect timeout; 0 => DefaultSSHTimeout (30s)
}
Opts holds SSH/SFTP connection parameters.
type RemoteEntry ¶
RemoteEntry describes a remote file (name, modtime, size).