go_sftp

package module
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: Apache-2.0 Imports: 19 Imported by: 1

README

Moov Banner Logo

Community · Blog

GoDoc Build Status Go Report Card Apache 2 License Slack Channel 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.

moov-io/go-sftp provides a simple SFTP client 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-io/go-sftp 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
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 (#infra) 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!

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 (make setup) run all tests with make check.

License

Apache License 2.0 - See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMultiKeyCallback added in v0.14.0

func NewMultiKeyCallback(keys []string) (ssh.HostKeyCallback, error)

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 configures an SSH public key to validate the remote server's host key.
	// If provided, this key will be merged into HostPublicKeys.
	// Deprecated: Use HostPublicKeys instead.
	HostPublicKey string

	// HostPublicKeys configures multiple SSH public keys to validate the remote server's host key.
	// Any key provided in HostPublicKey will be appended to this list.
	HostPublicKeys []string

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

	SkipChmodAfterUpload  bool
	SkipDirectoryCreation bool
	SkipSyncAfterUpload   bool
}

func (ClientConfig) HostKeys added in v0.14.0

func (cfg ClientConfig) HostKeys() []string

HostKeys returns the list of configured public keys to use for host key verification.

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 added in v0.5.0

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

func (*File) Stat added in v0.5.0

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 added in v0.9.0

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

func (*MockClient) UploadFile

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

func (*MockClient) Walk added in v0.9.0

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

type MultiKeyCallback added in v0.14.0

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

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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