Skip to content

Commit

Permalink
Merge pull request #17 from pin/better-client-readme
Browse files Browse the repository at this point in the history
more concise client usage example
  • Loading branch information
pin committed Apr 21, 2016
2 parents b506f93 + 53778cc commit 39d4171
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,52 +82,29 @@ TFTP Client
Uploading file to server:

```go
file, err := os.Open(path)
if err != nil {
...
}
// TODO: handle errors
c, err := tftp.NewClient("172.16.4.21:69")
if err != nil {
...
}
file, err := os.Open(path)
c.SetTimeout(5 * time.Second) // optional
r, err := c.Send("foobar.txt", "octet")
if err != nil {
...
}
// Optional tsize.
if ot, ok := r.(tftp.OutgoingTransfer); ok {
ot.SetSize(length)
}
n, err := r.ReadFrom(file)
fmt.Printf("%d bytes sent\n", n)
```

Downloading file from server:

```go
// TODO: handle errors
c, err := tftp.NewClient("172.16.4.21:69")
if err != nil {
...
}
w, err := c.Receive("foobar.txt", "octet")
if err != nil {
...
}
file, err := os.Create(path)
if err != nil {
...
}
// Optional tsize.
if it, ok := readTransfer.(IncomingTransfer); ok {
if n, ok := it.Size(); ok {
fmt.Printf("Transfer size: %d\n", n)
}
}
n, err := w.WriteTo(file)
if err != nil {
...
}
fmt.Printf("%d bytes received\n", n)
```

Expand Down

0 comments on commit 39d4171

Please sign in to comment.