FTP Server is more common on the Internet, the function of the Linux FTP command is to use the command to control the local and remote computer transfer files, here is a detailed description of the Linux FTP command some of the frequently used commands, I believe that the use of Linux for FTP operations will be very easy.
The general format of the Linux FTP command is as follows:
$ FTP host name/IP
WHERE "hostname/IP" is the host name or IP address of the remote machine you want to connect to. On the command line, the hostname is an option, and if you specify a host name, FTP will attempt to connect to the remote machine's FTP service, and if you do not specify a hostname, FTP will give you a prompt waiting for the user to enter the command:
$ ftp
FTP >
At this point, after entering the open command with the hostname or IP address at the ftp> prompt, you will attempt to connect to the specified host.
Whichever method is used, if the connection succeeds, you need to log on to the remote machine. If the user has an account on the remote machine, they can use the account via FTP and need to provide a password. The read and write permissions of the user account on the remote machine determine what files the user can download on the remote machine and in which directory the uploaded files are placed.
Many FTP sites have special accounts that you can use if you do not have a dedicated login account for the remote machine. The login name for this account is anonymous (also known as anonymous FTP), and when you use this account, you need to enter an email address as your password.
If the remote system provides an anonymous FTP service, users can log in to a special directory for public use by using this service. Typically two directories are available: Pub directory and incoming directory. The pub directory contains all the files that the site uses for public use, and the incoming directory holds files uploaded to that site.
Once the user has successfully logged on to the remote site using FTP, a "ftp>" prompt will be given. You can now freely use the commands provided by FTP, you can use the help command to get a list of available commands, or you can specify a specific command name after the help command to get a description of this command.
The most commonly used commands are:
FTP>ASCII: Set to transfer files in ASCII mode (default value)
Ftp>bell: Every time a file transfer is completed, the alarm prompts.
Ftp>binary: Sets the file to be transferred in binary mode.
Ftp>bye: Terminates the host FTP process and exits the FTP administration mode.
Ftp>case: When on, the file name copied with the Mget command to the local machine, all converted to lowercase letters.
FTP>CD: cd command with UNIX.
Ftp>cdup: Returns to the previous level of the directory.
Ftp>chmod: Changes the file permissions of the remote host.
Ftp>close: Terminates the remote FTP process, returns to the FTP command state, and all macro definitions are deleted.
Ftp>delete: Delete files from the remote host.
Ftp>dir [Remote-directory] [local-file] lists the files in the current remote host directory. If there is a local file, the result is written to a local file.
Ftp>get [Remote-file] [Local-file] is transferred from the remote host to the local host.
ftp>help [command] The interpretation of the output command.
FTP>LCD: Changes the working directory of the current local host and, if default, goes to the home directory of the current user.
Ftp>ls [Remote-directory] [local-file] with Dir.
Ftp>macdef: Defines a macro command.
Ftp>mdelete [Remote-files] Deletes a batch of files.
Ftp>mget [Remote-files] receives a batch of files from the remote host to the local host.
Ftp>mkdir directory-name The directory in the remote host.
Ftp>mput Local-files transfers A batch of files from the local host to the remote host.
Ftp>open host [Port] re-establishes a new connection.
Ftp>prompt: Interactive prompt mode.
Ftp>put Local-file [Remote-file] transfers a local file to the remote host.
FTP>PWD: Lists the current remote host directory.
Ftp>quit: With bye.
FTP>RECV Remote-file [Local-file] with Get.
Ftp>rename [from] [to] changes the file name in the remote host.
Ftp>rmdir directory-name Delete the directory from the remote host.
Ftp>send Local-file [Remote-file] with put.
Ftp>status: Displays the status of the current FTP.
Ftp>system: Displays the remote host system type.
Ftp>user user-name [Password] [account] re-login to the remote host with a different user name.
Ftp>? [command]: With help. [command] To specify the names of the commands that need help. If you do not specify COMMAND,FTP, a list of all commands is displayed.
ftp>! Exit from the FTP subsystem to the shell.
The following is a brief introduction to common FTP commands.
Start an FTP session
The Open command opens a session with a remote host. The general format of the command is:
Open Host name/IP
If you are connecting to more than one site during an FTP session, usually only FTP commands with no parameters are used. If you want to connect to only one computer during the session, specify the remote host name or IP address on the command line as the parameter for the FTP command.
Terminating an FTP session
The close, disconnect, and bye commands are used to terminate a session with a remote machine. The close and Disronnect commands close the connection to the remote machine, but the user is left in the FTP program on the local computer. And the bye command closes the user's connection to the remote machine, and then exits the FTP program on the user's computer.
Change Directory
The CD [directory] command is used to change the directory on the remote machine during an FTP session, and the LCD command changes the local directory so that the user can specify where to find or place the local file.
Remote directory List
The LS command lists the contents of the remote directory as if it were using the LS command in an interactive shell. The general format of the LS command is:
ls [directory] [local file]
If a directory is specified as a parameter, LS lists the contents of the directory. If you give the name of a local file, the directory list is placed in the file you specified on the local machine.
Getting files from a remote system
The Get and Mget commands are used to obtain files from the remote machine. The general format of the GET command is:
Get file name
You can also give the local file name, which is the file name of the file you want to get when it is created on your local machine. If you do not give a local file name, then use the original name of the remote file.
The mget command gets more than one remote file at a time. The general format of the Mget command is:
Mget File Name list
Use a space-delimited list of file names with wildcards or wildcard characters to specify the files to get, and each file in it requires the user to confirm the transfer.
Sending files to a remote system
The put and Mput commands are used to send files to the remote machine. The general format of the put command is:
Put file name
The mput command sends multiple local files at once, and the general format of the Mput command is:
Mput File Name list
Specify the file to send by using a space-delimited list of file names with wildcards or wildcard characters. For each of these files, the user is asked to confirm that they are sent.
Changing the file transfer mode
By default, FTP transfers files in ASCII mode, and users can specify other modes. The function of the ASCII and Brinary commands is to set the mode of transmission. Transferring files in ASCII mode is good for plain text, but in order to avoid the destruction of binary files, users can transfer files in binary mode.
Check transport status
When transferring large files, you may find it useful to have FTP provide feedback about the transport situation. The hash command causes FTP to print a # character on the screen after each transfer of data in the data buffer. This command can be used when sending and receiving files.
Local commands in FTP
When you use FTP, the character "!" Used to route a command to the command shell on the local machine. If the user is in an FTP session, it is useful to have the shell do something. For example, a user would create a directory to hold the received file. If you enter!mkdir New_dir, then Linux creates a directory named New_dir in the user's current local directory.
1. FTP automatically log in to bulk download files.
# # # # # # #从ftp服务器上的/home/data to the local/home/databackup####
#!/bin/bash
ftp-n<
Open 192.168.1.100
User Ftp01 Password
Binary
Cd/home/data
Lcd/home/databackup
Prompt
Mget *
Close
Bye
!
2. FTP automatically log in to upload files.
# # # #本地的/home/data#### on/home/databackup to FTP server
#!/bin/bash
ftp-n<
Open 192.168.1.100
User Ftp01 Password
Binary
Hash
Cd/home/data
Lcd/home/databackup
Prompt
Mput *
Close
Bye
!
3. FTP automatic login to download a single file.
# # # #ftp服务器上下载/home/data/a.sh to local/home/databackup####
#!/bin/bash
ftp-n<
Open 192.168.1.100
User Ftp01 Password
Binary
Cd/home/data
Lcd/home/databackup
Prompt
Get a.sh a.sh
Close
Bye
!
4. FTP automatic login to upload a single file.
# # # #把本地/home/databachup/a.sh up Ftp/home/databackup # # # #
#!/bin/bash
ftp-n<
Open 192.168.1.100
User Ftp01 Password
Binary
Cd/home/data
Lcd/home/databackup
Prompt
Put a.sh a.sh
Close
Bye
!
Small knowledge:
1.-N is not affected by the. netrc file. (FTP defaults to read the settings in the. netrc file)
2. << is using instant file redirection input.
3.! is the instant file flag it must appear in pairs to identify the start and end of the instant file.
FTP Server for Linux