sshcmd

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sshcmd allows running commands on a remote host via ssh.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	SshClient *ssh.Client
	SftClient *sftp.Client
	Username  string
	Host      string
	Port      string
	// contains filtered or unexported fields
}

Client is a wrapped around ssh.Client to run commands on a remote host via ssh using a simple and easy to use APIs.

func MakeClient

func MakeClient(username, host, port, privateKeyPath string) (*Client, error)

MakeClient returns an initialized Client.

func (*Client) Connect

func (c *Client) Connect() error

Connect connects the client to the remote host. After connection, the client is ready to run a command on the remote host.

func (*Client) ConnectSftpClient added in v0.1.0

func (c *Client) ConnectSftpClient() error

ConnectSftpClient initialize and connects the sftp.Client using the current ssh.Client. If the sftpClient is already initialized, it has no effect.

func (*Client) Exec

func (c *Client) Exec(cmd string) (string, error)

Exec runs a command on the remote host. Returns the output of the command and the error if occurred.

func (*Client) WalkDir added in v0.1.0

func (c *Client) WalkDir(srcPath, dstDir string, fn WalkDirFunc) error

WalkDir is a wrapper around filepath.WalkDir.

type WalkDirFunc added in v0.1.0

type WalkDirFunc func(srcPath, dstPath string, info fs.DirEntry, err error) error

WalkDirFunc is the type of the function called by WalkDir to visit each file or directory.

srcPath is the local source path.

dstPath is the remote destination path rooted in dstDir parameter of WalkDir method.

info and err are the same as fs.WalkDirFunc.

Jump to

Keyboard shortcuts

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