Transferring Files Using the TFTP Client
Now that we have a running TFTP server with a test file, let's learn how to transfer files using the TFTP client. We will practice both downloading files from the server and uploading files to the server.
Downloading Files from the TFTP Server
First, let's try to download the server-file.txt
file we created in the previous step. We'll use the TFTP client in interactive mode:
cd ~/project
tftp localhost
You should see the tftp>
prompt. Let's set the transfer mode to binary, which is suitable for all file types:
binary
Now, download the file from the server:
get server-file.txt downloaded-file.txt
This command downloads server-file.txt
from the server and saves it as downloaded-file.txt
in your current directory.
After the file transfer completes, exit the TFTP client:
quit
Let's verify that the file was downloaded correctly:
cat downloaded-file.txt
You should see:
This is a file in the TFTP server directory.
Uploading Files to the TFTP Server
Now, let's try uploading a file to the TFTP server. We already have a sample.txt
file in our project directory that was created by the setup script.
First, let's check the content of this file:
cat sample.txt
You should see:
This is a sample file for TFTP transfer testing.
Now, let's upload this file to the TFTP server:
tftp localhost
At the tftp>
prompt, set the transfer mode to binary and upload the file:
binary
put sample.txt uploaded-sample.txt
This command uploads your local sample.txt
file to the server and saves it as uploaded-sample.txt
. After the file transfer completes, exit the TFTP client:
quit
Now, let's verify that the file was successfully uploaded to the server:
cat /tftpboot/uploaded-sample.txt
You should see:
This is a sample file for TFTP transfer testing.
Using TFTP with a Single Command Line
You can also use TFTP without entering interactive mode by providing all the necessary information in a single command line. For example:
echo "One-line TFTP test" > oneline-test.txt
tftp -c put oneline-test.txt localhost
Let's check if the file was uploaded to the server:
cat /tftpboot/oneline-test.txt
You should see:
One-line TFTP test
This demonstrates that you can use TFTP both interactively and with single command lines, depending on your needs.
In the next step, we will explore more advanced TFTP options and troubleshooting techniques.