logman/sftp.go

48 lines
687 B
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
)
var (
2019-08-19 20:43:01 -05:00
dstPath string = "/home/wyatt/"
srcPath string = "/var/log/"
2019-08-19 20:43:01 -05:00
filename string = "dpkg.log"
)
2019-09-26 19:23:36 -05:00
func (s SSHConnection) getFile(client *ssh.Client) {
sftp, err := sftp.NewClient(client)
2019-09-26 19:23:36 -05:00
//var srcFile []*os.File
//var dstFile []*os.File
if err != nil {
2019-09-26 19:23:36 -05:00
fmt.Errorf("Error")
}
defer sftp.Close()
2019-09-26 19:23:36 -05:00
for _, j := range s.Logs {
srcFile, err := sftp.Open(srcPath + 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()
2019-09-26 19:23:36 -05:00
dstFile, err := os.Create(dstPath + j)
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)
}
}