/
sftp.go
40 lines (32 loc) · 820 Bytes
/
sftp.go
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
38
39
package sh
import (
"github.com/pkg/sftp"
"io"
"os"
)
type SftpClient interface {
Lock()
Unlock()
ReadDir(path string) ([]os.FileInfo, error)
Join(elem ...string) string
Remove(path string) error
Stat(p string) (os.FileInfo, error)
OpenFile(path string) (io.ReadCloser, error)
CreateFile(path string) (io.Writer, error)
Mkdir(path string) error
}
type extendedSftpClient struct {
*sftp.Client
}
func (client *extendedSftpClient) OpenFile(path string) (io.ReadCloser, error) {
return client.Open(path)
}
func (client *extendedSftpClient) CreateFile(path string) (io.Writer, error) {
return client.Create(path)
}
func (client *extendedSftpClient) Mkdir(path string) error {
return client.MkdirAll(path)
}
func extend(client *sftp.Client) *extendedSftpClient {
return &extendedSftpClient{client}
}