simplessh

package module
v0.0.0-...-42af1bb Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2016 License: MIT Imports: 12 Imported by: 0

README

simplessh

SimpleSSH is a simple wrapper around go ssh and sftp libraries.

License

SimpleSSH is licensed under the MIT license.

Installation

go get github.com/sfreiberg/simplessh

Documentation

GoDoc

Example

package main

import (
	"github.com/sfreiberg/simplessh"

	"fmt"
)

func main() {
	/*
		Leave privKeyPath empty to use $HOME/.ssh/id_rsa.
		If username is blank simplessh will attempt to use the current user.
	*/
	client, err := simplessh.ConnectWithKeyFile("localhost:22", "root", "/home/user/.ssh/id_rsa")
	if err != nil {
		panic(err)
	}
	defer client.Close()

	output, err := client.Exec("uptime")
	if err != nil {
		panic(err)
	}

	fmt.Printf("Uptime: %s\n", output)
}

Documentation

Overview

A simple abstraction around ssh and sftp libraries in go that extends sfreiberg's simplessh package to include ssh-agent support and separate output steams for command execution.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	SSHClient *ssh.Client
}

func ConnectWithKey

func ConnectWithKey(host, username, privKey string) (*Client, error)

Connect with a private key. If username is empty simplessh will attempt to get the current user.

func ConnectWithKeyFile

func ConnectWithKeyFile(host, username, privKeyPath string) (*Client, error)

Same as ConnectWithKeyFile but allows a custom timeout. If username is empty simplessh will attempt to get the current user.

func ConnectWithKeyFileTimeout

func ConnectWithKeyFileTimeout(host, username, privKeyPath string, timeout time.Duration) (*Client, error)

Connect with a private key. If privKeyPath is an empty string it will attempt to use $HOME/.ssh/id_rsa. If username is empty simplessh will attempt to get the current user.

func ConnectWithKeyTimeout

func ConnectWithKeyTimeout(host, username, privKey string, timeout time.Duration) (*Client, error)

Connect with a private key with a custom timeout. If username is empty simplessh will attempt to get the current user.

func ConnectWithPassword

func ConnectWithPassword(host, username, pass string) (*Client, error)

Connect with a password. If username is empty simplessh will attempt to get the current user.

func ConnectWithPasswordTimeout

func ConnectWithPasswordTimeout(host, username, pass string, timeout time.Duration) (*Client, error)

Same as ConnectWithPassword but allows a custom timeout. If username is empty simplessh will attempt to get the current user.

func ConnectWithSshAgent

func ConnectWithSshAgent(host, username string) (*Client, error)

Connect with a ssh agent. If username is empty simplessh will attempt to get the current user.

func ConnectWithSshAgentTimeout

func ConnectWithSshAgentTimeout(host, username string, timeout time.Duration) (*Client, error)

Connect with a ssh agent with a custom timeout. If username is empty simplessh will attempt to get the current user.

func (*Client) Close

func (c *Client) Close() error

Close the underlying SSH connection

func (*Client) Download

func (c *Client) Download(remote, local string) error

func (*Client) Exec

func (c *Client) Exec(cmd string) ([]byte, error)

Execute cmd on the remote host and return stderr and stdout combined

func (*Client) ExecWithOutputStreams

func (c *Client) ExecWithOutputStreams(cmd string) ([]byte, []byte, error)

Execute cmd on the remote host and return stderr and stdout as separte streams

func (*Client) ReadAll

func (c *Client) ReadAll(filepath string) ([]byte, error)

Read a remote file and return the contents.

func (*Client) SFTPClient

func (c *Client) SFTPClient() (*sftp.Client, error)

Return an sftp client. The client needs to be closed when it's no longer needed.

func (*Client) Upload

func (c *Client) Upload(local, remote string) error

Jump to

Keyboard shortcuts

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