tftp server & installation

Introduction

Trivial File Transfer Protocol (TFTP) is a simple lockstep File Transfer Protocol which allows a client to get a file from or put a file onto a remote host. One of its primary uses is in the early stages of nodes booting from a local area network. TFTP has been used for this application because it is very simple to implement. TFTP was first standardized in 1981 and the current specification for the protocol can be found in RFC 1350.

Installation (Linux)

Install the following packages

 $ sudo apt-get update
 $ sudo apt-get install tftpd-hpa

After installation, tftpd-hpa service will start running. check the service status

 $ sudo systemctl status tftpd-hpa

Modify tftpd-hpa configuration file

sudo nano /etc/default/tftpd-hpa

# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure --create"

Create a folder /tftp this should match whatever you gave in server_args. mostly it will be tftp

 sudo mkdir /tftp
 sudo chown tftp:tftp /tftp

Restart the tftpd-hpa service.

 sudo systemctl restart tftpd-hpa

Check the tftpd-hpa service status

 sudo systemctl status tftpd-hpa

Now our tftp server is up and running.

Testing our tftp server

Create a file named test with some content in /tftp path of the tftp server Obtain the ip address of the tftp server using ifconfig command.

Now in some other system follow the following steps.

 tftp <server-ip>
 tftp> get test
 Sent 159 bytes in 0.0 seconds

 tftp> quit

 cat test

ftp server using python

 #!/usr/bin/env python3

 from pyftpdlib import servers
 from pyftpdlib.handlers import FTPHandler
 address = ("0.0.0.0", 21)  # listen on every IP on my machine on port 21
 server = servers.FTPServer(address, FTPHandler)
 server.serve_forever()

©2023-2024 rculock.com