sftp2

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package sftp2 provides functions for interacting with a SFTP server.

Index

Constants

View Source
const (
	DefaultPort    = 22
	DefaultTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

func CheckFileRead

func CheckFileRead(client *sftp.Client, path string) error

func CheckFileWrite

func CheckFileWrite(client *sftp.Client, path string, appendToFile bool, overwrite bool) error

func Stat

func Stat(client *sftp.Client, path string) (bool, stat.Info, error)

Stat stats the given resource. Returns a bool indicating whether the file exists, file info, and an error if any. If the underlying error was a "does not exist" error, then the error is supressed and returns false, nil, nil If the underlying error was any other type of error, then the existence value is not guaranteed. Do check the error returned and do not ignore the error with "exists, _, _ := Stat(/path/tofile)".

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader implements the io.ReadCloser interface to enabling reading a remote file on a SFTP server and closing the underlying connections.

func Fetch

func Fetch(uri string, options ...ssh2.ClientOption) (*Reader, error)

Fetch returns a Reader for a file at a given SFTP address.

Fetch returns an error if the address cannot be dialed, the userinfo cannot be parsed, the user and password are invalid, or the file cannot be retrieved.

func FetchWithKey

func FetchWithKey(uri string, key []byte, options ...ssh2.ClientOption) (*Reader, error)

FetchWithKey parses the provided key, appends the key to the ClientOption options, and then calls Fetch with the uri and options.

func NewReader

func NewReader(file *sftp.File, sftpClient *sftp.Client, sshClient *ssh.Client) *Reader

NewReader creates a new Reader for reading a file from a SFTP server.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the file reader, the SFTP connection, and the SSH connection.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read implements the io.Reader interface.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer implements the io.WriteCloser interface to enabling writing a remote file on a SFTP server and closing the underlying connections.

func NewWriter

func NewWriter(file *sftp.File, sftpClient *sftp.Client, sshClient *ssh.Client, fileMode os.FileMode) *Writer

NewWriter creates a new WRiter for reading a file from a SFTP server.

func WriteFile

func WriteFile(uri string, fileMode os.FileMode, options ...ssh2.ClientOption) (*Writer, error)

func (*Writer) Close

func (w *Writer) Close() error

Close closes the file reader, the SFTP connection, and the SSH connection.

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

Write implements the io.Writer interface.

Jump to

Keyboard shortcuts

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