Downloading from non-HTTP sources

We'll start by writing the function that will download the data, as follows:

func download() io.Reader {  client, err := ftp.Dial("aftp.cmdl.noaa.gov:21")  dieIfErr(err)  dieIfErr(client.Login("anonymous", "anonymous"))  reader, err := client.Retr("products/trends/co2/co2_mm_mlo.txt")  dieIfErr(err)  return reader}

The NOAA data sits on a publicly accessible FTP server: ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt. If you visit the URI via a web browser, you would see the data immediately. To access the data programmatically is a little tricky, as this is not a typical HTTP URL.

To handle FTP connections, we will be using the github.com/jlaffaye/ftp package. The package can be installed using the ...

Get Go Machine Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.