Skip to content

Commit

Permalink
feat(readme): add file upload example (#17)
Browse files Browse the repository at this point in the history
* docs(readme): add file upload example

---------

Co-authored-by: Adam Shannon <[email protected]>
  • Loading branch information
hantsaniala and adamdecaf authored Oct 17, 2024
1 parent 1498bd3 commit d18b719
Showing 1 changed file with 49 additions and 0 deletions.
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

0 comments on commit d18b719

Please sign in to comment.