Summary of using lftp in linux (remote server backup)

Source: Internet
Author: User
Tags openssl library
When solving a remote server backup problem today, I used lftp-related knowledge and sorted it out as follows. For more information, see

I used lftp to solve a remote server backup problem today. As follows:

Lftp is more powerful, which is much easier than ftp.

1. login:

Lftp ftp: // yourname @ site

Pwd :*****

Or open ftp: // yourname @ site

2. basic operations (transfer)

Lftp usage
Lftp is a powerful download tool that supports file access protocols: ftp, ftps, http, https, hftp, and fish. (ftps and https must include the openssl library during compilation ). The llftp interface has a shell: it has command completion, history records, and allows multiple background tasks to be executed. it is very convenient to use. It also provides functions such as bookmarks, queues, images, resumable data transfer, and multi-process download.
Command line syntax
To view the command line syntax of lftp, you only need to input lftp -- help in the shell.
Lftp [OPTS]
'Lftp 'is the first command executed by lftp after the rc file is executed.
-F: execute the command in the file and exit.
-C: exit after executing the command
-- Help: displays help information and exits.
-- Exit after lftp version is displayed
Other options are the same as the 'open' command.
-E: execute the command after selection.
-U [,] use the specified user name/password for verification
-P: connection to the specified port
Host name, URL or bookmarkname
If you enter the site name in the command line, lftp will directly log on to the site, such
$ Lftp ftp ://.............
If you do not enter the site name in the command line, you must use the open command to open the site after entering the lftp interface.
[Yhj @ ccse-yhj] $ lftp
Lftp: ~> Open ftp ://...................
Common Commands
* Download a single file and a group of files, and use the-c parameter for resumable Upload.
Lftp ......:/> get-c ls-lR.txt
Lftp ......:/> mget *. txt
* An image (an image is uploaded) is a directory. you can use multiple threads to concurrently mirror a directory (-- parallel = N)
Lftp ......:/> mirror incoming local_name
Lftp ......:/> mirror-R local_name
Lftp ......:/> mirror -- parallel = 3 incoming local_name
* Multi-threaded download, similar to the functions of network Ant Financial. the default value is 5 threads.
Lftp ......:/> pget-n 4 ls-lR.txt
* Background task management
By default, press Ctrl + z to convert the task being executed to the background. you can also add the & symbol at the end of the command line to execute the task in the background. Run the jobs command to view all background processes. You can use the queue command to queue new tasks. If you exit lftp and execute tasks in the background, lftp will be executed in the background.
* Other usage
Running
Lftp ......:/> du incoming> ls.txt
Related Files
/Etc/lftp. conf
The actual location of the global configuration file depends on the Directory of the system configuration file, which may be in/etc or/usr/local/etc.
~ /. Lftp/rc ,~ /. Lftprc
The user configuration file will be executed after/etc/lftp. conf, so the above settings will overwrite the settings in/etc/lftp. conf.
By default, lftp does not display the ftp server's welcome information and error information, which is inconvenient in many cases, because you may want to know whether the server is unable to connect to the server because it is not powered on or the number of connections is full. If so, you can ~ /. Write a row in lftprc
Debug 3
The error message is displayed.
For more configuration options, see the man manual or use the set-a command on the lftp interface.
~ /. Lftp/log
When lftp is switched to the background non-suspended mode for execution, the output will be redirected here
~ /. Lftp/bookmarks
This is where lftp stores bookmarks. you can use lftp to view the bookmark command.
~ /. Lftp/cwd_history
This file is used to store the working directory of the Accessed site

~ /. Lftprc
When using lftp to access some ftp servers in China, Chinese characters are often garbled.
Pai_^ don't worry, because the server and local code are inconsistent. We only need to create a new file in the main directory ~ /. Lftprc or ~ /. Lftp/rc
Add the following content:
Debug 3 set ftp: charset GBKset file: charset UTF-8 # set ftp: passtive-mode no # alias utf8 "set ftp: charset UTF-8" # alias gbk "set ftp: charset GBK"
Log on to the ftp server
Let's take a look at how to log on to the ftp server.
Lftp ftp: // user: password @ site: port
Lftp user: password @ site: port
Lftp site-p port-u user, password
Lftp site: port-u user, password
The above methods work normally, but the passwords are in plain text, which seems insecure. No.
Lftp user @ site: port
The system will prompt you to enter the password, and the password will be displayed ***
However, it is troublesome to input so much data each time. If there is a site manager similar to leapftp, lftp has long wondered: this is bookmark. We will see it later.
Common Commands
Run on the terminal
Man lftp
Or enter
Help
The command list is displayed.
Let's take a look at common commands of lftp:
Ls
Display the remote file list (! Ls to display the local file list ).
Cd
Switch the remote directory (LCD switches to the local directory ).
Get
Download remote files.
Mget
Download a Remote File (wildcard * can be used *).
Pget
Use multiple threads to download remote files. the default value is five.
Mirror
Download/upload (mirror-R)/synchronize the entire directory.
Put
Upload a file.
Mput
Upload multiple files (wildcards are supported ).
Mv
Move the remote file (rename the remote file ).
Rm
Delete a remote file.
Mrm
Delete multiple remote files (wildcards are supported ).
Mkdir
Create a remote directory.
Rmdir
Delete the remote directory.
Pwd
Displays the current remote directory (lpwd displays the local directory ).
Du
Calculate the size of the remote directory
!
Run the local shell command (because lftp does not have lls, it is available! Ls to replace)
LCD
Switch local directory
Lpwd
Show local directory
Alias
Define aliases
Bookmark
Set bookmarks.
Exit
Exit ftp
Quick bookmarks
Supplement: aBiNg
The bookmark command in ftp writes the configuration ~ /. Lftp/bookmarks file; you can directly modify this file to quickly log on to the ftp server.

3. mirror synchronization and backup of server files

The main problem today is how to back up files on the server. After understanding the usage of the mirror command, it is found that it is suitable and easy to use.

Basic usage:

1) download server files:

# Mirror-vn rcd LCD // RCD is a remote path, and LCD is a local path

2) upload files:

# Mirror-R LCD RCD

The following is an automatic synchronization script:

#! Bin/bash
Echo "script start at 'date" + % Y-% m-% d % H: % M: % S"
HOST = "hostname"
USER = "yourname"
PASS = "password"
LCD = "LocalePath"
RCD = "RemotePath"
/Usr/sbin/lftp <EOF
Open ftp: // $ USER: $ PASS @ $ HOST
Mirror $ RCD $ LCD
EOF
Echo "script end at" 'date "+ % Y-% m-% d % H: % M: % S"

P.S:

It was a bit of pressure to start work today when we arrived yesterday. but it is a good thing to be under pressure and urge ourselves to work hard!

Think carefully and sum up to achieve better and faster growth!

Think more, sum up more, and grow up happily!

Related Article

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.