go_sftp

package module
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

README

Moov Banner Logo

Community · Blog

GoDoc Build Status Coverage Status Go Report Card Repo Size Apache 2 License Slack Channel GitHub Stars Twitter

moov-io/go-sftp

Moov's mission is to give developers an easy way to create and integrate bank processing into their own software products. Our open source projects are each focused on solving a single responsibility in financial services and designed around performance, scalability, and ease of use.

GoSFTP provides a simple SFTP client interface for uploading, listing, and opening files on an SFTP server.

type Client interface {
	Ping() error
	Close() error

	Open(path string) (*File, error)
	Reader(path string) (*File, error)

	Delete(path string) error
	UploadFile(path string, contents io.ReadCloser) error

	ListFiles(dir string) ([]string, error)
	Walk(dir string, fn fs.WalkDirFunc) error
}

The library also includes a mock client implementation which uses a local filesystem temporary directory for testing.

Project status

Moov GoSFTP is actively used in production environments. Please star the project if you are interested in its progress. Please let us know if you encounter any bugs/unclear documentation or have feature suggestions by opening up an issue or pull request. Thanks!

Getting help

channel info
Project Documentation Our project documentation available online.
Twitter @moov You can follow Moov.io's Twitter feed to get updates on our project(s). You can also tweet us questions or just share blogs or stories.
GitHub Issue If you are able to reproduce a problem please open a GitHub Issue under the specific project that caused the error.
moov-io slack Join our slack channel to have an interactive discussion about the development of the project.

Supported and tested platforms

  • 64-bit Linux (Ubuntu, Debian), macOS, and Windows

Contributing

Yes please! Please review our Contributing guide and Code of Conduct to get started!

This project uses Go Modules and Go v1.18 or newer. See Golang's install instructions for help setting up Go. You can download the source code and we offer tagged and released versions as well. We highly recommend you use a tagged release for production.

Releasing

To make a release of go-sftp simply open a pull request with CHANGELOG.md and version.go updated with the next version number and details. You'll also need to push the tag (i.e. git push origin v1.0.0) to origin in order for CI to make the release.

Testing

We maintain a comprehensive suite of unit tests and recommend table-driven testing when a particular function warrants several very similar test cases. After starting the services with Docker Compose run all tests with go test ./.... Current overall coverage can be found on Codecov.

License

Apache License 2.0 - See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Ping() error
	Close() error

	Open(path string) (*File, error)
	Reader(path string) (*File, error)

	Delete(path string) error
	UploadFile(path string, contents io.ReadCloser) error

	ListFiles(dir string) ([]string, error)
	Walk(dir string, fn fs.WalkDirFunc) error
}

func NewClient

func NewClient(logger log.Logger, cfg *ClientConfig) (Client, error)

type ClientConfig

type ClientConfig struct {
	Hostname string
	Username string
	Password string

	Timeout        time.Duration
	MaxConnections int
	PacketSize     int

	HostPublicKey string

	// ClientPrivateKey must be a base64 encoded string
	ClientPrivateKey         string
	ClientPrivateKeyPassword string // not base64 encoded

	SkipChmodAfterUpload  bool
	SkipDirectoryCreation bool
}

type File

type File struct {
	Filename string
	Contents io.ReadCloser

	// ModTime is a timestamp of when the last modification occurred
	// to this file. The default will be the current UTC time.
	ModTime time.Time
	// contains filtered or unexported fields
}

File represents a fs.File object of a location on a SFTP server.

func (*File) Close

func (f *File) Close() error

func (*File) Read

func (f *File) Read(buf []byte) (int, error)

func (*File) Stat

func (f *File) Stat() (fs.FileInfo, error)

type MockClient

type MockClient struct {
	Err error
	// contains filtered or unexported fields
}

func NewMockClient

func NewMockClient(t *testing.T) *MockClient

func (*MockClient) Close

func (c *MockClient) Close() error

func (*MockClient) Delete

func (c *MockClient) Delete(path string) error

func (*MockClient) Dir

func (c *MockClient) Dir() string

func (*MockClient) ListFiles

func (c *MockClient) ListFiles(dir string) ([]string, error)

func (*MockClient) Open

func (c *MockClient) Open(path string) (*File, error)

func (*MockClient) Ping

func (c *MockClient) Ping() error

func (*MockClient) Reader

func (c *MockClient) Reader(path string) (*File, error)

func (*MockClient) UploadFile

func (c *MockClient) UploadFile(path string, contents io.ReadCloser) error

func (*MockClient) Walk

func (c *MockClient) Walk(dir string, fn fs.WalkDirFunc) error

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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