I’m working on collecting log files from a server and storing them locally for additional processing. The logs come down as a zip. If I run this code, it does create the file, however it’s empty. If I take the url and paste it into a browser it does download the complete file. Any suggestions on how to fix it? I’m not worried about expanding the file, just want to download and store.
‘’'func DownloadFile(filepath string, url string) error {
request, httpErr := http.NewRequest("GET", url, nil)
// ignore certs during data collection
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
if httpErr != nil {
fmt.Printf("The HTTP request failed with error %s\n", httpErr)
}
client := &http.Client{Transport: tr}
response, err := client.Do(request)
defer response.Body.Close()
// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
// Write the body to file
_, err = io.Copy(out, response.Body)
return err
}
‘’’
Thanks,
Kevin