Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(readme): add file upload example #17

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,55 @@ type Client interface {

The library also includes a [mock client implementation](https://pkg.go.dev/github.com/moov-io/go-ftp#MockClient) 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:

```go
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!
Expand Down
Loading