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