search
HomeSystem TutorialLINUXFast and easy file transfer – learn about Linux TFTP

Fast and easy file transfer – learn about Linux TFTP

Feb 12, 2024 pm 03:15 PM
linuxlinux tutoriallinux systemlinux commandshell scriptembeddedlinuxGetting started with linuxlinux learning

In Linux systems, we often need to transfer files. However, although file transfer can be achieved using the traditional FTP protocol, the configuration process is relatively complex and is not suitable for quick and easy file transfer. So, is there a more convenient and faster way to transfer files? The answer is yes - it is TFTP.

Did you know there's a simpler alternative to the popular file transfer protocol? It's TFTP, and here's how to set it up on Linux.

TFTP (Trivial File Transfer Protocol) was first defined in 1980. It is a fairly old protocol, published as TFTP Protocol Revision 2 in June 1981 by Karen R. Sollins in RFC 783 (Request for Comments).

In the early days, the main goal of TFTP was to send and receive files over the network. In particular, it is used to transfer files required during boot to enable the system to boot over the network.

The following describes how to set up a TFTP server on a Linux machine.

What is TFTP?

TFTP is still used for file transfer purposes, with no fundamental changes to the functionality it supports. TFTP is used to download and send files over UDP/IP. It does not have additional features such as identity and authorization controls, file listing, deletion or renaming that are common in other file transfer protocols.

Unlike the Advanced File Transfer Protocol, which uses TCP at the transport layer, it works on the UDP protocol and does not have functions such as checking whether data packets belonging to files will be sent to the other end. Because of this limitation, it is more suitable for use in a LAN rather than the Internet or WAN.

Despite all of these seemingly disadvantageous properties listed above, one aspect of the TFTP protocol that is very powerful is its simplicity. Compared to its alternatives, this protocol is very easy to implement, even for environments without an operating system. Due to this feature, it has a wide range of uses in embedded systems.

Install TFTP server on Linux

When using embedded devices, it is important to install the TFTP server service. On Linux systems, it is possible to run multiple TFTP server implementations. If you are using a Debian-based distribution, you can install the tftpd-hpa, tftpd or atftpd packages. If you are not sure which one to choose, consider installing the tftpd-hpa package.

┌──(linuxmi㉿linuxmi)-[~/linuxmi.com]
└─$ sudo apt-get install tftpd-hpa
快速简便的文件传输——了解Linux TFTP

After installation, the TFTP service will start listening on UDP port 69. To serve files to other systems via a TFTP server, you need to remember some prerequisites:
The first is to copy the required files to the TFTP home directory or a directory under that home directory, and the second is to make the file permissions visible to the public
To find out what the TFTP server home directory is, you can look at the TFTP_DIRECTORY variable in the /etc/default/tftpd-hpa file. Typically, you'll see directories like /var/lib/tftpboot or /srv/tftp. If necessary, you can change this directory and restart the service.

┌──(linuxmi㉿linuxmi)-[~/linuxmi.com]
└─$ cat /etc/default/tftpd-hpa
快速简便的文件传输——了解Linux TFTP

For ease of use, if you change the owner of the relevant TFTP home directory to your user account, you do not need to add the sudo prefix to every command you run. Use the chown command to change ownership from root to the current user:

sudo chown -R $USER /srv/tftp

The TFTP server package name and default home directory may vary depending on the Linux distribution used.

Use TFTP server to send files

Sometimes there are situations where TFTP is the only option for moving files from an embedded Linux system to an external environment. For example, sometimes the system may not support any writable media that can be used to transfer files.

In this case, since the TFTP client may be compiled in busybox, you can send the files saved in the system to the TFTP server on the network.

To use the TFTP client application, issue the busybox tftp command:

busybox tftp

To send the sample file to the TFTP server, you need to use the following command:

busybox tftp -l example.bin -p 192.168.1.111

Although the above command is correct, an error will occur while transferring the file to the TFTP server. Since the error message returned is not self-explanatory, it can be difficult to understand what the real problem is.

The problem here is because of some security procedures on the TFTP server. TFTP requires that a file with the same name should be located in the directory where the file will be written, as a prerequisite for file upload, and that write permissions for the file should be available to everyone.

In other words, files that do not exist on the TFTP server cannot be uploaded through the TFTP client. If you create an empty file with the same name and edit its access permissions, the above upload process will succeed. To do this, you must run the following command in the relevant TFTP server home directory:

cd /srv/tftp  
touch example.bin
chmod 666 example.bin

Now you can perform the upload successfully.

It is also possible to disable the above security measures and let the TFTP server create a file that does not exist. To do this, you can use the -c or --create parameter when starting the tftpd-hpa application. It is sufficient to add this parameter to the existing TFTPD_OPTIONS variable in the /etc/default/tftpd-hpa file:

# /etc/default/tftpd-hpa  
TFTP_USERNAME="tftp"  
TFTP_DIRECTORY="/srv/tftp"  
TFTP_ADDRESS="0.0.0.0:69"  
TFTP_OPTIONS="--secure --create"

为什么使用 TFTP 服务器进行文件传输?

TFTP 最重要的优点是速度快,并且可以帮助您节省时间。它是将网络设备的配置文件传输到其他系统的理想选择。此外,它具有非常简单的使用标准。它可以与基于 Windows 和 Linux 的操作系统上的软件一起轻松运行。最后,在技术上无法使用 FTP 的情况下,TFTP 总是可以挽救局面。

当然,最大的缺点是不安全。因此,使用 TFTP 服务器传输文件时必须非常小心。

除了文件传输之外,您不能使用 TFTP 服务器执行文件删除、编辑和修改等功能。对于那些使用或寻求高级系统的人来说,此功能是一个主要缺点。最后,它不需要身份验证,如果您认真对待自己的安全性,这是一个主要缺点。

在其他操作系统上设置 TFTP

如果要在 Windows 上使用 TFTP,则无需安装任何第三方软件。您可以使用控制面板中的打开或关闭 Windows 功能选项启用 TFTP。

本文介绍了Linux系统中TFTP(Trivial File Transfer Protocol)的使用方法和特点。与FTP相比,TFTP具有更加简单、快速、轻量级的特点,既不需要繁琐的配置,也不会占用大量的系统资源。通过学习TFTP的使用方法,我们可以实现快速简便的文件传输,提高工作效率。因此,TFTP绝对是每个Linux用户都值得了解和掌握的重要工具!

The above is the detailed content of Fast and easy file transfer – learn about Linux TFTP. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:良许Linux教程网. If there is any infringement, please contact admin@php.cn delete
5 Best Free PDF to Word Doc Converters for Linux5 Best Free PDF to Word Doc Converters for LinuxMay 16, 2025 am 10:00 AM

Portable Document Format (PDF) remains a widely used file format due to its consistent standards across different platforms and devices, compatibility, and compact size.Numerous powerful tools are available for viewing PDF files, catering to various

How to Install Linux Mint 22 Mate on Your ComputerHow to Install Linux Mint 22 Mate on Your ComputerMay 16, 2025 am 09:44 AM

Linux Mint 22, codenamed “Wilma”, was officially launched as a significant update to Linux Mint on July 25, 2024. Linux Mint 22 is an LTS (Long Term Service) release, built upon Ubuntu 24.04, and will receive support until April 2029.As anticipated,

How to Hack Your Own Linux System to Strengthen SecurityHow to Hack Your Own Linux System to Strengthen SecurityMay 16, 2025 am 09:39 AM

Passwords serve as the primary security measure across various systems, including Linux, where the root password grants full control over the system. They are essential for securing BIOS, login, disks, applications, and more.Linux is widely regarded

6 Best Linux Software and Apps with Data Encryption6 Best Linux Software and Apps with Data EncryptionMay 16, 2025 am 09:33 AM

Data encryption is an essential component of modern cybersecurity, enabling the encoding of data to render it unreadable to unauthorized users. To enhance your online security, consider choosing software that incorporates this vital feature as a stan

How to Install Linux Mint 22 XFCE on Your ComputerHow to Install Linux Mint 22 XFCE on Your ComputerMay 16, 2025 am 09:28 AM

Linux Mint 22, with the codename “Wilma”, has been officially launched and is ready for download. Built on Ubuntu 24.04, it offers support until 2029 and comes in three flavors: Cinnamon, MATE, and XFCE.This guide will take you through the steps to i

16 Best Open Source Cloud Storage Software for Linux in 202416 Best Open Source Cloud Storage Software for Linux in 2024May 16, 2025 am 09:15 AM

The term "cloud" evokes a sense of vastness and expansiveness. In the technology sector, "the cloud" denotes a virtual platform that delivers services to end-users, encompassing data storage, application hosting, and the virtualiz

How to Install Linux Mint 22 Cinnamon on Your ComputerHow to Install Linux Mint 22 Cinnamon on Your ComputerMay 16, 2025 am 09:10 AM

Linux Mint is a contemporary, user-friendly, and community-driven GNU/Linux desktop distribution, built on the well-known Ubuntu Linux distribution. It's an excellent choice for users transitioning from Windows or macOS to the Linux environment.Linux

4 Best Tools to Create PDF Forms on Linux4 Best Tools to Create PDF Forms on LinuxMay 16, 2025 am 09:08 AM

Introduction: In this article, you will find the best applications for creating PDF files (also known as interactive tables) on Linux. If you need powerful tools to create and edit PDF files on Linux, you have many applications to choose from. These applications are able to perform basic editing operations such as merging pages, cropping pages, adding comments, and sometimes even providing advanced features. However, not all PDF editors can create PDF forms—that is, editable PDF files with interactive fields that can be filled in by other users. Such documents are useful in situations like you need to create a questionnaire, an admission form, or a sales contract, etc. The following list includes solutions that can run on various Linux distributions,

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool