Principles and commands of FTP

Source: Internet
Author: User
Tags ftp commands ftp file remote ftp server ftp client file transfer protocol ftp file transfer ftp protocol runique

FTP description:

FTP is short for file transfer protocol. It refers to the file transfer protocol. The main function is to complete the file copy from one system to another. Like HTTP, HTTP is a widely used protocol on the Internet. The FTP protocol uses two TCP connections. One is the command link used to transmit commands between the FTP client and the server, and the other is the data link used to upload or download data.

============= First understanding ========

The FTP protocol can work in two ways: Port and PASV. The Chinese meaning is active and passive.

The active connection process is that the client sends a connection request to the FTP port of the server (21 by default). The server accepts the connection and establishes a command link. When data needs to be transmitted, the client uses the PORT command on the command link to tell the server: "I opened port XXXX and you came to connect to me ". The server sends a connection request from Port 20 to port XXXX of the client and establishes a data link to transmit data.

PASV (passive) connection process: the client sends a connection request to the FTP port of the server (21 by default). The server accepts the connection and establishes a command link. When data needs to be transmitted, the server uses the PASV command on the command link to tell the client: "I opened port XXXX, and you came to connect to me ". Therefore, the client sends a connection request to port XXXX of the server and establishes a data link to transmit data.

=========== Second understanding =======

An FTP session contains two channels: a control channel and a data channel.

Control CHannel: The control channel is a channel for communication with the FTP server. It connects to FTP and sends FTP commands through the control channel.

Data Channel: The data channel is a channel for file transfer or list with the FTP server.

In the FTP protocol, the control connection is initiated by a client, and the data connection works in two ways: Port and PASV.

 

Port mode (active mode)

The FTP client first establishes a connection with the TCP port 21 of the FTP server and sends commands through this channel. When the client needs to receive data, it sends the PORT command through this channel. The PORT command contains the port used by the client (a port greater than 1024) to receive data. When transmitting data, the server sends data through its TCP port 20. The FTP server must establish a new connection with the client to transmit data.

PASV mode (passive mode)

The port mode is similar when a control channel is set up. When the client sends the PASV command through this channel, the FTP Server opens a random port greater than 1024 and notifies the client to send data requests on this port. Then, the FTP Server transfers data through this port, at this time, the FTP server no longer needs to establish a new connection with the client to transfer data.

 

In Port mode, the data transmission channel is initiated by the server. The server uses Port 20 to connect to a port greater than 1024 of the client. In PASV mode, the establishment of the data transmission channel is initiated by the FTP client. It uses a port greater than 1024 to connect to a port greater than 1024 of the server.
From the perspective of the C/S model, port is outbound for the server, while PASV mode is inbound for the server.

FTP Operating Principle

 FTP works in the same way as many other network utilities, and is also based on the customer-server mode. The file transfer protocol (FTP) standard is described in R f c 9 5 9. This Protocol defines a standard for transferring files between a remote computer system and a local computer system. Generally, users who want to transfer files must first pass authentication before they can log on to the f t p server and access the files on the remote server. Most f t p servers usually provide an anonymoust Public Account to allow users without an f t p server account to access the f t p server. An f t p session usually includes interaction of five software elements, 1. The model has not changed since 1973.

Figure 1 FTP protocol model

The following table lists the interaction elements.

In an ft p session, two independent network connections exist. One is used by p I at both ends, and the other is used by DTP at both ends. A connection between Pi is generally called a control connection, and a connection between d t p is called a data connection ). Normally, the FTP server listens to Port 2 1 to wait for the control connection to establish a request. When the client connection request arrives, a control connection is established between the client and the FTP server. The selection of the Data Connection port number depends on the command used to control the connection, generally, the customer sends a control message to specify that the customer needs to establish a data connection to transmit f t p data (such as downloading/uploading a file, displaying the content of the current directory, and so on, you must establish a data connection to transmit data). In this message, the port number of the client listening and waiting for the connection is specified, and the server receives the command from the control connection, the client initiates a connection request to the specified port number in the message. After receiving the request, the client establishes a data connection. After the connection is established, the server or customer will send data through the connection (it may be the file to be transmitted or the LS command output from the command line ).

Two types of connections are required for a complete FTP file transfer. One is a file transfer command called a control connection, and the other is a real file transfer called a data connection.

1) control connection

When the client wants to establish an upload/download data transmission with the FTP server, it first initiates a connection establishment request to the TCP port 21 of the server. The FTP Server accepts requests from the client, after the connection is established, the connection is called an FTP control connection.

2) Data Connection

After the FTP control connection is established, you can start transferring files. The file transfer connection is called an FTP data connection. FTP data connection is the process of FTP data transmission. It has two transmission modes: active and passive ). See figure 2.

Figure 2 active and passive Modes

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. In active transmission mode, the FTP server uses Port 20 to connect to the temporary port of the client and transmit data. The client is only in the receiving status.

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. In passive transmission mode, the FTP Server opens a transient port and waits for the client to connect to it and transmit data. The server does not participate in active data transmission, but passively accepts the data.

FTP commands

FTP commands are one of the most frequently used commands by Internet users. A large number of internal FTP commands are used in both dos and UNIX operating systems. Familiar with and flexible application of FTP Internal commands can greatly facilitate users and get twice the result with half the effort.

The command line format of FTP is: ftp-v-d-I-n-g [host name], where

-V: displays all the response information of the remote server;

-N indicates that FTP automatic logon is disabled;

. N etrc file;

-D. Use the debugging method;

-G cancels the global file name.

The internal commands used by FTP are as follows (brackets indicate optional ):

1 .! [Cmd [ARGs]: Execute the interactive shell on the local machine and exit to return to the FTP environment, for example :! Ls *. Zip.

2. $ macro-Ame [ARGs]: Execute macro to define macro-name.

3. Account [Password]: Provide the supplemental Password required to access system resources after logging on to the remote system.

4. append local-file [Remote-file]: append the local file to the remote system host. If the remote system file name is not specified, the local file name is used.

5. ASCII: Use the ASCII type transmission method.

6. Bell: after each command is executed, the computer rings once.

7. Bin: Binary File Transfer Mode.

8. Bye: exit the FTP session.

9. Case: when using mget, convert uppercase letters in the remote host file name to lowercase letters.

10. CD remote-Dir: Enter the remote host directory.

11. cdup: Enter the parent directory of the remote host directory.

12. chmod mode file-Name: Set the file-name access mode of the remote host file to mode, for example, chmod 777 A. Out.

13. Close: interrupt the FTP session with the remote server (corresponding to open ).

14. Cr: When a file is transmitted using asscii, the carriage return line is converted into a return line.

15. Delete remote-file: delete remote host files.

16. debug [debug-value]: sets the debugging mode. Each Command sent to the remote host is displayed, for example, Deb up 3. If it is set to 0, the debug is canceled.

17. dir [Remote-Dir] [local-file]: displays the remote host directory and saves the result to the local file.

18. Disconnection: Same as close.

19. Form Format: sets the file transmission mode to format. The default mode is file.

20. Get remote-file [local-file]: transfers the remote-file of the remote host to the local-file of the local hard disk.

21. glob: Set the extension of the mdelete, mget, and mput file names, which is the same as the-G parameter in the command line.

22. Hash: A hash symbol (#) is displayed for every 1024 bytes transferred (#).

23. Help [cmd]: displays the help information of the FTP Internal Command cmd, for example, help get.

24. idle [seconds]: Set the Sleep timer of the remote server to [seconds] seconds.

25. Image: sets the binary transmission mode (the same as binary ).

26. LCD [dir]: Switch the local working directory to Dir.

27. ls [Remote-Dir] [local-file]: displays the remote Directory Remote-Dir and stores the local-file.

28. macdef macro-Name: defines a macro. When an empty row under macdef is encountered, the macro definition ends.

29. mdelete [Remote-file]: delete remote host files.

30. mdir remote-files local-file: similar to Dir, but multiple remote files can be specified, such as: mdir *. O. *. zipoutfile

31. mget remote-Files: Transfers multiple remote files.

32. mkdir Dir-Name: create a directory on the remote host.

33. MLS remote-File Local-file: Same as NLIST, but multiple file names can be specified.

34. mode [modename]: sets the file transmission mode to modename. The default mode is stream.

35. modtime file-Name: displays the last modification time of the remote host file.

36. mput local-file: Transfers multiple files to the remote host.

37. Newer file-Name: if the modification time of file-name on the remote machine is closer than that of files with the same name on the local hard disk, the file will be re-transmitted.

38. NLIST [Remote-Dir] [local-file]: displays the list of files in the remote host directory and stores the local-file on the local hard disk.

39. NMAP [inpattern outpattern]: sets the file name ing mechanism so that some characters in the file are converted to each other during file transmission, such as NMAP $1. $2. $3 [$1, $2]. [$2, $3], transfer the file a1.a2. when A3, the file name is changed to a1, a2. This command is especially applicable when the remote host is not a unix host.

40. ntrans [inchars [outchars]: sets the file name character translation mechanism, for example, ntrans 1R, then the file name lll will change to Rrr.

41. Open host [port]: Specifies the FTP server connection. You can specify the connection port.

42. Passive: enters the passive transmission mode.

43. Prompt: Set interaction prompts when multiple files are transferred.

44. Proxy FTP-cmd: Execute an FTP command in the secondary control connection. This command allows two FTP servers to be connected to transfer files between the two servers. The first FTP command must be open to first establish a connection between two servers.

45. put local-file [Remote-file]: transfers the local-file to the remote host.

46. pwd: displays the current working directory of the remote host.

47. Quit: Same as bye, quit the FTP session.

48. Quote arg1, arg2. ..: Send the parameter to the remote FTP server, for example, quote syst.

49. Recv remote-file [local-file]: Same as get.

50. reget remote-file [local-file]: similar to get. However, if local-file exists, it will be resumed from the last transmission interruption.

51. rhelp [cmd-name]: request for help from the remote host.

52. rstatus [file-name]: If no file name is specified, the remote host status is displayed; otherwise, the file status is displayed.

53. RENAME [from] [to]: Change the remote host file name.

54. Reset: Clear the answer queue.

55. Restart marker: Start get or put again from the specified mark marker, for example, restart 130.

56. rmdir Dir-Name: Delete the remote host directory.

57. runique: Set the unique storage of file names. If the file exists, add the suffix... 1 and. 2 after the original file.

58. Send local-file [Remote-file]: Same as put.

59. sendport: Set the PORT command.

60. Site arg1, arg2. ..: Send the parameter to the remote FTP host as the site command.

61. Size file-Name: displays the file size of the remote host, for example, site idle 7200.

62. Status: displays the current FTP status.

63. struct [struct-name]: sets the file transmission structure to struct-name, and uses the stream structure due to lack of time.

64. sunique: Set the remote host file name storage to unique (corresponding to runique ).

65. System: displays the operating system type of the remote host.

66. tenex: Set the file transfer type to the required type of the tenex server.

67. Tick: sets the byte counter during transmission.

68. Trace: Set package tracing.

69. Type [type-name]: sets the file transfer type to type-name. The default value is ASCII, for example, Type Binary. Sets the binary transfer mode.

70. umask [newmask]: Set the default umask of the remote server to newmask, for example, umask 3.

71. User user-name [Password] [account]: indicates your identity to the remote host. If you need a password, enter the password, for example, USER anonymous my @ email.

72. verbose: Same as the-V parameter of the command line, that is, set the detailed report mode. All responses of the FTP server will be displayed to the user. The default value is on.

73 .? [Cmd]: Same as help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.