-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsftp_utils.go
More file actions
37 lines (33 loc) · 822 Bytes
/
sftp_utils.go
File metadata and controls
37 lines (33 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
"net"
)
func createSshSession(host, port, username, password string) (*ssh.Client, error) {
// user data
sshConfig := &ssh.ClientConfig{
User: username,
Auth: []ssh.AuthMethod{
ssh.Password(password),
},
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
// create ssh connection
return ssh.Dial("tcp", fmt.Sprintf("%s:%s", host, port), sshConfig)
}
func saveImageOnServer(sftpConn *sftp.Client, uploadDirectory string, screenName string, data []byte) error {
// create new file
f, err := sftpConn.Create(uploadDirectory + "/" + screenName)
if err != nil {
return err
}
// write in new fle
if _, err := f.Write(data); err != nil {
return err
}
return nil
}