blob: 4950d4cbdc8d7a6572fa9aa4ef30b054f14f946e [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package botanist
import (
// FetchAndArchiveFile fetches a remote file via TFTP from a given node, and
// writes it an archive.
func FetchAndArchiveFile(t *tftp.Client, addr *net.UDPAddr, tw *tar.Writer, path, name string) error {
receiver, err := t.Receive(addr, path)
if err != nil {
return fmt.Errorf("failed to receive file %s: %v\n", path, err)
hdr := &tar.Header{
Name: name,
Size: receiver.(tftp.Session).Size(),
Mode: 0666,
if err := tw.WriteHeader(hdr); err != nil {
return err
_, err = receiver.WriteTo(tw)
return err