ssh

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Command string
}

func (*Command) RunCommandOverSSH

func (command *Command) RunCommandOverSSH(credentials SSHCredentials) (string, error)

RunCommandOverSSH Run command over SSH

type SFTP

type SFTP struct {
	// Path to a directory on the remote machine
	RemoteDir string
	// Empty, existing local directory where the RemoteDir will be copy
	EmptyLocalDir  string
	SSHCredentials *SSHCredentials
	LogWriter      io.Writer
}

func (*SFTP) DownloadDirectory

func (sftpd *SFTP) DownloadDirectory() error

DownloadDirectory Download directory from RemoteDir to EmptyLocalDir. EmptyLocalDir must be empty! Function returns error in case of problem or nil if succeeded.

type SSHCredentials

type SSHCredentials struct {
	IPAddress string
	Port      uint16
	Username  string
	Password  string
}

SSHCredentials is used as endpoint credentials of the remote server

func (*SSHCredentials) CheckPrerequisites

func (cred *SSHCredentials) CheckPrerequisites(*prerequisites.Args) error

func (*SSHCredentials) FillDefault

func (cred *SSHCredentials) FillDefault(*prerequisites.Args) error

func (*SSHCredentials) FillDynamic

func (cred *SSHCredentials) FillDynamic(*prerequisites.Args) error

type SSHSession

type SSHSession struct {
	StdIn  io.Reader
	StdOut io.Writer
	StdErr io.Writer
	// contains filtered or unexported fields
}

SSHSession represents standard SSH Session needed for each SSH "Connection"

func (*SSHSession) GetSSHSession

func (session *SSHSession) GetSSHSession() *ssh.Session

func (*SSHSession) IsLoggedIn

func (session *SSHSession) IsLoggedIn() bool

IsLoggedIn Check if the session is logged in

func (*SSHSession) Login

func (session *SSHSession) Login(credentials SSHCredentials) error

Login tries to login to the remote server. It creates an SSH Session if succeed the nil is returned. If not succeed the valid error is returned

func (*SSHSession) LoginMultipleAttempts

func (session *SSHSession) LoginMultipleAttempts(credentials SSHCredentials) error

LoginMultipleAttempts calls Login a maximum of N times. It calls Login, if the Login fails it waits M seconds and then try it again. If the Login failed N times then error is returned.

func (*SSHSession) Logout

func (session *SSHSession) Logout()

Logout from session if the session is active.

func (*SSHSession) Run

func (session *SSHSession) Run(command string) error

Run It runs a given command on the remote machine.

func (*SSHSession) SetEnvironment

func (session *SSHSession) SetEnvironment(envMap map[string]string) error

SetEnvironment sets the Environment variables for the given session.

func (*SSHSession) Start

func (session *SSHSession) Start(command string) error

Start It starts a given command on the remote machine. User must call 'Wait' function to wait until command returns.

func (*SSHSession) Wait

func (session *SSHSession) Wait() error

Wait Wait until command started by 'Start' function ends

type ShellEvaluator

type ShellEvaluator struct {
	// Commands to execute, each command must exit with 0 return code else error is returned.
	Commands []string
	// Preparing commands are executed before main commands. Their exit values are not captured and checked.
	PreparingCommands []string
	// Environments variables to set
	Env map[string]string
	// StdOut writer to capture stdout of the process
	StdOut io.Writer
}

ShellEvaluator run commands by the bash thru the SSH.

func (*ShellEvaluator) RunOverSSH

func (shell *ShellEvaluator) RunOverSSH(credentials SSHCredentials) error

RunOverSSH Runs command over SSH.

All commands specified in Commands are run be Bash by a one Bash session

All environment variables are preserved across command run and can be used by other subsequent commands.

type Tar

type Tar struct {
	// ArchiveName name of the archive which will be created
	ArchiveName string
	// SourceDir source directory where are files which will be added to archive (without root folder)
	SourceDir string
}

Tar Struct for creating tar archive using a tar tool

func (*Tar) CheckPrerequisites

func (tar *Tar) CheckPrerequisites(*prerequisites.Args) error

func (*Tar) ConstructCMDLine

func (tar *Tar) ConstructCMDLine() []string

ConstructCMDLine Constructs command for tar tool.

func (*Tar) FillDefault

func (tar *Tar) FillDefault(*prerequisites.Args) error

func (*Tar) FillDynamic

func (tar *Tar) FillDynamic(args *prerequisites.Args) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL