2017-05-16 17:01:02 +00:00
|
|
|
# goftp #
|
|
|
|
|
|
|
|
[![Build Status](https://travis-ci.org/jlaffaye/ftp.svg?branch=master)](https://travis-ci.org/jlaffaye/ftp)
|
|
|
|
[![Coverage Status](https://coveralls.io/repos/jlaffaye/ftp/badge.svg?branch=master&service=github)](https://coveralls.io/github/jlaffaye/ftp?branch=master)
|
|
|
|
[![Go ReportCard](http://goreportcard.com/badge/jlaffaye/ftp)](http://goreportcard.com/report/jlaffaye/ftp)
|
2019-04-13 12:47:57 +00:00
|
|
|
[![godoc.org](https://godoc.org/github.com/jlaffaye/ftp?status.svg)](http://godoc.org/github.com/jlaffaye/ftp)
|
2017-05-16 17:01:02 +00:00
|
|
|
|
|
|
|
A FTP client package for Go
|
|
|
|
|
|
|
|
## Install ##
|
|
|
|
|
|
|
|
```
|
|
|
|
go get -u github.com/jlaffaye/ftp
|
|
|
|
```
|
|
|
|
|
2019-04-13 12:47:57 +00:00
|
|
|
## Example ##
|
2017-05-16 17:01:02 +00:00
|
|
|
|
2019-04-13 12:47:57 +00:00
|
|
|
```go
|
2019-04-30 16:07:37 +00:00
|
|
|
c, err := ftp.Dial("ftp.example.org:21", ftp.DialWithTimeout(5*time.Second))
|
2019-04-13 12:47:57 +00:00
|
|
|
if err != nil {
|
2019-04-30 16:07:37 +00:00
|
|
|
log.Fatal(err)
|
2019-04-13 12:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.Login("anonymous", "anonymous")
|
|
|
|
if err != nil {
|
2019-04-30 16:07:37 +00:00
|
|
|
log.Fatal(err)
|
2019-04-13 12:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do something with the FTP conn
|
|
|
|
|
2019-04-30 16:07:37 +00:00
|
|
|
if err := c.Quit(); err != nil {
|
|
|
|
log.Fatal(err)
|
2019-04-13 12:47:57 +00:00
|
|
|
}
|
|
|
|
```
|
2019-08-26 17:00:17 +00:00
|
|
|
|
|
|
|
## Store a file example ##
|
|
|
|
|
|
|
|
```go
|
|
|
|
data := bytes.NewBufferString("Hello World")
|
|
|
|
err = c.Stor("test-file.txt", data)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Read a file example ##
|
|
|
|
|
|
|
|
```go
|
|
|
|
r, err := c.Retr("test-file.txt")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-05-30 13:59:23 +00:00
|
|
|
defer r.Close()
|
2019-08-26 17:00:17 +00:00
|
|
|
|
|
|
|
buf, err := ioutil.ReadAll(r)
|
|
|
|
println(string(buf))
|
|
|
|
```
|