Chinaunix首页 | 论坛 | 博客
  • 博客访问: 503300
  • 博文数量: 119
  • 博客积分: 5054
  • 博客等级: 大校
  • 技术积分: 1305
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-03 13:13
文章分类

全部博文(119)

文章存档

2011年(4)

2010年(115)

我的朋友

分类:

2010-01-04 16:01:11

lftp是老牌,“万里长城永不倒”类型的王道unix/linux下的ftp客户端,可是很多新手总是想要找一个所谓
* 图形界面
* 中文不乱码
* 可以多线程
的ftp客户端。由于lftp的命令行特性,总觉得可能是高手才用的东东,其实不然,俺老pan也就只有几板斧,照样用的很high~下面容俺一一道来:

首先,所有的lftp终端内的命令,都可以用

help    (显示所有可以使用的命令)

help 命令名

(上面的这两个命令可以说是最最强大的了^_^)

的方式来查看帮助信息。
另外,lftp支持tab自动补全,记不得命令是,多打两个tab,就可以看到可能的选项了。

1、登录ftp

lftp 用户名:密码@ftp地址:传送端口(默认21)

也可以先不带用户名登录,然后在接口界面下用login命令来用指定账号登录,密码不显示。

2、查看文件与改变目录

ls

cd 对应ftp目录

嘿嘿,很简单吧?其实,在lftp终端中,前面带一个l的命令例如lcd,指的是local,就是在本机的操作,而对应的没有这个l的,都是对ftp site的操作。还有就是要执行本地终端命令,也可以用前面带一个!的方式。这样,配合起来,终端,本地的操作都很方便。
例如,查看ftp上所有的以mp3为扩展名的文件:

find . -name "*.mp3"

3、下载

get当然是可以的,还可以

mget  -c *.pdf

把所有的pdf文件以允许断点续传的方式下载。m代表multi

mirror aaa/

将aaa目录整个的下载下来,子目录也会自动复制

pget -c -n 10 file.dat

以最多10个线程以允许断点续传的方式下载file.dat
可以通过设置pget:default-n的值而使用默认值。

4、上传

同样的put,mput,都是对文件的操作,和下载类似。

mirror -R 本地目录名

将本地目录以迭代(包括子目录)的方式反向上传到ftp site。

5、模式设置。

set ftp:charset gbk

远程ftp site用gbk编码,对应的要设置为utf8,只要替换gbk为utf8即可。

set file:charset utf8

本地的charset设定为utf8,如果你是gbk,相应改掉。

set ftp:passive-mode 1

使用被动模式登录,有些site要求必须用被动模式或者主动模式才可以登录,这个开关就是设置这个的。0代表不用被动模式。

6、书签

其实命令行也可以有书签,在lftp终端提示符下:

bookmark add ustc

就可以把当前正在浏览的ftp site用ustc作为标签储存起来。以后在shell终端下,直接

lftp ustc

就可以自动填好用户名,密码,进入对应的目录了。

bookmark edit

会调用编辑器手动修改书签。当然,也可以看到,这个书签其实就是个简单的文本文件。密码,用户名都可以看到。

7、配置文件

/etc/lftp.conf

一般,我会添加这几行:

set ftp:charset gbk
set file:charset utf8
set pget:default-n 5

这样,就不用每次进入都要打命令了。其他的set 可以自己tab然后help 来看。

原作者: xeoc

1. lftp 的上傳下載的速度限制

於 lftp.conf 中加入

set net:limit-rate 10000,10000  (单位是字节)

2. lftp 缺省不会显示 ftp 服务器的欢迎信息和错误信息,这在很多时候不方便,因为你有可能想知道这个服务器到底是因为没开机连不上,还是连接数已

满。如果是这样,你可以在 ~/.lftprc 里写入一行

debug 3

3.

下载文件命令: 续传,下载多个文件,多线程

lftp> get -c filename

lftp> mget *.file

lftp> pget -n 4 filename

下载/上传/多线程 文件夹

lftp> mirror dir

lftp> mirror -R dir

lftp> mirror --parallel=3 dir

纠正乱码显示中文及显示登录消息设置,修改/etc/lftp.conf,加入一段

#myset begin

set ftp:charset "gbk"

set file:charset "UTF-8"

#end

debug 3

更改本地下载目录

ftp> lcd ldir

默认为/home/user

比如改成lcd /home/user/download

队列命令(不必等到下载完毕再输入命令)

> queue

查看后台队列

> jobs

加入队列

>queue get file

>jobs

> queue start

> jobs

ctrl+z 后台运行

退出

ctrl+d
$lftp

>help lftp

可以查看lftp的更多命令,其中尤其是put, mput, 和get,mget完全对应。

例如

上传单个html文件到服务器一级目录下

>put localdir/index.html

上传多个html文件到服务器一级目录下

>mput localdir/*.html

4.

远程文件目录操作

cat[-b]:滚屏显示文件的内容。

more:分屏显示文件的内容。

zcat:滚屏显示.gz文件的内容。

zmore:分屏显示.gz文件的内容。

mv:文件改名。

rm[-r][-f]:删除文件。

mrm:删除文件(可用通配符)。

du[opts]:显示整个目录的容量。

find[directory]:递归显示指定目录的所有文件(用于ls–R失效时)。

3.上传和下载

get[opts][-o]:下载文件,可以改名后存储在本地。

mget[opts]:下载多个文件。

pget[opts][-o]:多线程下载。

regetrfile[-olfile]:下载续传。

put[opts][-o]:上传文件,可以改名后存储在远程。

mput[opts]:上传多个文件。

reputlfile[-orfile]:上传续传。

4.连接会话和队列管理

scache[]:显示所有连接会话或切换至指定的连接会话。

queue[opts][]:将命令置于队列等待执行。

jobs[-v]:显示后台执行的作业。

wait[]|all:将后台进程换到前台执行(fg是wait的别名)。

killall|:删除后台作业。

exitbg:退出lftp后,所有任务移至后台继续执行。

5.Cache管理

cache[SUBCMD]:管理lftp的cache。

[re]ls[args]:读取cache显示远程文件列表,rels不读取cache。

[re]cls[opts][path/][pattern]:cls提供了比ls更丰富的列表功能。

[re]nlist[]:nlist只显示文件名(没有颜色区分)。

6.站点镜像

mirror[opts][remote[local]]:用于实现站点镜像。

7.书签管理

bookmark[SUBCMD]:用于管理书签。

8.环境参数设置

set[opts][[]]:用户设置lftp的环境参数。

提示: lftp的功能

支持ftp、ftps、http、https、hftp、fish等传输协议;

支持FXP(在两个FTP服务器之间传输文件);

支持代理;

支持多线程传输;

支持传输队列(queue);

支持书签;

类似bash,它提供后台命令、nohop模式、命令历史、命令别名、命令补齐
和作业控制支持。

支持镜像(mirror);

lftp还有许许多多的功能,可以通过man lftp来了解。

man lftp (节选)

NAME
       lftp - Sophisticated file transfer program

SYNTAX
       lftp [-d] [-e cmd] [-p port] [-u user[,pass]] [site]
       lftp -f script_file
       lftp -c commands
       lftp --version
       lftp --help

VERSION
       This man page documents lftp version 3.6.0.

DESCRIPTION
       lftp is a file transfer program that allows sophisticated ftp, http and other connections to other hosts. If site is specified then
       lftp will connect to that site otherwise a connection has to be established with the open command.

       lftp can handle several file access methods - ftp, ftps, http, https, hftp, fish, sftp and file (https and ftps are only  available
       when  lftp  is  compiled  with  GNU  TLS  or  OpenSSL library). You can specify the method to use in `open URL' command, e.g. `open
       '. hftp is ftp-over-http-proxy protocol. It can be used automatically instead of ftp if ftp:proxy
       is  set  to  `[:port]'.  Fish is a protocol working over an ssh connection to a unix account. SFtp is a protocol imple-
       mented in ssh2 as sftp subsystem.

       Every operation in lftp is reliable, that is any not fatal error is ignored and  the  operation  is  repeated.  So  if  downloading
       breaks,  it  will  be  restarted  from  the point automatically. Even if ftp server does not support REST command, lftp will try to
       retrieve the file from the very beginning until the file is transferred completely.

       lftp has shell-like command syntax allowing you to launch several commands in parallel in background (&). It is  also  possible  to
       group commands within () and execute them in background. All background jobs are executed in the same single process. You can bring
       a foreground job to background with ^Z (c-z) and back with command `wait' (or `fg' which is alias to `wait'). To list running jobs,
       use  command  `jobs'. Some commands allow redirecting their output (cat, ls, ...) to file or via pipe to external command. Commands
       can be executed conditionally based on termination status of previous command (&&, ||).

       If you exit lftp when some jobs are not finished yet, lftp will move itself to nohup mode in background. The same happens when  you
       have a real modem hangup or when you close an xterm.

       lftp has builtin mirror which can download or update a whole directory tree. There is also reverse mirror (mirror -R) which uploads
       or updates a directory tree on server. Mirror can also synchronize directories between two remote servers, using FXP if  available.

       There is command `at' to launch a job at specified time in current context, command `queue' to queue commands for sequential execu-
       tion for current server, and much more.

       On startup, lftp executes /etc/lftp.conf and then ~/.lftprc and ~/.lftp/rc. You can place aliases and `set'  commands  there.  Some
       people  prefer  to see full protocol debug, use `debug' to turn the debug on. Use `debug 3' to see only greeting messages and error
       messages.

       lftp has a number of settable variables. You can use `set -a' to see all variables and their values or `set  -d'  to  see  list  of
       defaults.  Variable names can be abbreviated and prefix can be omitted unless the rest becomes ambiguous.

       If lftp was compiled with OpenSSL (configure --with-openssl), then it includes software developed by the OpenSSL Project for use in
       the OpenSSL Toolkit. ()

   Commands
       ! shell command

       Launch shell or shell command.

            !ls

       To do a directory listing of the local host.
……

       bookmark  [subcommand]

       The bookmark command controls bookmarks.
            add  []  add current place or given location
                           to bookmarks and bind to given name
            del           remove bookmark with name
            edit           start editor on bookmarks file
            import        import foreign bookmarks
            list           list bookmarks (default)
……

   Settings
       On startup, lftp executes ~/.lftprc  and  ~/.lftp/rc.   You  can  place
       aliases and `set' commands there. Some people prefer to see full proto-
       col debug, use `debug' to turn the debug on.

       There is also a system-wide startup file in /etc/lftp.conf.  It can  be
       in different directory, see FILES section.

       lftp has the following settable variables (you can also use `set -a' to
       see all variables and their values):
……

OPTIONS
       -d     Switch on debugging mode

       -e commands
              Execute given commands and don't exit.

       -p port
              Use the given port to connect

       -u user[,pass]
              Use the given username and password to connect
              (其实也可以采用:lftp user[:pass]@ftpserver)
       -f script_file
              Execute commands in the file and exit

       -c commands
              Execute the given commands and exit

FILES
       /etc/lftp.conf
              system-wide   startup   file.   Actual   location   depends   on
              --sysconfdir  configure  option. It is /etc when prefix is /usr,
              /usr/local/etc by default.

       ~/.lftp/rc, ~/.lftprc
              These files are executed on lftp startup after /etc/lftp.conf.

       ~/.lftp/log
              The file things are logged to when lftp  moves  into  the  back-
              ground in nohup mode.

       ~/.lftp/transfer_log
              The file transfers are logged to when xfer:log setting is set to
              `yes'.

       ~/.lftp/bookmarks
              The file is used to store lftp's bookmarks.   See  the  bookmark
              command.
       ~/.lftp/cwd_history
              The file is used to store last working directories for each site
              visited.

       ~/.netrc
              The file is consulted to get default login and password  to  ftp
              server.   Passwords  are  also searched here if an URL with user
              name but with no password is used.
阅读(1935) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~