ssh

package
v0.0.0-...-854496c Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SCP_PUSH_BEGIN_FILE       = "C"
	SCP_PUSH_BEGIN_FOLDER     = "D"
	SCP_PUSH_BEGIN_END_FOLDER = "0"
	SCP_PUSH_END_FOLDER       = "E"
	SCP_PUSH_END              = "\x00"
)
View Source
const (
	NO_EXIST   = "0"
	IS_FILE    = "1"
	IS_DIR     = "2"
	DefaultCon = 5
	Timeout    = 600
)

Variables

View Source
var (
	NO_PASSWORD = "GET PASSWORD ERROR\n"
)

Functions

func CheckResults

func CheckResults(crs chan string, ls int, wt *sync.WaitGroup, ccons chan struct{})

func CmdExec

func CmdExec(host, user, port, password, key, privilegeCmd, cmd, model string, force bool) error

func CmdExecOut

func CmdExecOut(host, user, port, password, key, privilegeCmd, cmd, model string, force bool) (string, error)

func FileExists

func FileExists(path string) bool

func GetIps

func GetIps(h []Host) []string

func GetPerm

func GetPerm(f *os.File) (perm string)

func MakePath

func MakePath(path string) error

func PathExists

func PathExists(path string) bool

func PrintExecResult

func PrintExecResult(res Result)

func PrintPullResult

func PrintPullResult(ip, src, dst string, err error)

print pull result

func PullFile

func PullFile(host, src, dst, user, port, password, key, model string, force bool)

func PushFile

func PushFile(host, src, dst, user, port, password, key, model string, force bool)

func SinglePull

func SinglePull(host, src, dst, model string, cu *CommonUser, force bool)

func SinglePush

func SinglePush(ip, src, dst, model string, cu *CommonUser, f bool)

func SingleRun

func SingleRun(host, cmd, model string, user *CommonUser, force bool) error

func SingleRunOut

func SingleRunOut(host, cmd, model string, user *CommonUser, force bool) (string, error)

Types

type CommonUser

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

func NewUser

func NewUser(user, port, psw, key string, force bool) *CommonUser

type Host

type Host struct {
	Ip           string
	Port         string
	User         string
	Psw          string
	Key          string
	PrivilegeCmd string
	Cmd          string
	SSHModel     string
}

type Result

type Result struct {
	Ip     string
	Cmd    string
	Result string
	Err    error
}

func ServersPush

func ServersPush(src, dst string, hosts []Host) []Result

push file or dir to remote servers

func ServersRun

func ServersRun(hosts []Host) []Result

func ServersRun(cmd string, cu *CommonUser, wt *sync.WaitGroup, crs chan machine.Result, ipFile string, ccons chan struct{}) {

type Scp

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

func NewScp

func NewScp(clientConn *ssh.Client) *Scp

Initializer

func (*Scp) PullFile

func (scp *Scp) PullFile(srcpath, targetFile string) error

Pull file from remote serter to local

func (*Scp) PushDir

func (scp *Scp) PushDir(src string, dest string) error

Push directory to server

func (*Scp) PushFile

func (scp *Scp) PushFile(src string, dest string) error

Push one file to server

type ScpConfig

type ScpConfig struct {
	Src string
	Dst string
}

type Server

type Server struct {
	Ip         string
	Port       string
	User       string
	Psw        string
	Key        string
	Action     string
	Cmd        string
	FileName   string
	RemotePath string
	Force      bool
	SSHModel   string
}

func NewCmdServer

func NewCmdServer(ip, port, user, psw, action, cmd, key, model string, force bool) *Server

func NewPullServer

func NewPullServer(ip, port, user, psw, key, action, file, rpath, model string, force bool) *Server

func NewScpServer

func NewScpServer(ip, port, user, psw, key, action, file, rpath, model string, force bool) *Server

func (*Server) PRunCmd

func (server *Server) PRunCmd(crs chan Result)

run command for parallel

func (*Server) PRunScp

func (server *Server) PRunScp(crs chan Result)

PRunScp() can transport file or path to remote host

func (*Server) PullScp

func (server *Server) PullScp() (err error)

pull file from remote to local server

func (*Server) RunCmd

func (server *Server) RunCmd() (result string, err error)

func (*Server) RunScpDir

func (server *Server) RunScpDir() (err error)

func (*Server) SRunCmd

func (server *Server) SRunCmd() Result

func (*Server) SetCmd

func (s *Server) SetCmd(cmd string)

set Server.Cmd

Jump to

Keyboard shortcuts

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