Wednesday, 11 November 2026

Quick-and-Dirty TFTP Server

It is easy and frequently handy to spin up an impromptu webserver using Python's http.server module:-

$ python -m http.server Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

But what if you want a similarly-impromptu TFTP server? It is almost as easy. It requires the tftpy module (installable with pip) a few lines of code:-

#!/usr/bin/env python3 import os import sys import tftpy # Serves/saves files in the directory where the script is executed root_dir = os.getcwd() print(f"[*] Starting temporary TFTP server in {root_dir}") print("[*] Listening on 0.0.0.0:69 (UDP)... Press Ctrl+C to stop.") server = tftpy.TftpServer(root_dir) try: # Set to '0.0.0.0' to listen on all interfaces server.listen('0.0.0.0', 69) except PermissionError: print("\n[!] Error: Binding to UDP port 69 requires root privileges.") print(" Please run again using: sudo python3 tftpd.py") sys.exit(1) except KeyboardInterrupt: print("\n[*] Stopping TFTP server.")

Then...

$ sudo python server.py [*] Starting temporary TFTP server in /home/pi/tftpy [*] Listening on 0.0.0.0:69 (UDP)... Press Ctrl+C to stop.

The sudo is only required if you need to listen on port 69/udp: if you can use a non-default port, you can run as a regular user.

No comments:

Post a Comment