GithubHelp home page GithubHelp logo

sshclient's Introduction

sshclient

Simple ssh client, wrapped around x/crypto/ssh.

Allows simple execute commands and wait for prompt or catch something, given as regexp.

Sample usage:

  c := sshclient.New(2, "login", "password", `(?msi:(~ \$|#)\s+$)`)
  err := c.Open("10.10.10.40", 22)
	if err != nil {
		panic(err)
	}
	defer c.Close()

	c.GlobalTimeout(5)
  
  // wait for first prompt
  out, err := c.ReadUntil(`(?msi:(~ \$|#)\s+$)`)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s\n", out)
  
  // get ls -l
  err = c.Write("ls -l /")
	if err != nil {
		panic(err)
	}
  
  // wait for prompt again. Output between command and prompt is the 'ls -l' output.
  out, err = c.ReadUntil(`(?msi:(~ \$|#)\s+$)`)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s:\n%s\n", "ls -l", out)
  
  
  // Ooor, you may just call 'Cmd()' - it will write command, catch default prompt (passed to New()), and 
  // return output and error, if any
  out, err = c.Cmd("date")
	if err != nil {
		panic(err)
	}
	fmt.Printf("%s:\n%s\n", "date", out)

sshclient's People

Contributors

ircop avatar mihonarium avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.