sshclient

package module
v0.0.0-...-06ff90f Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2018 License: Apache-2.0 Imports: 11 Imported by: 8

Documentation

Index

Constants

View Source
const (
	LIST         = "ls -l %v"
	LIST_PARAM   = "ls -l %v | awk '{ print $1,\"||\",$2,\"||\",$3,\"||\",$4,\"||\",$5,\"||\",$6,\"||\",$7,\"||\",$8,\"||\",$9,$10,$11}'"
	SEARCH       = "find %v -name *%v* -ls | awk '{print $3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13}'"
	SEARCH_PARAM = "" /* 132-byte string literal not displayed */
	// SEARCH       = "find %v -name *%v* | xargs -r -l ls -l"
	// SEARCH_PARAM = "find %v -name *%v* | xargs -r -l ls -l | awk '{ print $1,\"||\",$2,\"||\",$3,\"||\",$4,\"||\",$5,\"||\",$6,\"||\",$7,\"||\",$8,\"||\",$9,$10,$11}'"
	// SEARCH           = "ls -l -R %s | grep %s"
	// SEARCH_PARAM     = "ls -l -R %s | grep %s | awk '{ print $1,\"||\",$2,\"||\",$3,\"||\",$4,\"||\",$5,\"||\",$6,\"||\",$7,\"||\",$8,\"||\",$9,$10,$11}'"
	MKDIR            = "mkdir -m %v '%v'"
	REMOVE           = "rm -f %v"
	REMOVE_RECURSIVE = "rm -R -f %v"
	RENAME           = "mv '%v' '%v'"
	MKFILE           = "echo \"%v\" > '%v'"
	CHMOD            = "chmod %v %v"
	CHOWN            = "chwon %v:%v %v"
	CHOWN_RECURSIVE  = "chwon -R %v:%v %v"
	CAT              = "cat %v"
)

Variables

This section is empty.

Functions

func Cat

func Cat(s SshSetting, path string) (string, error)

func Chmod

func Chmod(s SshSetting, path string, permission string, format bool) (e error)

func Chown

func Chown(s SshSetting, path string, user string, group string, recursive bool) error

func List

func List(s SshSetting, path string, isParseble bool) (string, error)

func MakeDir

func MakeDir(s SshSetting, path string, permission string) error

func MakeFile

func MakeFile(s SshSetting, content string, path string, permission string, format bool) error

func PublicKeyFile

func PublicKeyFile(file string) ssh.AuthMethod

Parsing private key certicate using for connection over ssh

func Remove

func Remove(s SshSetting, recursive bool, paths ...string) map[string]error

func Rename

func Rename(s SshSetting, oldPath string, newPath string) error
func Search(s SshSetting, path string, isParseble bool, search string) (string, error)

func TermInOut

func TermInOut(w io.Writer, r io.Reader) (chan<- string, <-chan string)

Handle input and output into terminal using channel

Types

type RunCommandResult

type RunCommandResult struct {
	CMD    string
	Output string
}

type SSHAuthTypeEnum

type SSHAuthTypeEnum int
const (
	//Type authentication login in ssh, it can using password or using public-private key
	SSHAuthType_Password SSHAuthTypeEnum = iota
	SSHAuthType_Certificate
)

type SshSetting

type SshSetting struct {
	//Setting information for ssh connection
	SSHHost        string
	SSHUser        string
	SSHPassword    string
	SSHKeyLocation string
	SSHAuthType    SSHAuthTypeEnum
	SSHDebug       bool
}

func (*SshSetting) Connect

func (S *SshSetting) Connect() (*ssh.Client, error)

Build connection ssh client to ssh server

func (*SshSetting) GetOutputCommandSsh

func (s *SshSetting) GetOutputCommandSsh(cmd string) (string, error)

Run single command, get the output

func (*SshSetting) NewSession

func (s *SshSetting) NewSession() (*ssh.Client, *ssh.Session, error)

Create new session

func (*SshSetting) RunCommandSsh

func (S *SshSetting) RunCommandSsh(cmds ...string) (string, error)

Build connection and run ssh script, catch the output or give error message if any

func (*SshSetting) RunCommandSshAsMap

func (s *SshSetting) RunCommandSshAsMap(cmds ...string) ([]RunCommandResult, error)

Build connection and run ssh script, catch the output or give error message if any

func (*SshSetting) SshCopyByFile

func (S *SshSetting) SshCopyByFile(content io.Reader, size int64, perm os.FileMode, filename string, destination string) error

func (*SshSetting) SshCopyByPath

func (S *SshSetting) SshCopyByPath(filePath, destinationPath string) error

Copy file adopted from https://github.com/tmc/scp/blob/master/scp.go

func (*SshSetting) SshGetFile

func (S *SshSetting) SshGetFile(path string) (res bytes.Buffer, e error)

Jump to

Keyboard shortcuts

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