Repository: github.com/janmz/sshcommands
Go library for SSH/SFTP operations with a parameter-based API: upload (sync), list, delete, download, and fetch server host key. No config struct dependency; all options are passed as parameters. Optional AES-256-CTR encryption for upload/download.
Donationware for CFI Kinderhilfe. License: MIT with attribution.
go get github.com/janmz/sshcommandsBuild Opts with SSH connection parameters:
opts := &sshcommands.Opts{
Host: "example.com",
Port: 22,
User: "deploy",
KeyFile: "/home/user/.ssh/id_ed25519", // or Password: "secret"
HostKey: "ed25519 AAAAC3...", // or path to known_hosts file
}Use at least KeyFile or Password for authentication. HostKey is required
for verified connections (path to a file or inline key line; multiple keys
separated by ||).
Upload local files that are missing or newer on the remote; remove remote files that are not in the local list. Optional AES password for encryption.
localFiles := []sshcommands.LocalFile{
{Name: "file.zip", Path: "/local/file.zip", ModTime: t, Size: 1024},
}
err := sshcommands.Sync(opts, localFiles, "/remote/dir", "", log)List all non-directory entries in a remote directory.
entries, err := sshcommands.List(opts, "/remote/dir", log)
// entries: []RemoteEntry{Name, ModTime, Size}Remove given file names from the remote directory.
err := sshcommands.Delete(opts, "/remote/dir", []string{"old.zip"}, log)Download files matching a pattern (literal name or wildcards *, ?) into a
local directory. Optional AES password for decryption.
paths, err := sshcommands.Download(opts, "backup_*.zip", "/local/dir",
"/remote/dir", aesPassword, log)
// paths: []string of written local pathsConnect without host key verification and return the server's key line (e.g. for initial setup):
keyLine, err := sshcommands.FetchServerHostKey(opts)
// keyLine: "ed25519 AAAAC3..."Check if a key line is already among the configured keys (inline or file):
ok, err := sshcommands.HostKeyAlreadyPresent(currentHostKeyValue, newKeyLine)All functions accept an optional Logger interface (Info, Warn with
format strings). Pass nil to disable logging.
When aesPassword is non-empty, Sync encrypts and Download decrypts using
AES-256-CTR with PBKDF2-derived keys (salt + nonce prefix). Format is
compatible with streams written by this package.