Skip to content
/ go-ftp Public

A Go client for performing common FTP operations

License

Notifications You must be signed in to change notification settings

moov-io/go-ftp

Repository files navigation

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-ftp

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.

Go FTP provides a simple FTP client interface for uploading, listing, and opening files on an FTP 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.

Example

Here is an example of how to push file to an FTP server using this module:

package main

import (
	"log"
	"os"
	"path/filepath"

	ftp "github.com/moov-io/go-ftp"
)

// A simple FTP file upload using go-ftp.
func main() {
	// Create an FTP client using the server's host and port
	clientConfig := ftp.ClientConfig{
		Hostname: "ftp.server.com:21",
		Username: "admin",
		Password: "admin",
	}

	client, err := ftp.NewClient(clientConfig)
	if err != nil {
		log.Fatal(err)
	}

	// Check if the FTP client is reachable
	if err := client.Ping(); err != nil {
		log.Fatal(err)
	}

	if client != nil {
		defer client.Close()
	}

	// Open the file to be uploaded
	fileData, err := os.Open("file.txt")

	// Upload the file to the destination path
	err = client.UploadFile(filepath.Join("/tmp", "file.txt"), fileData)
	if err != nil {
		log.Fatal(err)
	}
}

Project status

Moov Go FTP 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-ftp 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.