Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.
/ ftp Public archive
forked from jlaffaye/ftp

FTP client package for Go

License

Notifications You must be signed in to change notification settings

DevotedHealth/ftp

 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.4%
  • Shell 1.6%