sftp

package
v0.0.0-...-f0ab10a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OpEnum = &Op{
	Encrypt: 1,
	Decrypt: 0,
}

OpEnum is the Enum for encryption operations

View Source
var RawEncryptionKey = "SlNqVVhZalpzWWg5ZkRWOENvWHdwNzhITnl3RnpnWnFE"

RawEncryptionKey is for the AES encryption key, it is base64Encoded.

Functions

func CreateSSHConfig

func CreateSSHConfig(inputConf *Input) (*ssh.ClientConfig, error)

CreateSSHConfig returns a config instance used to create an ssh/sftp connection.

func GetConfig

func GetConfig(confFile string) (map[string][]TransferConfig, error)

GetConfig returns the parsed config

func GetSFTPConfig

func GetSFTPConfig(sshhostkey string) *ssh.ServerConfig

GetSFTPConfig returns the config for the ssh/sftp server

func ListenSFTPServer

func ListenSFTPServer(lis net.Listener, sshhostkey string) error

ListenSFTPServer starts an SFTP Server

Types

type Client

type Client struct {
	Conn *sftp.Client
}

Client is a struct for client object + properties

func CreateClient

func CreateClient(inputConf *Input) (*Client, error)

CreateClient creates an sftp client

func (*Client) GetListOfFiles

func (client *Client) GetListOfFiles(rootDir string) []FileStat

GetListOfFiles gets the list of files on a remote sftp server

func (*Client) MultiFilesPull

func (client *Client) MultiFilesPull(fileList chan FileStat, outputPath string, length int) chan FileStat

MultiFilesPull is for pulling multiple files in parallel

func (*Client) Open

func (client *Client) Open(filepath string) (io.ReadWriteCloser, error)

Open is a wrapper around sftp Open function

func (*Client) Pull

func (client *Client) Pull(inputfile, outputfile string) (int64, error)

Pull copies inputfile from a remote sftp server as outputfile on the local filesystem.

func (*Client) Push

func (client *Client) Push(inputfile, outputfile string) (int64, error)

Push copies inputfile to a remote sftp server as outputfile

func (*Client) Stat

func (client *Client) Stat(filename string) (os.FileInfo, error)

Stat is a wrapper around the the sftp Stat function

func (*Client) Walk

func (client *Client) Walk(rootDir string) *fs.Walker

Walk is a wrapper around the sftp walk function

type Config

type Config interface {
	EncryptSecureFields(key string) error
	DecryptSecureFields(key string) error
	EncodeGob() error
	DecodeGob() error
}

Config is the Interface for methods on TransferConfig struct

type FileStat

type FileStat struct {
	Path string
	Stat os.FileInfo
	Err  error
}

FileStat is for file info on a remote sftp file.

type Input

type Input struct {
	Address  string
	Username string
	Password string
	Protocol string
	// AuthMethod: One of pk, pk+pass, pass
	AuthMethod string
	PrivateKey string
	// ?
	ConnectionType string
}

Input is a struct for creating the sftp client

type Op

type Op struct {
	Encrypt int
	Decrypt int
}

Op is for encryption operation

type TransferConfig

type TransferConfig struct {
	TransferID        string `json:"transfer_id"`
	Description       string `json:"description"`
	Type              string `json:"type"`
	LocalFile         string `json:"local_file"`
	LocalPath         string `json:"local_path"`
	RemoteFile        string `json:"remote_file"`
	RemotePath        string `json:"remote_path"`
	RemoteHost        string `json:"remote_host"`
	RemotePort        int    `json:"remote_port"`
	RemoteUser        string `json:"remote_user"`
	RemotePassword    string `json:"remote_password"`
	RemoteAuthKeyFile string `json:"remote_auth_key"`
}

TransferConfig is the struct for parsing the configs

func (*TransferConfig) DecodeGob

func (config *TransferConfig) DecodeGob(value []byte) error

DecodeGob takes a encoded Gob as a byte array and updates the struct instance with the decoded values

func (*TransferConfig) DecryptSecureFields

func (config *TransferConfig) DecryptSecureFields() error

DecryptSecureFields decrypts the fields of the struct instance.

func (*TransferConfig) EncodeGob

func (config *TransferConfig) EncodeGob() ([]byte, error)

EncodeGob Returns Gob encoded byte array of struct

func (*TransferConfig) EncryptSecureFields

func (config *TransferConfig) EncryptSecureFields() error

EncryptSecureFields encrypts the fields of struct instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL