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.
Important Note: When using TFTP to upload files, the client looks for files in your current working directory. Make sure you're in the correct directory (~/project) before attempting to upload files.
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 make sure we're in the correct directory and check the content of this file:
cd ~/project
ls -la sample.txt
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
If you get a "File not found" error, exit TFTP and verify the file exists:
quit
ls -la ~/project/sample.txt
cd ~/project
tftp localhost
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:
cd ~/project
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.