A summary of using LFTP under Linux

Source: Internet
Author: User
Tags openssl library

Today, when solving a remote server backup problem, the LFTP knowledge is used. Tidy up as follows:

LFTP features more powerful, compared to the original with FTP, a lot of convenience.

1. Login:

Lftp Ftp://[email protected]

pwd:*****

or open Ftp://[email protected]

2. Basic operation (Turn)

Lftp Usage Introduction
Lftp is a powerful download tool that supports access to file protocols: FTP, FTPS, HTTP, https, hftp, fish. (where FTPs and HTTPS need to include the OpenSSL library when compiling). Llftp's interface is very much like a shell: command completion, history, allowing multiple background tasks to perform and other functions, easy to use. It also has bookmarks, queues, mirroring, breakpoint continuation, multi-process download and other functions.
Command-line Syntax
To see LFTP's command-line syntax, just enter LFTP in the shell--help
lftp [OPTS]
' Lftp ' is the first command executed after the RC file is executed lftp
-F exit after executing commands in file
-C exit after executing command
--HELP Display Help information after exiting
--version exit after displaying lftp version
Other options with the ' Open ' command
-e Executes the command after selection
-u [,] authenticate with the specified username/password
-P connection to the specified port
Host name, URL, or bookmark name
If the site name is entered on the command line, LFTP will log in directly to the site, for example
$lftp ftp://.......
If you do not enter a site name at the command line, you must open it with the Open command after entering the LFTP interface
[Email protected] yhj]$ lftp
Lftp:~> Open ftp://.....------...
Common commands
* Download a single file and a set of files, the breakpoint continues with the-c parameter
Lftp ................:/> get-c Ls-lr.txt
Lftp ...............:/> mget *.txt
* Mirror (reverse image upload) A directory, you can mirror a directory in parallel with multiple threads (--parallel=n)
LFTP ................:/> Mirror Incoming local_name
Lftp ................:/> mirror-r Local_name
LFTP ................:/> Mirror--parallel=3 incoming Local_name
* Multi-threaded download, similar to network ant function; default is 5 threads
Lftp ................:/> pget-n 4 ls-lr.txt
* Background Task Management
By default, by pressing CTRL + Z, the task you are performing will be executed in the background, or you can add the & symbol at the end of the command line to make the task execute in the background. Use the jobs command to view all background processes. You can queue new tasks with the queue command. If exiting Lftp is still a task in the background, LFTP will be executed in the background.
* Other usage
LFTP supports a bash-like pipeline operation, such as using the following command to save the size of all files in a specific directory on an FTP server (or the entire site) to a local file Ls.txt
Lftp ................:/> du incoming > Ls.txt
Related documents
/etc/lftp.conf
Global profile, the actual location depends on the system configuration file directory, may be in/etc, may also be in/usr/local/etc
~/.LFTP/RC, ~/.LFTPRC
The user profile will be executed after/etc/lftp.conf, so the settings in this will overwrite the settings in/etc/lftp.conf.
Lftp default does not display the FTP server welcome information and error messages, which is inconvenient in many cases, because you may want to know whether the server is not connected to the boot, or the number of connections is full. If so, you can write a line in the ~/.LFTPRC
Debug 3
You can see the error message.
For more configuration options, please check the man manual or use the command set-a within the Lftp interface.
~/.lftp/log
Output is redirected here when lftp transitions to background non-suspend mode execution
~/.lftp/bookmarks
This is where Lftp stores bookmarks and can lftp view the bookmark command
~/.lftp/cwd_history
This file is used to store the working directory of the visited site

~/.lftprc
When using LFTP to access some of the domestic FTP server, often see the Chinese is garbled
^_^ Don't panic, this is due to inconsistent server and local code. We just need to create a new file in the main directory ~/.LFTPRC or ~/.LFTP/RC
and add the following content to it:
Debug 3set 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 see how to log in to the FTP server first.
Lftp Ftp://user:[email protected]:p ORT
Lftp User:[email protected]:p ORT
Lftp site-p port-u User,password
Lftp Site:port-u User,password
There are several ways to work, but the passwords are clear, so it seems less secure. Never mind
lftp [email protected]:p ORT
The system prompts for password, and the password is echoed back to ******.
But every time you input so much, good trouble oh. If there is a similar Leapftp site manager is good, in fact, Lftp long ago to us think well: This is the bookmark. We'll see in the back.
Common commands
Run at Terminal
Mans LFTP
or login FTP after entering
Help
You'll see a list of commands
Let's take a look at the commands commonly used by LFTP:
Ls
Displays a list of remote files (!ls displays a list of local files).
Cd
Switch the remote directory (LCD switch local directory).
Get
Download the remote file.
Mget
Download the remote file (you can use a wildcard character, which is *).
Pget
Use multiple threads to download remote files with a preset of five.
Mirror
Download/upload (mirror-r)/Synchronize the entire directory.
Put
Upload the file.
Mput
Upload multiple files (wildcard characters are supported).
Mv
Move the remote file (the remote file renamed).
Rm
Delete the remote file.
Mrm
Delete multiple remote files (wildcard characters are supported).
Mkdir
Create a remote directory.
RmDir
Delete the remote directory.
Pwd
Displays the directory where the remote is currently located (LPWD displays the local directory).
Du
Calculate the size of the remote directory
!
command to execute local shell (because Lftp does not have lls, it can be replaced by!ls)
Lcd
Switch Local Directory
Lpwd
Show Local Directory
Alias
Defining aliases
Bookmark
Set bookmarks.
Exit
Exit FTP
Shortcut bookmarks
Supplemental abing
The bookmark command in FTP is to write the configuration to the ~/.lftp/bookmarks file; we can directly modify this file and quickly log on to the FTP server.

3, Mirror synchronous mirror, backup server files

The main problem today is solving the problem of how to back up server-side files. After understanding the usage of the mirror instruction, it was found to be more suitable and useful.

Basic methods of Use:

1), download server-side files:

# MIRROR–VN RCD LCD//RCD for remote path, LCD for local path

2), Upload files:

# mirror–r LCD RCD

An automatic synchronization script is attached:

#!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: [email protected] $HOST
Mirror $RCD $LCD
Eof
echo "Script end at" ' Date "+%y-%m-%d%h:%m:%s"

A summary of using LFTP under Linux

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.