Ai
1 Star 0 Fork 0

moorewqk/sshftp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sshclient.go 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
moorewqk 提交于 2022-03-09 19:13 +08:00 . add code
package sshftp
import (
"bytes"
)
func (this *Client) Cmd(cmd string) (stdout, stderr string, err error) {
var (
stdoutBuf bytes.Buffer
stderrBuf bytes.Buffer
)
err = this.connect()
if err!=nil{
return stdoutBuf.String(),stderrBuf.String(),err
}
this.sshSession.Stdout = &stdoutBuf
this.sshSession.Stderr = &stderrBuf
err = this.sshSession.Run(cmd)
defer this.sshSession.Close()
stdout = stdoutBuf.String()
stderr = stderrBuf.String()
return
}
//func (c *SSHClient) Pipe(rw ReadWriteCloser, pty *PtyInfo, deadline *time.Time, idleTimeout int) (currentSession *SshSession, err error) {
// if c.isConnected == false {
// _, err := c.Connect()
// if err != nil {
// return nil, err
// }
// }
// currentSession, err = NewSession(c.remoteConn, deadline, idleTimeout)
// if err != nil {
// return
// }
//
// if err = currentSession.RequestPty(pty.Term, pty.H, pty.W, pty.Modes); err != nil {
// return
// }
// wc, err := currentSession.StdinPipe()
// if err != nil {
// return
// }
//
// go CopyIOAndUpdateSessionDeadline(wc, rw, currentSession)
//
// r, err := currentSession.StdoutPipe()
// if err != nil {
// return
// }
// go CopyIOAndUpdateSessionDeadline(rw, r, currentSession)
// er, err := currentSession.StderrPipe()
// if err != nil {
// return
// }
// go CopyIOAndUpdateSessionDeadline(rw, er, currentSession)
// err = currentSession.Shell()
// if err != nil {
// return
// }
// err = currentSession.Wait()
// if err != nil {
// return
// }
// defer currentSession.Close()
// return
//}
//func getClient(hostname string) (client *SSHClient, err error) {
// if hostname == "" {
// return nil, errors.New("host name is empty")
// }
// sshClientsMutex.RLock()
// client = sshClients[hostname]
// if client != nil {
// return client, nil
// }
// sshClientsMutex.RUnlock()
// return nil, errors.New("client not create")
//}
//
//func ExecuteCmd(cmd, hostname string) (output, errput string, currentSession *SshSession, err error) {
// client, err := getClient(hostname)
// if err != nil {
// return
// }
// return client.Cmd(cmd, nil, nil, 0)
//}
//func UploadFile(hostname, sourceFile, targetFile string) (stdout, stderr string, err error) {
// client, err := getClient(hostname)
// if err != nil {
// return
// }
// f, err := os.Open(sourceFile)
// if err != nil {
// return
// }
// defer f.Close()
// data, err := ioutil.ReadAll(f)
// if err != nil {
// return
// }
// return client.TransferData(targetFile, data)
//}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/moorewqk/sshftp.git
git@gitee.com:moorewqk/sshftp.git
moorewqk
sshftp
sshftp
master

搜索帮助