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)?
Asked
Active
Viewed 3.9k times
1 Answers
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"