logman/sftp.go

48 lines
684 B
Go
Raw Permalink Normal View History

package main
import (
"fmt"
"os"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
)
func (s SSHConnection) getFile(client *ssh.Client) []*os.File {
homedir, _ := os.UserHomeDir()
var dstFiles []*os.File
for _, j := range s.Logs {
sftp, err := sftp.NewClient(client)
if err != nil {
fmt.Errorf("Error")
}
defer sftp.Close()
srcFile, err := sftp.Open(j)
2019-09-26 19:23:36 -05:00
if err != nil {
fmt.Errorf("Error")
}
2019-09-26 19:23:36 -05:00
defer srcFile.Close()
h := slashSeperator(j)
dstFile, err := os.Create(homedir + "/" + h)
2019-09-26 19:23:36 -05:00
if err != nil {
fmt.Errorf("Error")
}
2019-09-26 19:23:36 -05:00
defer dstFile.Close()
srcFile.WriteTo(dstFile)
dstFiles = append(dstFiles, dstFile)
2019-09-26 19:23:36 -05:00
}
return dstFiles
}