9

I need to download the complete directory structure from a TFTP server. Is there some simple way to do that? If that is not possible, than how could I download all files individually (provided I have a list of all files on the server)?

vonbrand
  • 18,156
  • 2
  • 37
  • 59
user1968963
  • 3,973
  • 13
  • 37
  • 56

1 Answers1

8

You cannot list files or directories with TFTP. Read first paragraph of RFC 1350 - 1. Purpose. (or better yet, read the whole document.)

If you have a file list in say files.txt you can use expect, curl or other to automate a download. Simple example (as a starter) using curl:

tftpbatch:

#!/bin/bash

server="tftp://$2"

while IFS= read -r path; do
    [[ "$path" =~ ^\ *$ ]] && continue
    dir="$(dirname "$path")"
    printf "GET %s => %s\n" "$path" "$dir"
    ! [ -d "$dir" ] && mkdir -p "$dir"
    curl -o "$path" "$server/$path"
done < "$1"

Run with:

./tftpbatch files.txt "10.0.0.5:69"
Runium
  • 28,133
  • 5
  • 50
  • 71