FTP (file transfer protocol) plays an important role in many network applications. Software resources are a very important resource in the Internet, and most of the various software resources are stored on the FTP server. Like most Internet services, FTP is also a client/server system. You can use a client program that supports the FTP protocol to connect to the FTP server program on the host. The user sends commands to the server program through the client program. The server program executes the commands issued by the user and returns the execution results to the client.
The FTP service can be divided into two types based on different service objects: The system FTP Server can only be used by legal users on the system; the Anonymous FTP Server (Anonymous FTP Server) allow anyone to log on to the FTP server to obtain files.
The FTP data transmission mode is divided into three modes for FTP data connection: Active Transmission Mode, passive transmission mode, and single-port transmission mode.
1. Active Transmission Mode
When the FTP control connection is established and the customer proposes a directory list and transfers files, the client issues The PORT command to negotiate with the server, the FTP server uses a standard Port 20 as the server's data connection port (ftp-data) to establish a data connection with the customer. Port 20 is only used to connect the source address to the server, and Port 20 does not listen to the process to listen to customer requests.
In active transmission mode, the FTP data connection and control connection are in the opposite direction. The server initiates a connection for data transmission to the client. The client connection port is determined by the server and the client through negotiation.
2. Passive Transmission Mode
When the FTP control connection is established and the customer proposes a directory list and transfers files, the client sends the PASV command to make the server in passive transmission mode, and the FTP server waits for the customer to contact it. The FTP server listens to customer requests on other non-20 data transmission ports.
In passive transmission mode, the FTP data connection and the control connection direction are the same, and the client initiates a connection for data transmission to the server. The client connection port is the port used to initiate the data connection request. When an FTP client accesses an FTP server outside the firewall, it must use the passive transmission mode.
3. Single Port Mode
In addition to the above two modes, there is also a single port mode. Data connection requests in this mode are initiated by the FTP server. When this transmission mode is used, the control connection port of the client is the same as the data connection port. This mode is not commonly used because it cannot input data or transmit commands continuously in a short period of time.
Linux has a lot of available FTP servers, among which popular are WU-FTP (Washington University FTP) and VSFTP. Red Hat 8.0 comes with both WU-FTP and VSFTP software. WU-FTP is a famous FTP server software, which is powerful and can run well in many Unix operating systems. However, VSFTP is becoming more and more popular as a rising star, and only VSFTP is available in Red Hat 9.0 release.
In VSFTP, VS indicates "Very Secure ". From the name, we can see that from the very beginning, software writers have paid great attention to their security. In addition to inherent security, VSFTP also features high-speed and stable performance. In terms of stability, VSFTP supports simultaneous connection of more than 4000 concurrent users on a single machine (non-cluster. According to ftp.redhat.com, VSFTP supports up to 15000 concurrent users.
Quickly build an FTP server
The basic function implemented by the FTP server is upload and download. The following describes several steps to build a simple FTP server that can implement the download function.
1. Install the FTP server
If you do not select to install the FTP server when installing the system, you can install it using the "Add/delete application" tool in Red Hat 9.0. Select "Main Menu"> "system settings"> "Add/delete application", select the FTP server on the displayed page, and click "Update.
If you cannot confirm whether the software is installed, run the following command:
#rpm -qa|grep vsftpdvsftpd-1.1.3-8
|
2. Start the FTP server
Use the default example of Red Hat 9.0 to directly start VSFTP.
#/Sbin/service vsftpd start
Start vsftpd For vsftpd: [OK]
3.Create a file named test.txt in the/var/ftp/pubdirectory with the content "This is a test file ".
4. Test
Log on to the local server using the FTP client, and then log on with an anonymous identity (anonymous:
# ftp 127.0.0.1Connected to 127.0.0.1 (127.0.0.1).220 (vsFTPd 1.1.3)Name (127.0.0.1:root): anonymous331 Please specify the password.Password:230 Login successful. Have fun.Remote system type is UNIX.Using binary mode to transfer files.
|
In this way, you can successfully log on to the FTP server. The server directory list is displayed as follows:
ftp> ls227 Entering Passive Mode (127,0,0,1,63,15)150 Here comes the directory listing.drwxr-xr-x 2 0 0 4096 Dec 04 01:35 pub226 Directory send OK.
|
Switch to the pubdirectory and display the directory content. You can find the created file test.txt:
ftp> cd pub250 Directory successfully changed.ftp> ls227 Entering Passive Mode (127,0,0,1,232,34)150 Here comes the directory listing.-rw-r--r-- 1 0 0 21 Dec 04 01:35 test.txt226 Directory send OK.
|
Download the test.txt file:
ftp> mget test.txtmget test.txt? y227 Entering Passive Mode (127,0,0,1,186,210)150 Opening BINARY mode data connection for test.txt (21 bytes).226 File send OK.21 bytes received in 0.0108 secs (1.9 Kbytes/sec)
|
In the local directory, you can see that test.txt has been successfully downloaded to the local machine.
ftp> !lsa EIO_Binders initrd mnt proc tftpboot ylg.txtbin etc lib mymnt root tmpboot home lost+found myshare sbin usrdev id_dsas.pub misc opt test.txt var
|
After trying to upload the file named ylg.txt, you can see that the request is rejected.
ftp> put ylg.txtlocal: ylg.txt remote: ylg.txt227 Entering Passive Mode (127,0,0,1,243,10)550 Permission denied.
|
Log out:
The test shows that files can be downloaded, but files cannot be uploaded (or directories and files cannot be created on the server ). In fact, this is an anonymous FTP server dedicated to providing download services.
From the above steps, we can see that a simple FTP server can be set up without any configuration. This is because Red Hat has configured a default FTP server. However, in most cases, this simple server cannot meet your needs.