package context
import (
"bytes"
"fmt"
"golang.org/x/crypto/ssh"
"io"
"log"
"strings"
"sync"
"time"
)
type Context struct {
SshBuffer *SshBuffer
SshTerminal *SshTerminal
Client *ssh.Client
Session *ssh.Session
Start bool
User string
}
type SshBuffer struct {
outBuf *bytes.Buffer
stdinBuf io.WriteCloser
}
type SshTerminal struct {
in chan string
out chan string
}
//var terminatorMap = map[string]byte{"root":'#',"common":'$'}
func NewContext() *Context {
var stdinBuf io.WriteCloser
return &Context{
SshBuffer: &SshBuffer{
bytes.NewBuffer(make([]byte,0)),
stdinBuf,
},
SshTerminal: &SshTerminal{
make(chan string,1),
make(chan string,1),
},
}
}
func (c *Context) InitCommonTerminal() error {
if c.Start{
return fmt.Errorf("session is start terminal")
}
err := c.InitCommonSession()
if err != nil{
return err
}
session := c.Session
modes := ssh.TerminalModes{
ssh.ECHO: 0,
ssh.TTY_OP_ISPEED: 14400,
ssh.TTY_OP_OSPEED: 14400,
}
if err = sessio
go ssh session执行多条命令
最新推荐文章于 2023-12-12 10:55:11 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)