Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Latest commit

 

History

History
72 lines (55 loc) · 1.47 KB

README.md

File metadata and controls

72 lines (55 loc) · 1.47 KB

goftp

Build Status Coverage Status Go ReportCard

A FTP and FTPS client package for Go

Install

go get -u github.com/dchang-dchang/ftp

Usage

Create a FTP connection

host, port := "ftp.hostname.com", 21
_ = s.Dial(fmt.Sprintf("%s:%d", host, port))
defer s.Quit()

Set timeouts, debug mode, and/or TLS config for implicit TLS

(Note: If a TLSConfig is set, both the command and data channel will be secured with the same config)

host, port := "ftp.hostname.com", 990
s := ftp.ServerConn{
  Debug:     true,
  Timeout:   30*time.Second,
  TLSConfig: &tls.Config{ServerName: host},
}
_ = s.Dial(fmt.Sprintf("%s:%d", host, port))
defer s.Quit()

Login

_ = s.Login(username, password)

List files

entries, _ := s.List("/")
for _, entry := range entries {
  fmt.Println(entry)
}

Get a file

res, _ := s.Retr("/filename.txt")
reader := bufio.NewReader(res)
for {
  line, err := reader.ReadString('\n')
  if err == io.EOF {
    break
  } else if err != nil {
    panic(err)
  }
  fmt.Println(line)
}

Documentation

http://godoc.org/github.com/dchang-dchang/ftp