Documentation
¶
Index ¶
- func SetHost(host string) options.Option
- func SetInsecureIgnoreHostKey(ignore bool) options.Option
- func SetKnownHostsPath(knownHostsPath string) options.Option
- func SetPassword(password string) options.Option
- func SetPort(port int) options.Option
- func SetPrivateKeyPassphrase(passphrase string) options.Option
- func SetPrivateKeyPath(privateKeyPath string) options.Option
- func SetTimeout(timeout time.Duration) options.Option
- func SetTrustUnknownHost(trust bool) options.Option
- func SetUser(user string) options.Option
- type IRemoter
- type Remoter
- func (r *Remoter) Close() error
- func (r *Remoter) Connect() error
- func (r *Remoter) CrateRemoteDir(remoteDir string) error
- func (r *Remoter) DeleteDir(remotePath string) error
- func (r *Remoter) DeleteFile(remotePath string) error
- func (r *Remoter) DownloadFile(remotePath, localPath string) error
- func (r *Remoter) PathExists(remotePath string) (bool, error)
- func (r *Remoter) ReadFile(remotePath string) ([]byte, error)
- func (r *Remoter) RunCmd(cmd string) ([]byte, error)
- func (r *Remoter) RunCmdContext(ctx context.Context, cmd string) ([]byte, error)
- func (r *Remoter) RunCmds(cmds ...string) ([]byte, error)
- func (r *Remoter) RunCmdsContext(ctx context.Context, cmds ...string) ([]byte, error)
- func (r *Remoter) UploadDir(localDir, remoteDir string) error
- func (r *Remoter) UploadFile(localPath, remotePath string) error
- func (r *Remoter) WriteFile(remotePath string, content []byte, perm os.FileMode) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetInsecureIgnoreHostKey ¶
SetInsecureIgnoreHostKey is an option to skip host key verification. Use only for testing; it disables MITM protection.
func SetKnownHostsPath ¶
SetKnownHostsPath is an option to set the path to the known_hosts file.
func SetPassword ¶
SetPassword is an option to set the SSH password for authentication.
func SetPrivateKeyPassphrase ¶
SetPrivateKeyPassphrase is an option to set the passphrase for the private key.
func SetPrivateKeyPath ¶
SetPrivateKeyPath is an option to set the path to the SSH private key file.
func SetTimeout ¶
SetTimeout is an option to set the SSH connection timeout.
func SetTrustUnknownHost ¶
SetTrustUnknownHost is an option to auto-trust and persist an unknown host key on first connection. Subsequent connections still verify the stored host key.
Types ¶
type IRemoter ¶
type IRemoter interface {
// Connect establishes an SSH connection; must be called before any other method.
Connect() error
// Close terminates the SSH connection.
Close() error
// RunCmd executes a command on the remote host and returns combined output (stdout + stderr).
RunCmd(cmd string) ([]byte, error)
// RunCmds executes multiple commands in a single remote shell context.
RunCmds(cmds ...string) ([]byte, error)
// RunCmdContext executes a command with context, supporting timeout and cancellation.
RunCmdContext(ctx context.Context, cmd string) ([]byte, error)
// RunCmdsContext executes multiple commands in a single remote shell context with context support.
RunCmdsContext(ctx context.Context, cmds ...string) ([]byte, error)
// UploadFile uploads a local file to the remote host via SFTP.
UploadFile(localPath, remotePath string) error
// UploadDir recursively syncs a local directory to the remote host.
UploadDir(localDir, remoteDir string) error
// DownloadFile downloads a remote file to the local machine via SFTP.
DownloadFile(remotePath, localPath string) error
// PathExists checks whether the given path (file or directory) exists on the remote host.
PathExists(remotePath string) (bool, error)
// CrateRemoteDir creates a remote directory recursively if needed.
CrateRemoteDir(remoteDir string) error
// DeleteFile deletes a file on the remote host.
DeleteFile(remotePath string) error
// DeleteDir recursively deletes a directory on the remote host.
DeleteDir(remotePath string) error
// WriteFile writes content to a remote file. Creates the file if it does not exist,
// overwrites it if it does.
WriteFile(remotePath string, content []byte, perm os.FileMode) error
// ReadFile reads the content of a remote file.
ReadFile(remotePath string) ([]byte, error)
}
IRemoter defines the remote operation interface, wrapping SSH + SFTP capabilities on top of goph (github.com/melbahja/goph).
type Remoter ¶
type Remoter struct {
Host string
Port int
User string
Password string
PrivateKeyPath string
PrivateKeyPassphrase string
KnownHostsPath string
TrustUnknownHost bool
InsecureIgnoreHostKey bool
Timeout time.Duration
// contains filtered or unexported fields
}
Remoter is the concrete implementation of IRemoter using goph. It supports SSH connections via password, private key, or ssh-agent, and provides SFTP-based file operations.
func NewRemoter ¶
NewRemoter creates a new Remoter instance with default port (22) and default timeout (20s). Use option functions to override defaults.
func (*Remoter) Close ¶
Close terminates the SSH connection and releases the SFTP client. It is safe to call multiple times.
func (*Remoter) Connect ¶
Connect establishes the SSH connection. It is safe to call multiple times; subsequent calls are no-ops if the connection is already established.
func (*Remoter) CrateRemoteDir ¶
CrateRemoteDir creates a remote directory. @param remoteDir remote directory path
func (*Remoter) DeleteDir ¶
DeleteDir recursively deletes a directory and all its contents on the remote host. Returns an error if the path is not a directory.
func (*Remoter) DeleteFile ¶
DeleteFile deletes a single file on the remote host. Returns an error if the path is a directory.
func (*Remoter) DownloadFile ¶
DownloadFile downloads a single remote file to the local machine via SFTP. Local parent directories are created automatically if they do not exist.
func (*Remoter) PathExists ¶
PathExists checks whether a file or directory exists at the given remote path.
func (*Remoter) RunCmd ¶
RunCmd executes a command on the remote host and returns the combined stdout and stderr output. It auto-connects if not already connected.
func (*Remoter) RunCmdContext ¶
RunCmdContext is like RunCmd but accepts a context for timeout and cancellation.
func (*Remoter) RunCmds ¶
RunCmds executes multiple commands on the remote host in a single shell context. It auto-connects if not already connected.
func (*Remoter) RunCmdsContext ¶
RunCmdsContext is like RunCmds but accepts a context for timeout and cancellation.
func (*Remoter) UploadDir ¶
UploadDir recursively syncs an entire local directory to the remote host via SFTP. It creates the remote directory tree and uploads all files with their original permissions.
func (*Remoter) UploadFile ¶
UploadFile uploads a single local file to the remote host via SFTP. For directory sync, use UploadDir instead.