FTP File Transfer Protocol and command

Source: Internet
Author: User
Tags ftp commands ftp file ftp client file transfer protocol ftp file transfer ftp file transfer protocol how to use ftp runique

Http://course.cug.edu.cn/netinfo/Chapter06/6.6.3.1.htm
File Transfer Protocol (FTP) is an online service similar to telnet. Allows users to obtain a copy of a file from a remote computer and transmit it to a local computer or a copy of the file on the local computer to the remote computer. Similarly, the remote computer requires the user's account and password for file transfer. However, many FTP servers on the Internet provide free software and information. users do not log on with an anonymous FTP service.

FTP adopts the "Client/Server" working mode. The client must arrange FTP client programs on its own computer. You can use ftp to transfer any types of files, such as text files, binary files, audio files, image files, and data compression files.

FTP is used to copy data between two computers. Copying a file from a remote computer to your computer is called a "Download" file. If you copy a file from your computer to a remote computer, it is called an upload file.

There are two FTP transmission modes: ASCII transmission mode and binary data transmission mode.

1. ASCII Transmission Mode

Assume that the file being copied contains simple ASCII code text. If the file running on a remote machine is not UNIX, during file transfer, FTP usually automatically adjusts the content of the file so that the file can be interpreted as another computer that stores the text file format.

However, in this case, the files being transferred by the user are not text files, they may be programs, databases, word processing files or compressed files (although most of the word processing files contain text, it also contains non-printable characters indicating the page size and font information ). Before copying any non-text files, use the Binary command to tell FTP to copy them verbatim. Do not process these files. This is also the binary transfer to be discussed below.

2. binary transmission mode

During binary transmission, the file order is saved so that the original and copied files are one-to-one. Even if the destination machine contains files with bit sequences, it makes no sense. For example, if a Macintosh transfers an executable file to an ibm vm System in binary mode, the file cannot be executed on the other system. (However, it can be executed by copying binary data from the VM system to another Macintosh ).

If you transfer a binary file in ASCII mode, the translation will still be translated even if you do not need it. This slows down the transmission, damages the data, and makes the file unusable. (On most computers, the ASCII mode generally assumes that the first valid bit of each character is meaningless, because it is not used for the combination of ASCII characters. If you transmit binary files, all bits are important .) If you know that the two machines are the same, the binary method is effective for text files and data files.

 

 

1. Connection Method

First, we will consider how to transfer files between two machines with an existing account. When you run an FTP client program on your local system, FTP requires you to specify the machine on which files will be exchanged, just like Telnet. This can be done using the following command:

% FTP remote-machine-name <Remote Host Name>

This starts the FTP program and connects it to the machine with this name. When some systems cannot process some domain name addresses, you can use the IP address, as described in 202.114.200.254. A remote machine is a host on the internet, regardless of whether the operating system is UNIX, IBM/Vm, machizer, or dossystem.

When FTP is connected to a remote computer, you will be asked to confirm with the registration name and password:

% FTP dns.cug.edu.cn connected to dns.cug.edu.cn

Connected to DNS.

220 dns ftp Server (Unix (r) System V Release 4.0) ready.

Name (DNS: Zhangfeng): Zhangfeng type the user name

331 Password required for Zhangfeng.

Password: ***** enter the password

230 user Zhangfeng logged in.

2. Main FTP Functions

FTP commands can be classified as: transferring a single file, browsing, changing directories, transferring multiple files, and setting the mode.

(1) transfer a single file

Ftp transfers files in two directions. It can take a file from the local machine to send it to the remote machine, or take a file from the remote machine to put it on the local machine. This can be implemented by the get and put commands.

① GET command

Get is to get the files on the remote host to the local machine, in the following format:

Ftp> Get source-file destination-File

Source-file is the name of the file to be copied, and destination-file is the name of the file to be copied. The destination-file name is arbitrary. If it is omitted, the copied name will be the same-source file name.

Ftp> get comments: Obtain the comments file from the remote machine FTP to the local machine DNS

200 PORT command successful.

150 ASC data connection for comments.

226 ASC transfer complete.

1634 bytes recieved in 0.052 seconds (30 Kbytes/s)

In the above example, apart from the input information, FTP provides a lot of information, all information starts with a number, to achieve interactive sessions with users. After each transmission, FTP tells you what it is transmitting and what its large and average transmission rate is. The transmission rate varies depending on the machine used and the network router used.

② PUT command

Put is to send a local file to a remote machine in the same format as the GET command:

Ftp> put source-life destination-File

To send the newversion file on the local (Tech) to the remote (FTP) machine and change the name to readthis, you can do the following:

Ftp> put newversion readth transfers newversion from the local machine's DNS to FTP, and the name is changed to readthis

200 PORT command successful.

150 ASC data connection for comments.

226 ASC transfer complete.

62757 bytes sent in 0.22 seconds (2.8e + 02 Kbytes)

Ftp> quit end session

221 goodbye.

In this example, the quit command is used to exit the FTP program and return to the original UNIX system. The bye command plays the same role. In addition, if you misspell the name of the file to be transferred, or the file does not exist, you will get the "No such file or firectory" information or the equivalent information. In this case, enter the command again and enter its name correctly.

(2) browsing on a remote machine

① Dir command

When using FTP, you often do not know exactly what file names you want and where they are located. Therefore, you need to browse to find the files to be transmitted, this can be done using the Dir command in the following format:

Ftp> dir directory-name local-file-name

The dir command lists complete information:

Ftp> dir

200 PORT command successful.

150 ASCII data connection for/bin/LS (202.114.200.254, 54860) (0 bytes ).

Total 44

Drwxr-XR-x 2 zhangfen other 7168 Jun 25 1996 Bin
Drwxr-XR-x 2 zhangfen other 3072 Jun 25 1996 etc
Drwxrwxrwx 2 zhangfen users 512 Jun 13 1996 etc. Mail. Files
Drwxrwxrwx 3 zhangfen users 512 Jun 13 1996 etc. Named
-RW-r -- 1 root other 3793 Jan 12 tess.html

226 ASCII transfer complete.

644 bytes encoded ed in 0.058 seconds (11 Kbytes/s)

② LS command

The format of the 1 s command is the same as that of the Dir command:

Ftp> ls directory-name local-file-name

The two variables are the same as those of Dir. The results listed by the 1 s command are very different from those listed by the Dir command. The default LS command is used to list only the file names without any information:

Ftp> ls

200 PORT command successful.

150 ASCII data connection for/bin/LS (202.114.200.254, 54859) (0 bytes ).

Bin
Etc
Etc. Mail. Files
Etc. Named
Tess.html

226 ASCII transfer complete.

94 bytes encoded ed in 0.045 seconds (2 Kbytes/s)

(3) Change and view the Directory

The Dir and 1 s commands only list files in the current directory. to view files in other directories, you must change the directory first. Two sets of directories are involved in FTP: The registered local directory and the directory of the remote machine connected to FTP (remote directory). To change the directory on the remote host, run the following command:

Ftp> Cd directory

The command works the same way as the CD command in shell. The difference is that it is only valid on the remote machine. These can be summarized as follows:

* If no directory is specified, CD allows you to return to the default directory you registered.

* If this directory starts with "/", it will be moved to the specified directory regardless of your current location (absolute location.

* If the directory is..., it will move up the level in the current directory.

* If the directory starts with an alphanumeric character, it treats the directory as the current subdirectory.

If you cannot determine the current directory, run the PWD command to view your location. The format is as follows:

Ftp> pwd

When sending and obtaining files, you also need to change the local directory to find the directory where the files to be sent are located and the directory where the obtained files are stored. You can use the LCD command to complete the process:

Ftp> LCD directory

The LCD command rules are the same as those for Unix CD commands.

(4) Multi-file transmission

We have discussed get and put commands. Only one file can be transferred at a time. Sometimes, if you want to transmit multiple files at a time, you can use the mput and mget commands. The format is as follows:

Ftp> mput list of source-files (File Name List)

Ftp> mget list of source-files (File Name List)

The mput command transfers the listed files to the remote system, and the mget command transfers the files from the remote system to the local system. In both cases, the file names in the local and remote systems are the same. The table listed in the file can be of any length and can contain a matching character. The actual rules on how to expand a match character are more complex than those on FTP files. Generally, you can use * to match 0 or more characters, regardless of the complexity. In UNIX, are you available? To match any single character. In other systems, you must do some practice or read the document carefully to see what is legal.

The following is an example of using mget and mput.

Ftp> mget 1 * transfers documents starting with 1

Mget 11? Y: Indicates whether to download the document named 11. If yes, Type Y. Otherwise, type N.

200 PORT command successful. Command executed successfully

150 opening ASC mode data connection for 1l (183 bytes). ASCII Transmission Mode

226 transfer complete. Transmission completed

190 bytes encoded ed in 0.0031 seconds (60 Kbytes/s) indicates the time and transmission rate of the number of bytes transmitted.

Mget 12? N no download

Mget 13? N no download

Ftp> mput file2 file3

Mput file2? Y

200 PORT command successful.

150 opening ASC mode data connection for file2.

226 transfer complete.

12106 bytes sent in 0.047 seconds (2.5 + 02 Kbytes/s)

Mput file3? Y

200 PORT command successful.

150 opening ASC mode data connection for file3.

226 transfer complete.

12481 bytes sent in 0.079 seconds (1.5e + 02 Kbytes/s)

 

6.6.3.2 FTP command Summary
Life order Release
ASCII Enter the ASCII mode, which is used to transmit text files.
Binary The binary mode is used to transmit binary files.
CD Change the working directory of the remote machine.
Close End the FTP session with the remote machine and return the FTP command status. After close is used, you can connect to a new system or exit from ftp.
Delete filename Delete the batch name files in the remote system.
Dir file destination List all directories on the remote machine. File and destination are optional. file can be a single file or contain "?" And. List all objects that meet the specified conditions. If file is omitted, all files in the current directory are listed. Destination is the place where the input should be placed. It can be a file on a local machine or a command to filter files. If it is omitted, it will be displayed on the terminal.
Hash When you use the get or PUT command to send a data block each time, let the FTP display #. When transferring large files, if you are not sure whether the network is working or not, you will be given a visible signal to determine whether the data is being transmitted. If FTP displays this signal, the Hash command cancels the signal.
Help Command A short help text about this command is displayed.
LCD directory Change the default directory to the specified directory on the local machine.
Ls List A short directory on a remote machine with the same parameters as dir.
Mget file-list Obtain multiple files from a remote machine. File-list can be a column of names separated by spaces. "*" That expresses arbitrary files and "?" That expresses anything at this location .
Mput file-list Transfers multiple files to a remote machine. File-list is a list of file names separated by a space, or "*" or "?" is used. .
Open Connect to the machine with the specified name. It is useful if you want to connect to a new system after uploading a file from a system. You must first close the original connection.
Prompt When using mget or mput, the prompt command prompts you to confirm before ftp transfers each file. This is useful when you are sure that transferring or overwriting existing files is unnecessary. If you have started the prompt when issuing the prompt command, FTP will turn off the prompt. When all files are transmitted, no questions will be asked.
PWD Displays the name of the Remote Current directory.
Quit Exit FTP and close all connections currently open.
User Send the user name to the remote machine for Logon. It is useful when you do not enter the user name and password correctly. You do not need to close the current connection and create a new connection. You can run the USER command to try again.
! In Unix systems, when running FTP, run "!" directly without exiting FTP. The Unix Command.
CTRL + c Interrupt the FTP command.

 

The following are commonly used commands for logging:

Open [host_name]: establishes a connection with a local host.

Close

Close

Bye or quit: end with the connection between the client host and the ftp

CTRL-C: medium volume FTP

Get rfile [lfile]: retrieve the hosts file

Put lfile [rfile] Or send lfile [rfile]: The producer sends the transfer case to the receiver's host.

Mget rfile [lfile]

Mput lfile [rfile]: sends multiple cases to the terminal host at a time, with wildcard characters available.

PWD: displays the current status of the client host.

LCD ldir: changes the work of local hosts

CD rdir: changes the Working Scope of the terminal host

Ls [rdir]: displays the working content of the client host.

Dir [rdir]: displays the internal content of the master machine.

Dir [rdir]: displays the internal content of the master machine.

ASCII: sets the encoding type to ASCII.

Binary: sets the Protocol encoding type to binary.

Prompt: determines whether to notify the user of the response when mget mput is used.

! Lcommand: run the commands of the local host machine.

(Above lfile-> local file, ldir-> local directory, lcommand-> local command
Rfile-> remote file, rdir-> remote directory)

 

Top

   

 

  • Send Short Message
  • Add as a friend

Elders
Offline

Elders

Post
1649
Excellent
1
Points
10
Read Permission
200
Last login

Administrator

5#


EldersPublished on|
View the author only
If you want to learn how to use ftp for background download, you must learn FTP commands.
The FTP command line format is: ftp-v-d-I-n-g [host name],

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

-N: Restrict FTP automatic logon, that is, do not use;. 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 the 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 a 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, if ntrans1r is used, the file name lll is changed 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 file name to only one-level storage. If the file exists, add the suffix. 1,. 2 and so on 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 only one (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, the detailed report mode is set. All the alarms on the FTP server are displayed to the user. The default value is on.

73 .? [Cmd]: Same

 

 

 

 

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.