Documentation
¶
Overview ¶
Package remote provides SSH exec + SFTP file ops against source/target hosts.
Index ¶
- Variables
- func OpenDB(d config.DB) (*sql.DB, error)
- type Client
- func (c *Client) Close() error
- func (c *Client) DirSizeBytes(path string) (uint64, error)
- func (c *Client) DiskFreeBytes(path string) (uint64, error)
- func (c *Client) Exists(path string) (bool, error)
- func (c *Client) FetchFile(remotePath, localPath string) (LocalFetchResult, error)
- func (c *Client) ReadFile(path string) ([]byte, error)
- func (c *Client) Run(cmd string) ([]byte, error)
- func (c *Client) RunStream(cmd string, w io.Writer) error
- func (c *Client) WriteFile(path string, data []byte, mode os.FileMode) error
- type LocalFetchResult
Constants ¶
This section is empty.
Variables ¶
var ErrHostUnknown = errors.New("host not in known_hosts")
ErrHostUnknown signals that the remote host is not present in the known_hosts file. It is safe for callers to run `ssh-keyscan` and append the result; the server is not presenting a key that conflicts with a previously-recorded one.
A MISMATCHED host key (i.e. a MITM or server re-key) returns a different error and is NOT wrapped by ErrHostUnknown — callers must not auto-trust in that case.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func Dial ¶
Dial opens an SSH connection with the settings from config.SSH. The caller must Close() when done.
Host key verification order:
- If HostKeyFingerprint is set, the advertised key's SHA256 fingerprint must match.
- Otherwise KnownHosts (defaulting to ~/.ssh/known_hosts) is consulted via golang.org/x/crypto/ssh/knownhosts.
There is intentionally no "trust on first use" fallback — if neither mechanism can authenticate the host, Dial returns an error.
func (*Client) DirSizeBytes ¶
DirSizeBytes returns the size of a directory tree on the remote. Relies on `du -sb PATH`.
func (*Client) DiskFreeBytes ¶
DiskFreeBytes returns free bytes on the filesystem holding path. Relies on `df -B1 --output=avail PATH | tail -1`.
func (*Client) FetchFile ¶
func (c *Client) FetchFile(remotePath, localPath string) (LocalFetchResult, error)
FetchFile downloads remotePath to localPath and returns how the transfer was satisfied. When the result is ResultSymlinked the caller MUST NOT delete the source file while localPath is still in use, or the symlink becomes dangling.
func (*Client) ReadFile ¶
ReadFile reads a remote file fully into memory. Use only for small files (app.ini, etc.); use OpenRemote for large files.
type LocalFetchResult ¶ added in v0.2.10
type LocalFetchResult int
LocalFetchResult describes how FetchFile satisfied a same-host transfer. Callers use ResultSymlinked / ResultHardLinked to decide whether deleting the source file is safe — hard links keep the inode alive; symlinks break.
const ( ResultCopied LocalFetchResult = iota // bytes were actually moved ResultHardLinked // new directory entry, same inode ResultSymlinked // new symlink; source must NOT be deleted ResultRemote // SFTP was used (truly remote source) )