Application layer---email on the Internet

1. File Transfer Protocol FTP

1.1 Definition

  • Function:
    Early useshare filesprotocol (including uploading and downloading files), the role of FTP servers such as the current Thunder, Baidu, and Cloud Disk

Network administrators maintain FTP servers. The sharer (a user) uploads (uploads) files to share via an FTP client. Other users access this content through FTP clients.

  • Constitute
    user interface, local file interface. The FTP server has a storage hard disk (cloud hard disk) and transfers files between local files and server file directories.

TFTP protocol:

TFTP:TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户机与服务器之间进
          行简单文件传输的协议,提供不复杂、开销不大的文件传输服务。
      TFTP通常用于从TFTP服务器下载或上传文件,
          例如操作系统引导程序、配置文件等。TFTP客户端和TFTP服务器之间的通信是基于UDP协议进行的,端口号为69。
      与FTP协议相比,TFTP协议更加简单和轻量级,但功能较少。TFTP协议不支持用户认证,只能以匿名方式进行文件传输。
      此外,TFTP协议不支持文件目录操作,只能进行文件传输。
      在TFTP协议中,有两种传输模式,分别是读写模式(读写模式)和只读模式(只读模式):
          读写模式:客户端可以从服务器下载文件,也可以向服务器上传文件。
          只读模式:客户端只能从服务器下载文件,不能向服务器上传文件。

      需要注意的是,由于TFTP协议的安全性较低,因此在实际应用中,通常会使用FTP协议来代替TFTP协议。
  • FTP server and client
    Insert image description here

Windows system comes with FTP command

Users can use the FTP command through the following steps:

打开命令提示符。
输入“ftp”并按下回车键,进入FTP模式。
输入FTP服务器的地址,并按照提示进行操作。

It should be noted that when using FTP commands, users need to have certain basic computer knowledge and skills, as well as correct security measures and operating procedures to ensure data security and reliability2

1.2 Work stages

Insert image description hereInsert image description here

establish connection

When FTP客户端向FTP服务器发送连接请求时,FTP服务器会向客户端发送连接应答,建立起FTP控制连接.
Then, the FTP client needs to send the username and password to the FTP server for authentication. If the authentication is successful, operations such as file transfer can be started.

Authentication

User authentication belongs to control connectionThe content is performed after the connection is established. For controlling the connection, see 1.3.1.

  • Enter username and password to log in (FTP server performsUsername and password are transmitted in clear text, which poses a security risk and can be easily intercepted by hackers using packet capture tools)
  • Log in anonymously

Insert image description here

File operation and transfer

After the connection is established, two differentTCP connection, respectively calledcontrol connectionandData Connections.
Instructions are transmitted on the control connection, and file data is transmitted on the data connection.

1.3 FTP control connection and data connection

FTP控制连接与数据连接分开

1.3.1 Control connection

existcontrol connectionsuperior

  • User authentication
    user, password使用的是明文传输

  • The client sends instructions to the server, such as instructions to switch directories, delete, upload, and download files.
    The transmission of data commands is called "out-of-band"

FTP command and response status code explanation example:
Insert image description hereThe lowercase words in the command example in the above figure are variable parameters and specific values. Capitalized words are proper nouns and are fixed.

The RETR (retrieve) instruction is an instruction to download a file from the server and specifies a certain file name.
STOR upload (upload).

上载
下载
客户端
服务器

When the client sends the download file command to the server服务器的使用自己的20号端口主动与客户端建立数据连接

1.3.2 Data connection

existData connection

  • Perform file downloading, uploading (uploading) and other data stream transmission.

The transmission of data takes place over the data connection. Data transfer is called "in-band"

During the FTP data connection process, the client sends an FTP command to the server to tell the server that it needs to transmit or receive data. After receiving the command, the server will use its own port 20 to send a confirmation response to the client. After receiving the response, the client opens a data transfer connection and sends a data connection request to the server. After receiving the request, the server will use its own port 20 to establish a data transfer connection with the client process.

It should be noted that the FTP data connection port is dynamically allocated and is not a fixed port 20. But generally speaking, the data connection port of FTP is port 20, because the FTP protocol stipulates that port 20 is used for data connection.

FTP is a stateful protocol, the server needs to maintain client state.

HTTP transmission is inA TCP connectioncarried out on. The initial design of HTTP wasno statusYes, it can be turned into a stateful protocol through the function of cookies.

Illustration

The specific working process can be seen in the figure below:
Insert image description here

Insert image description here

In computer networks,Stateful and stateless refer to whether the network protocol saves information about the status of the network connection..
A stateless protocol means that the protocol does not save information about the state of the network connection.Stateless protocols do not keep records of previous requests or responses, complete information is required for each request. For example, the HTTP protocol is a stateless protocol. It does not save the request information sent by the client. Each request is independent.
Stateful protocols refer to protocols that save information about the status of network connections.Stateful protocols keep records of previous requests or responses, for subsequent processing. For example, the FTP protocol is a stateful protocol that saves the client's connection status information on the server for subsequent processing.
In computer networks, stateful and stateless protocols each have advantages and disadvantages. Stateless protocols can better support concurrent processing and load balancing because stateless protocols do not save connection state information, making it easier to handle multiple requests. Stateful protocols can better support scenarios where connection state information needs to be saved, such as web applications that need to maintain sessions.
It should be noted that stateful protocols are vulnerable to attacks if not handled properly. For example, anonymous access rights to an FTP server can easily cause the FTP server to be attacked. Therefore, in practical applications, it is necessary to select an appropriate protocol according to the specific situation.

2. Email

2.1 Email Overview

Email is a form of communication using computer networks that can be used to send and receive digital information over the Internet.
The basic components of an email include an email header and an email body. The email header includes the sender, recipient, subject, date and other information. The email body is the main part of the email content and can contain text, pictures, links and other elements.

The process of sending and receiving emails generally requires three steps: the user writes the email and sends it to the sending server, the sending server forwards the email to the transfer server based on the recipient's address, and the transfer server then forwards the email to the final recipient. file server.

The recipient can connect to the receiving server through a client program (such as Outlook, Thunderbird, etc.) and download the email, and then read the email content.
Using email requires setting up protocols such as SMTP and POP3, which stipulate the transmission and reception standards for email.

2.2 Email system structure

Email includes:User agent, mail server, protocol

Email protocols includeSend protocols (SMTP) and pull protocols (POP3, IMAP, HTTP). Since sending and receiving emails are push and pull operations, they can also be called "push" protocols and "pull" protocols.

Sender (User Agent), 发送协议SMTP, Sender Mail Server, SMTP协议, Receiver Mail Server, 拉取协议, Receiver (User Agent).

SMTP is a "push" protocol, where the sender pushes email data to the outgoing message queue of the SMTP server;

HTTPmainIt is a "pull" protocol that pulls files from the server at any time through the browser client. In web browser-based email, the HTTP protocol can also function as the sending protocol.

Insert image description hereInsert image description here

  • Overall workflow

Insert image description here
Insert image description here

2.3 Email message format

Insert image description here

3. Simple Mail Transfer Protocol SMTP

SMTP (Simple Mail Transfer Protocol) is a protocol used for email transmission.

The SMTP protocol defines the communication protocol between the sender and the receiver of the email during the email transmission process, including regulations on the email format, transmission method, authentication mechanism, etc.

3.1 SMTP protocol working

The SMTP protocol workflow is as follows:

TCP three-way handshake.
Send connection request SMTP HELO.
Send sender information SMTP MAIL FROM.
Send recipient information SMTP RCPT TO.
Send email content command SMTP DATA.
Send email content.
Mail transfer completed, SMTP QUIT.

There are some important protocol commands in SMTP, such as:

HELO: The hostname used to identify itself to the receiving server.
MAIL FROM: Used to specify the sender's address.
RCPT TO: Used to specify the recipient's address.
DATA: The SMTP DATA command is used to specify the beginning of the email body and tells the SMTP server to start receiving the email content. DATA should be followed by the email text and end with a single line "."

Key points:

  • C/S: client/server mode
  • TCP connection
  • direct transfer
    Direct transmission from the sending server to the receiving server, without transferring to other servers for storage.
  • The port number
    Use port 25 by defaultMessages are transmitted between the client and the server.
  • communication stage
    • Connection established (handshake)
    • Sending emails (transmitting messages)
    • Connection released (closed)
  • command/response interaction
    • Commands: ASCII text (14 commands, several letters)
    • Response: status code and status information (21 types of response information: three-digit code + simple text description)
  • limit
    • The message must be a 7-bit ASCII code
  • persistent connection
    • A TCP connection can send multiple emails in sequence, and the connection is closed after all are sent.

Insert image description here

3.2 Limitations

Insert image description here

  • SMTP protocol is insufficient: it can only transmit 7-bit ASCII email data, including email headers and bodies. If there is data in the email that has not been ASCII encoded, it will be encoded before transmission. This design was wise in the early days of the Internet, because no one would transmit large data streams such as videos, pictures, etc. in emails.

3.3 Example

Insert image description here

  • Simple SMTP interaction

Insert image description here

Insert image description here

3.4 SMTP format

Insert image description here

3.5 Summary

HTTP is mainly "pull", but it can also be "push".

Insert image description here

4. Post Office Protocol POP3 version 3

POP3 is a very simple email access protocol. When the recipient reads the email, there are disadvantages because SMTP does not support pulling files. The third generation email reading protocol POP3 was born, which is used to send emails from the recipient's SMTP server to the recipient's mailbox.

4.1 Illustration of working position

Insert image description here

4.2 How to work

Insert image description here
POP3 has two working modes: download and retain (retained on the receiving server). This working mode allows multiple clients (such as mobile phones, macs, computers, fax machines, etc.) to download and read.
The download and delete working method only supports downloading once and then deleting it. For example, if you receive an email on your mobile phone, you cannot receive it from the email server on other devices.

POP3 session

Insert image description here

  • concession stage
    User agent sends (plaintext) username and password to authenticate the user.
  • Transaction processing stage
    • User agent returns message
    • Mark the message for deletion and unmark the message for deletion
    • Get email statistics
  • update stage: Appears after the user issues the quit command
    • End POP3 session
    • Delete messages marked for deletion

5. Multimedia extension MIME

Insert image description here
MIME supports encoding non-ASCII bytes and then converting them to ASCII for transmission to SMTP. It is common to base64 encode Chinese characters and then convert them.
Insert image description here

6. Internet Mail Access Protocol IMAP

The POP3 protocol does not provide users with any method to create remote folders and assign folders to messages. In order to solve this problem, the Internet Mail Access Protocol IMAP was created.
Insert image description here

6.1 POP3 and IMAP

Insert image description hereInsert image description here

7. Web-based email

Insert image description here
From the user to the mail server, the HTTP protocol is used, including the sender and receiver.. But 邮件服务器与邮件服务器之间的传输依然是使用SMTP协议.

Guess you like

Origin blog.csdn.net/qq_74259765/article/details/131688124