ssh_client

package module
v0.0.0-...-fe23734 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: BSD-2-Clause Imports: 2 Imported by: 0

README

ssh-client

Simple packaging for golang.org/x/crypto/ssh

Install
go get gitee.com/zhangsq-cn/ssh-client
Usage Example
package main

import (
    "gitee.com/zhangsq-cn/ssh_client"
    "fmt"
)

func main()  {
    client, err := ssh_client.NewSSHClient("IP:port", "username", "password")
    if err != nil {
        panic(err)
    }

    username, err = client.Output("whoami")
    if err != nil {
        panic(err)
    }

    fmt.Println(string(username))
}
Test
$ export TEST_HOST="ip:port"
$ export TEST_USER="username"
$ export TEST_PWD="password"
$ go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SSHClient

type SSHClient struct {
	// contains filtered or unexported fields
}

func NewSSHClient

func NewSSHClient(host, username, password string) (*SSHClient, error)

func (*SSHClient) Close

func (c *SSHClient) Close() error

Close the ssh client

func (*SSHClient) CombinedOutput

func (c *SSHClient) CombinedOutput(cmd string) ([]byte, error)

Start a command and receive all output from the command

func (*SSHClient) Output

func (c *SSHClient) Output(cmd string) ([]byte, error)

Start a command and receive standard output from the command

func (*SSHClient) Run

func (c *SSHClient) Run(cmd string) error

Start a command that does not require output

func (*SSHClient) Start

func (c *SSHClient) Start(cmd string) (*ssh.Session, error)

Start a command that will run continuously, calling Close() method of the session to end the command

Jump to

Keyboard shortcuts

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