LFTP是一款非常著名的字符界面的文件传输工具。支持FTP、HTTP、FISH、SFTP、HTTPS和FTPS协议,如果还需要ssl的支持,则需要额外的OpenSSL依赖。
LFTP is sophisticated ftp/http client, file transfer program supporting a number of network protocols. Like BASH, it has job control and uses readline library for input. It has bookmarks, built-in mirror, can transfer several files in parallel. It was designed with reliability in mind. LFTP is free software, distributed under GNU GPL license.
Features
* FTP and HTTP protocols support.
* FTP (e.g. TIS FWTK) proxy support.
* HTTP proxy support.
* FTP over HTTP proxy support (hftp and CONNECT method).
* HTTPS and FTPS protocols support using GNU TLS or OpenSSL library.
* Automatic OPIE/SKEY support in FTP protocol.
* FXP transfers support (between two FTP servers, bypassing client machine).
* FTP listings support: unix-style, NT, EPLF, OS/2, AS400, MacWebStar, MLSD.
* Automatic reconnect and retry of an operation on retriable errors or timeout.
* IPv6 support in both FTP and HTTP.
* FISH protocol support. It uses ssh with no special program on server side.
* SFTP protocol v3-v6 support.
* HTTP/1.1 keep-alive support.
* Partial WebDAV support.
* BitTorrent protocol support.
* Experimental support for SRV DNS records.
* SOCKS support (configure option).
* Modification time preservation (if server can report it).
* `reget' and `reput' support.
* Built-in mirror and reverse mirror (mirror -R).
* Transfer rate throttling for each connection and for all connections in sum.
* Limit for number of connections to the same site. Interruption of background transfer to do a foreground operation when the limit is reached.
* Socket options tuning: buffer size and maximum segment size.
* Job queueing.
* Job execution at specified time.
* Comprehensive scripting support.
* URL recognition in most operations.
* Readline library is used for input.
* Context sensitive completion.
* Bash-like prompt extensions.
* Launching of local shell commands.
* Suspend support.
* Bookmarks.
* Aliases.
* Saving of last directory on each site. `cd -' to go there.
* Copying of files between two servers, e.g. between FTP and HTTP.
* Numerous settings which can be associated with a specific server or a group.
* Paging of remote files using external program.
* `zcat' and `zmore' support.
* Help for commands.
* Command history saved in a file.
* Transfer status includes rate and ETA.
* File listing cache.
* Background jobs (bash-like).
* Job output redirection to a file or to a program via pipe.
* Conditional commands depending on exit status of previous one.
* Loading of binary modules at run time (configure option).
* `pget' to download a file using several connections. `pget' download can be continued as it saves a status file periodically.
* `mirror' can download several files in parallel (--parallel option) and a single file with `pget' (--use-pget-n option).
* Slots. Each slot is a separate session, switch using Meta-{1-9} or `slot' command. Refer to a slot site using pseudo URL slot:name.
lftp的操作基本和ftp命令大同小异,首先打开ftp连接:lftp username:password@ip,打开链接后,需要使用cd命令进入到你需要上传的目录,然后通过lcd命令进入到本地的目录,这时可以通过put、mput、mirror等命令上传文件,或通过get、mget等命令下载文件,最后可以通过exit退出ftp。
lftp主要命令
| 命令 | 作用 |
|---|---|
| help | 产看命令列表 |
| ls | 显示远端文件列表 |
| cd | 切换远端目录 |
| get | 下载远程文件(单文件) |
| mget | 下载远程文件(多文件) |
| pget | 使用多个线程来下载远端文件 |
| mirror | 同步目录,可以用于下载和上传(- R)目录 |
| put | 上传文件(单文件) |
| mput | 上传文件(多文件) |
| mv | 移动文件(可以重命名目录、文件) |
| rm | 删除远端文件 |
| mrm | 删除多个文件,可以使用通配符 |
| mkdir | 创建目录 |
| rmdir | 删除目录 |
| pwd | 显示远端的当前目录 |
| lcd | 切换本地目录 |
| lpwd | 显示本地目录 |
| exit | 退出ftp |
示例:
# 连接数据库
lftp username:password@freeoa
# 列出当前ftp目录的文件
lftp username@freeoa:~> ls
# 进入ftp上的某个目录
lftp username@freeoa:~> cd testDir
# 定位到本地目录
lftp username@freeoa:~> lcd /local/testDir
# 上传单个文件
lftp username@freeoa:~> put testFile
# 上传多个文件,可以使用通配符
lftp username@freeoa:~> mput *.md
# 将本地的目录同步到ftp上
lftp username@freeoa:~> mirror -R .
# 获取远程的文件
lftp username@freeoa:~> get testFile
# 获取远程的多个文件
lftp username@freeoa:~> mget testFile
# 将远程的目录同步到本地
lftp username@freeoa:~> mirror .
# 退出ftp
lftp username@freeoa:~> exit
ftp上传脚本:
#!/bin/bash
pathStr=`pwd`
# 将脚本所在的目录的所有文件都上传到ftp上
# 参数为ftp连接信息 username:password@ip
lftp $1 <<EOF
lcd $pathStr
mirror -R -c .
rm ftp.sh
exit;
EOF
只要将上面脚本的mirror -R -c .改为mirror -c .就可以变成一个备份脚本
最新版本:4.6
更多内容请看主页。
项目主页:http://lftp.yar.ru/