ssh

package
v0.0.0-...-81011cd Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const TCPTimeout = time.Second * 30

Variables

View Source
var Cmd = &cli.Command{
	Name:      "ssh",
	Usage:     "ssh client",
	UsageText: "destination [--key FILE]",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:      "key",
			Usage:     "path to private key `FILE`",
			TakesFile: true,
		},
	},
	Action: func(ctx *cli.Context) error {
		dst := ctx.Args().First()
		if dst == "" {
			return fmt.Errorf("missing destination")
		}

		privF := ctx.String("key")
		method, err := Auth(privF)
		if err != nil {
			return err
		}

		c, err := NewClient(dst, method)
		if err != nil {
			return err
		}

		s, err := c.NewSession()
		if err != nil {
			return err
		}

		err = s.SetPipes()
		if err != nil {
			return err
		}

		go s.HandleSignals()

		if ctx.NArg() == 1 {
			err := s.Shell()
			if err != nil {
				fmt.Println(err.Error())
			}
			s.WaitAndClose()
			return nil
		}

		cmd := strings.Join(ctx.Args().Tail(), " ")
		err = s.Run(cmd)
		if err != nil {
			fmt.Println(err.Error())
		}
		s.CloseAndWaith()
		return nil
	},
}
View Source
var ErrInvalidDest = errors.New("invalid destination")

Functions

func Auth

func Auth(privF string) ([]ssh.AuthMethod, error)

Types

type Client

type Client struct {
	*ssh.Client
}

func NewClient

func NewClient(dst string, auth []ssh.AuthMethod) (*Client, error)

func (*Client) NewSession

func (c *Client) NewSession() (*Session, error)

type Session

type Session struct {
	*ssh.Session
	// contains filtered or unexported fields
}

func (*Session) Close

func (s *Session) Close()

func (*Session) CloseAndWaith

func (s *Session) CloseAndWaith()

func (*Session) HandleSignals

func (s *Session) HandleSignals()

func (*Session) SetPipes

func (s *Session) SetPipes() error

func (*Session) Wait

func (s *Session) Wait()

func (*Session) WaitAndClose

func (s *Session) WaitAndClose()

Jump to

Keyboard shortcuts

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