| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package ftp
- import (
- "bytes"
- "io/ioutil"
- "testing"
- )
- const (
- testData = "Just some text"
- )
- func TestConn(t *testing.T) {
- c, err := ConnectAnonymous("localhost:21")
- if err != nil {
- t.Fatal(err)
- }
- err = c.NoOp()
- if err != nil {
- t.Error(err)
- }
- data := bytes.NewBufferString(testData)
- err = c.Stor("test", data)
- if err != nil {
- t.Error(err)
- }
- _, err = c.List(".")
- if err != nil {
- t.Error(err)
- }
- err = c.Rename("test", "tset")
- if err != nil {
- t.Error(err)
- }
- r, err := c.Retr("tset")
- if err != nil {
- t.Error(err)
- } else {
- buf, err := ioutil.ReadAll(r)
- if err != nil {
- t.Error(err)
- }
- if string(buf) != testData {
- t.Errorf("'%s'", buf)
- }
- r.Close()
- }
- err = c.Delete("tset")
- if err != nil {
- t.Error(err)
- }
- err = c.MakeDir("mydir")
- if err != nil {
- t.Error(err)
- }
- err = c.RemoveDir("mydir")
- if err != nil {
- t.Error(err)
- }
- c.Quit()
- }
|