Tuesday, February 06, 2007

lftp 用法 教程 大全

lftp

登录 ftp

> open -u

下传目录

方法一 > mget -d dirname/*

方法二 > mirror dirname

上传目录

方法一 >mput -d dirname/*

方法二 >mirror -R dirname

下传普通文件

> get filename

下传多个普通文件

> mget *

lftp搜索文件方法
ls -R | grep .iso
find -d 3 | grep .iso

在使用中,多看看帮助 help

bookmark 标签

cat/more/less 显示文件内容(用cat和more)
zcat/zmore/zless 显示文件内容(用zcat和zmore,区别是zcat和zmore只能直接操作.gz文件)
bzcat/bzmore/bzless 显示文件内容(用bzcat和bzmore,区别是bzcat和bzmore只能直接操作.bz2文件)

get/mget/pget 抓取文件
put/mput/ 上传文件
mirror (-R) 下载上传目录
version 显示版本
cache 缓存操作

!ls !rm !rmdir !mkdir !mv !du !chmod
ls rm rmdir mkdir mv du chmod

scache 显示登录的站点会话(就是你进入过的并且缓存了的目录)
suspend 相当于 ctrl-z命令,主要是因为lftp不能用ctrl-z命令挂起,然后用fg命令回复
queue 队列 -d -m -v stop start
jobs (下载任务的显示)
kill 关闭下载任务
wait/fg 将任务放到前台,等待其结束

bye/quit/exit 退出
close 关闭发呆的连接,作用很弱
history 历史控制,history all 显示全部
open/connect 登录
user/login 在同一个ftp中改换用户名和密码登录
find -d 3 | grep .iso
ls -R | grep .iso
get1 获取单个文件(来自man lftp)

sleep 在睡眠阶段的间隔时间?什么时候是睡眠阶段? 不会用
repeat 可能是续传或登录的尝试间隔和次数?不会用
lftp 为什么这里面还有一个lftp?不会用
slot 连接的虚拟控制台,不会用
command 无帮助(几乎不用)
echo 无帮助(几乎不用)
site (几乎不用)
debug 调试(几乎不用)
source 读取外部lftp设置文件(几乎不用)
set 设置lftp参数(几乎不用)
alias 软链接(几乎不用)
module 读取外部lftp函数模块(几乎不用)
glob (几乎不用)
quote (几乎不用)
anon (匿名登录,几乎不用)

对于本地的目录改变要用lcd 而不能用!cd,而远程只用cd即可
对于本地目录要用lpwd,而不能用!pwd,而远程只用pwd(-p)即可

put [OPTS] [-o ]
get [OPTS] [-o ]
-c 选项,表示续传
-o 表示指定下传(上载)后得文件名
-E 表示删除远程文件
-a 表示用ascii模式(默认是用 binary模式)
-O 指定下传的文件所处的目录

reget [-o ]
等价与 get -c

mput [OPTS] [-o ]
mget [OPTS] [-o ]
-c 选项,表示续传
XXXXXX -o 表示指定下传(上载后)得文件名(这一项功能没有了)
-d 表示创建文件夹,使其与远程的文件夹名相同,并将其下的文件放入这个文件夹,如果不用这个命令,远程的文件夹中的内容就存到当前文件夹内了
-E 表示删除远程文件
-a 表示用ascii模式(默认是用 binary模式)
-O 指定下传的文件所处的目录

reput [-o ]
等价于 put -c

bye/quit/exit 退出
用法: exit [|bg]
exit - exit from lftp or move to background if jobs are active

If no jobs active, the code is passed to operating system as lftp
termination status. If omitted, exit code of last command is used.
`bg’ forces moving to background if cmd:move-background is false.

close 关闭发呆的连接,作用很弱

rm -r(删除目录内容和目录) 和 rmdir(只删除空目录)

对于ls的用法有很多
ls cls
rels recls
nlist relist

用法: bookmark [SUBCMD]
bookmark 命令控制书签

支持下面的子命令:
add [] - 把当前位置或指定的位置加入书签,并使用给定名字
del - 删除指定名字的书签
edit - 编辑书签文件
import - 导入其他程序的书签
list - 列出书签 (默认)

用法: cache [SUBCMD]
cache 命令控制本地的缓存

支持下列子命令:
stat - 显示缓存的状态 (默认)
on|ff - 打开/关闭缓存
flush - 清除缓存
size - 设置内存限制, -1 表示没有限制
expire - 设置缓存过期的时间为 N 秒 (x=s)
分钟 (x=m) 小时 (x=h) 或天(x=d)

open [OPTS] 打开站点
-e 在打开执行命令
-u [,] 指定用户 比如 open -u fff,fffcode 202.xxx.xxx.xxx
-p 指定端口
主机名,URL或书签名

user/login 在同一个ftp中改换用户名和密码登录,这要求你的ftp服务器有多个用户可以登录
用法: open [OPTS]
选择一个服务器, URL 或书签
-e 在选中后执行命令
-u [,] 使用指定的用户名/口令进行验证
-p 连接指定端口
主机名, URL 或书签

cache 缓存,在读入一次后,该目录或站点的内容就自动存在本机的缓存中,显示或者其它操作就不用再次下载远程的内容了,如果远程的内容有了变化,那么缓存若没有 更新,就无法显示远程的更新内容。这时需要用cache flush来清空缓存,这样在显示时就会再次登录ftp来更新缓存

du 常用 du -ah; du -sh; du -ch;若要比较大小变化,不要用h
-h 表示用M kb等表示文件大小
-a 全部显示
-s summrize
-c 最后显示total

mirror [OPTS] [remote [local]]
-c 续传
-e 比较并同步
-R 上传整个目录
-r 不递归目录
-n 只下载较新的档案
-parallel=n 同时下载n个档案(预设一次只下载一个)

用法: rm [-r] [-f]
Remove remote files
-r recursive directory removal, be careful
非常可怕,没有任何寻问,直接递归删除指定的文件,太可怕了
但是rm是不能用通配符的
-f work quietly(不反馈消息)

用法: mrm
使用通配符展开来删除指定的文件,不同同时和递归一起使用
-r 使用递归删除,这个命令等同于rm -r,这时是无法使用通配符的
-f work quietly

用法: mkdir [-p]
建立远程目录
-p 建立各级路径

用法: pwd [-p]
Print current remote URL.
-p show password(显示路径和密码)

用法: rmdir [-f]
删除远程目录,只能删除空目录

用法: chmod [OPTS] mode file…
Change the mode of each FILE to MODE.

-c, –changes - like verbose but report only when a change is made
-f, –quiet - suppress most error messages(安静模式)
-v, –verbose - output a diagnostic for every file processed(冗余模式)
-R, –recursive - change files and directories recursively(递归处理)

用法: history -w file|-r file|-c|-l [cnt]
-w Write history to file. 写入文件
-r Read history from file; appends to current history. 读入文件
-c Clear the history. 清除历史
-l List the history (default).
Optional argument cnt specifies the number of history lines to list,
or "all" to list all entries.(显示全部历史)

用法: kill all|
删除指定的任务号为 的任务, 或者所有的任务

flashfxp,用法ftp对传
ftpcopy

Obsolete. Use one of the following instead:
get ftp://… -o ftp://…
get -O ftp://… file1 file2…
put ftp://…
mput ftp://…/*
mget -O ftp://… ftp://…/*
or other combinations to get FXP transfer (directly between two ftp
servers). lftp would fallback to plain copy (via client) if FXP trans-
fer cannot be initiated or ftp:use-fxp is false.

get1用法,表示传送担搁文件,这真是太奇怪了
get1 [OPTS] rfile

Transfer a single file. Options:
-o destination file name (default - basename of rfile)
-c continue, reget
-E delete source files after successful transfer
-a use ascii mode (binary is the default)
–source-region=
transfer specified region of source file
–target-position=
position in target file to write data at

slot用法,对于多个ftp的登录
slot [name]

Select specified slot or list all slots allocated. A slot is a connec-
tion to a server, somewhat like a virtual console. You can create mul-
tiple slots connected to different servers and switch between them. You
can also use slot:name as a pseudo-URL evaluating to that slot loca-
tion.

Default readline binding allows quick switching between slots named 0-9
using Meta-0 - Meta-9 keys (often you can use Alt instead of Meta).

suspend用法
suspend

reconnect 是 `close; cache flush; cd .’ 的别名

ls,cls,nlist
rels,recls,renlist(与上面的命令相同,只是忽略cache缓存)

用法: [re]cls [opts] [path/][pattern]
List remote files. You can redirect output of this command to file
or via pipe to external command.

-1 - single-column output 单列显示
-h, –human-readable - print sizes in human readable format (e.g., 1K) 显示文件大小(可读性好一点)
-l, –long - use a long listing format 显示长文件信息
-s, –size - print size of each file (常用cls -sh)
–filesize - if printing size, only print size for files
-i, –nocase - case-insensitive pattern matching(对于通配符很有效果)
-I, –sortnocase - sort names case-insensitively(对于显示顺序有用)
–sort=OPT - "name", "size", "date"( cls –sort="size")(cls –sort="date")
-S - sort by file size (cls -S)
–user, –group, –perms, –date, –linkcount, –links (这些是显示所选内容,只加这些值即可比如cls –user pattern)
- show individual fields

-q, –quiet - don’t show status
-d, –directory - list directory entries instead of contents 只显示文件夹
-F, –classify - append indicator (one of /@) to entries ??
-B, –basename - show basename of files only 只显示文件名,不给全路径名
–block-size=SIZ - use SIZ-byte blocks
–si - likewise, but use powers of 1000 not 1024
-k, –kilobytes - like –block-size=1024
-D, –dirsfirst - list directories first(没用)

By default, cls output is cached, to see new listing use `recls’ or
`cache flush’.

The variables cls-default and cls-completion-default can be used to
specify defaults for cls listings and completion listings, respectively.
For example, to make completion listings show file sizes, set
cls-completion-default to "-s".

Tips: Use –filesize with -D to pack the listing better. If you don’t
always want to see file sizes, –filesize in cls-default will affect the
-s flag on the commandline as well. Add `-i’ to cls-completion-default
to make filename completion case-insensitive.
continue the process with shell’s fg or bg commands.

ls用法
ls 相当于 cls -l,不能控制文件大小的显示等等,但是,ls可以用-R命令递归
关键的关键是ls -R 可以输出重定向到grep或more,cat,less等命令来进行内容的筛选
这个功能可以完成ftp上的文件查找,实在是太强大了,不过,如果server不支持ls -R
那么就用传说中的find来实现

ls -R | grep .iso
find | grep .iso 不过find和ls -R 相比有些不足,有时会堵死,这时用 find -d 3 来指定
只搜索3层文件,一般就不会挂了

nlist
显示远程文件名,这个是不能用彩色显示的,功能一般,而且参数也很少

queue jobs suspend
queue
-m num1 num2
-d num
-n num command

example:

queue get FC4-i386-disc1.iso 任务将立即执行,如果前面没有任务的话
jobs
queue get FC3-i386-disc1.iso 添加这个任务到1号
jobs
queue get FC3-i386-rescuecd.iso 添加这个任务到2好
jobs
queue -n 1 get FC3-i386-disc3.iso 将这个命令添加到队列1号任务
jobs
queue -m 3 1 将排名第3的排到第1
jobs
queue -d 2 将队列中的2号任务删除
jobs

get aaa.iso
在文件传送中用ctrl-z,那么这个传输将被放到后台运行,可以用jobs来查看
实际上命令应当用后台下载,也就是
get aaa.iso &

queue stop将停止队列的执行,但是正在执行的队列不会受影响

queue start 将重新启动队列运行

queue单独的这样一个命令会列出queue的信息

停止运行中的jobs
kill all
kill job_number

当你在一个ftp server中打开了多个文件夹之后,一般你的命令若没有用re前缀的话,都会将当前的内容cache到本地硬盘内,这时你可以用scache看看你到过那些目录,然后可以用这个命令前面的数字,直接进入其目录内,比如
scache
4 ftp://aldfja/asldkfj/
6 ftp://aldfja/asdfasd/asa

scache 6 这时你就进入了ftp://aldfja/asdfasd/asa这个目录中