lftp - Unix, Linux 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 http://www.us.kernel.org/pub/linux’. hftp is
ftp-over-http-proxy protocol. It can be used automatically instead of ftp
if ftp:proxy is set to ‘http://proxy[:port]’. Fish is a protocol working
over an ssh connection to a unix account. SFtp is a protocol implemented
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 execution
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. (http://www.openssl.org/)






! shell command 

Launch shell or shell command.






!ls


To do a directory listing of the local host.


alias  [name [value]] 

Define or undefine alias name. If value is omitted, the alias is
undefined, else it takes the value value. If no argument is given
the current aliases are listed.






alias dir ls -lF
alias less zmore


anon 

Sets the user to anonymous.  This is the default.


at time [ -- command ]  

Wait until the given time and execute given (optional) command. See also at(1).


bookmark  [subcommand] 

The bookmark command controls bookmarks.




add <name> [<loc>]      add current place or given location
                        to bookmarks and bind to given name
del <name>              remove bookmark with name
edit                    start editor on bookmarks file
import <type>           import foreign bookmarks
list                    list bookmarks (default)


cache  [subcommand] 

The cache command controls local memory cache.
The following subcommands are recognized:




stat                    print cache status (default)
on|off                  turn on/off caching
flush                   flush cache
size lim                        set memory limit, -1 means unlimited
expire Nx               set cache expiration time to N seconds (x=s)
                        minutes (x=m) hours (x=h) or days (x=d)




cat files 

cat outputs the remote file(s) to stdout.  (See also more,
zcat and zmore)


cd rdir 

Change current remote directory.  The previous remote directory is
stored as ‘-’. You can do ‘cd -’ to change the directory back.
The previous directory for each site is also stored on disk,
so you can do ‘open site; cd -’ even after lftp restart.


chmod mode files 

Change permission mask on remote files. The mode must be an octal number.


close [-a] 

Close idle connections.  By default only with the current server, use
-a to close all idle connections.


cls [OPTS] files... 

‘cls’ tries to retrieve information about specified files or directories
and outputs the information according to format options. The difference between
‘ls’ and ‘cls’ is that ‘ls’ requests the server to format file listing, and
‘cls’ formats it itself, after retrieving all the needed information.
See ‘help cls’ for options.


commandcmdargs... 

execute given command ignoring aliases.


debug [-o file] level|off 

Switch debugging to level or turn it off.  Use -o to redirect
the debug output to a file.


echo [-n] string 

guess what it does.


eval [-f format ] args... 

without -f it just executes given arguments as a command. With -f, arguments
are transformed into a new command. The format can contain plain text and
placeholders $0...$9 and $@, corresponding to the arguments.


exit [bg] [top] [kill] [code] 

exit will exit from lftp or move to background if there are active jobs. If
no job is active, code is passed to operating system as lftp’s
termination status. If code is omitted, the exit code of last
command is used.


‘exit bg’ forces moving to background when cmd:move-background is false.
‘exit top’ makes top level ‘shell’ (internal lftp command executor) terminate.
‘exit kill’ kills all numbered jobs before exiting. The options can be combined, e.g.
‘at 08:00 -- exit top kill &’ kills all jobs and makes lftp exit at specified time.


fg 

Alias for ‘wait’.


find  [directory]  

List files in the directory (current directory by default) recursively.
This can help with servers lacking ls -R support. You can redirect output
of this command.


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://.../*


get [-E] [-a] [-c] [-O base] rfile [-o lfile] ... 

Retrieve the remote file rfile and store it as the local file
lfile.  If -o is omitted, the file is stored to local file named as
base name of rfile. You can get multiple files by specifying multiple
instances of rfile (and -o lfile). Does not expand wildcards, use
mget for that.




-c              continue, reget
-E              delete source files after successful transfer
-a              use ascii mode (binary is the default)
-O <base>       specifies base directory or URL where files should be placed


Examples:




get README
get README -o debian.README
get README README.mirrors
get README -o debian.README README.mirrors -o debian.mirrors
get README -o ftp://some.host.org/debian.README
get README -o ftp://some.host.org/debian-dir/ (end slash is important)


get1 [OPTS] rfile 

Transfer a single file. Options:




-o <lfile>      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=<from-to>
                transfer specified region of source file
--target-position=<pos>
                position in target file to write data at


glob [-d] [-a] [-f] command patterns 

Glob given patterns containing metacharacters and pass result to given command.
E.g. ‘‘glob echo *’’.




-f      plain files (default)
-d      directories
-a      all types


help [cmd]


Print help for cmd or if no cmd was specified print a list of
available commands.


jobs [-v] 

List running jobs. -v means verbose, several -v can be specified.


kill all|job_no


Delete specified job with job_no or all jobs.
(For job_no see jobs)


lcd ldir


Change current local directory ldir. The previous local
directory is stored as ‘-’. You can do ‘lcd -’ to change the directory back.


lpwd 

Print current working directory on local machine.


ls params


List remote files. You can redirect output of this command to file or
via pipe to external command.  By default, ls output is cached, to see
new listing use
rels or
cache flush. 

mget [-c] [-d] [-a] [-E] [-O base] files 

Gets selected files with expanded wildcards.






-c              continue, reget.
-d              create directories the same as file names and get
                the files into them instead of current directory.
-E              delete source files after successful transfer
-a              use ascii mode (binary is the default)
-O <base>       specifies base directory or URL where files should be placed


mirror [OPTS] [source [target]] 

Mirror specified source directory to local target directory. If target
directory ends with a slash, the source base name is appended to target
directory name. Source and/or target can be URLs pointing to directories.






-c, --continue          continue a mirror job if possible
-e, --delete            delete files not present at remote site
    --delete-first              delete old files before transferring new ones
    --depth-first               descend into subdirectories before transferring files
-s, --allow-suid                set suid/sgid bits according to remote site
    --allow-chown       try to set owner and group on files
    --ascii             use ascii mode transfers (implies --ignore-size)
    --ignore-time               ignore time when deciding whether to download
    --ignore-size               ignore size when deciding whether to download
    --only-missing      download only missing files
    --only-existing     download only files already existing at target
-n, --only-newer        download only newer files (-c won’t work)
    --no-empty-dirs     don’t create empty directories (implies --depth-first)
-r, --no-recursion      don’t go to subdirectories
    --no-symlinks       don’t create symbolic links
-p, --no-perms          don’t set file permissions
    --no-umask          don’t apply umask to file modes
-R, --reverse           reverse mirror (put files)
-L, --dereference       download symbolic links as files
-N, --newer-than=SPEC   download only files newer than specified time
    --on-change=CMD             execute the command if anything has been changed
    --older-than=SPEC   download only files older than specified time
    --size-range=RANGE  download only files with size in specified range
-P, --parallel[=N]      download N files in parallel
    --use-pget[-n=N]    use pget to transfer every single file
    --loop              loop until no changes found
-i RX, --include RX     include matching files
-x RX, --exclude RX     exclude matching files
-I GP, --include-glob GP        include matching files
-X GP, --exclude-glob GP        exclude matching files
-v, --verbose[=level]   verbose operation
    --log=FILE          write lftp commands being executed to FILE
    --script=FILE               write lftp commands to FILE, but don’t execute them
    --just-print, --dry-run     same as --script=-
    --use-cache         use cached directory listings
--Remove-source-files   remove files after transfer (use with caution)
-a                      same as --allow-chown --allow-suid --no-umask


When using -R, the first directory is local and the second is remote.
If the second directory is omitted, base name of first directory is used.
If both directories are omitted, current local and remote directories are used.
If target directory ends with a slash (except root directory) then base
name of source directory is appended.


RX is an extended regular expression, just like in egrep(1).


GP is a glob pattern, e.g. ‘*.zip’.


Include and exclude options can be specified multiple times. It means that
a file or directory would be mirrored if it matches an include and does
not match to excludes after the include, or does not match anything
and the first check is exclude. Directories are matched with a slash appended.


Note that symbolic links are not created when uploading to remote server,
because ftp protocol cannot do it. To upload files the links refer
to, use ‘mirror -RL’ command (treat symbolic links as files).


For option --newer-than you can either specify a file or time specification
like that used by at(1) command, e.g. ‘now-7days’ or ‘week ago’. If you
specify a file, then modification time of that file will be used.


Verbosity level can be selected using --verbose=level option or by several
-v options, e.g. -vvv. Levels are:




0 - no output (default)
1 - print actions
2 - +print not deleted file names (when -e is not specified)
3 - +print directory names which are mirrored


--only-newer turns off file size comparison and uploads/downloads
only newer files even if size is different. By default older files are transferred and replace newer ones.


You can mirror between two servers if you specify URLs instead of directories.
FXP is used automatically for transfers between ftp servers, if possible.


Some ftp servers hide dot-files by default (e.g. .htaccess), and show
them only when LIST command is used with -a option. In such case try to use
‘set ftp:list-options -a’.


mkdir [-p] dir(s) 

Make remote directories. If -p is used, make all components of paths.


module module [ args ] 

Load given module using dlopen(3) function. If module name does not contain
a slash, it is searched in directories specified by module:path variable.
Arguments are passed to module_init function. See README.modules for technical
details.


more files


Same as ‘cat files | more’. if PAGER is set, it is used as filter.
(See also cat, zcat and zmore)


mput [-c] [-d] [-a] [-E] [-O base] files 

Upload files with wildcard expansion. By default it uses the base name of
local name as remote one. This can be changed by ‘-d’ option.




-c              continue, reput
-d              create directories the same as in file names and put the
                files into them instead of current directory
-E              delete source files after successful transfer (dangerous)
-a              use ascii mode (binary is the default)
-O <base>       specifies base directory or URL where files should be placed


mrm file(s)


Same as ‘glob rm’. Removes specified file(s) with wildcard expansion.


mv file1 file2


Rename file1 to file2.


nlist [args]


List remote file names


open [-e cmd] [-u user[,pass]] [-p port] host|url 

Select an ftp server.


pget [OPTS] rfile [-o lfile] 

Gets the specified file using several connections. This can speed up
transfer, but loads the net and server heavily impacting other users. Use only if
you really have to transfer the file ASAP.
Options:




-c              continue transfer. Requires lfile.lftp-pget-status file.
-n maxconn      set maximum number of connections (default is taken from pget:default-n setting)




put [-E] [-a] [-c] [-O base] lfile [-o rfile] 

Upload lfile with remote name rfile. If -o omitted, the base name
of lfile is used as remote name. Does not expand wildcards, use mput for that.




-o <rfile>      specifies remote file name (default - basename of lfile)
-c              continue, reput
                it requires permission to overwrite remote files
-E              delete source files after successful transfer (dangerous)
-a              use ascii mode (binary is the default)
-O <base>       specifies base directory or URL where files should be placed


pwd [-p] 

Print current remote URL. Use ‘-p’ option to show password in the URL.


queue [-n num ] cmd 

Add the given command to queue for sequential execution. Each site has its own
queue. ‘-n’ adds the command before the given item in the queue. Don’t try to
queue ‘cd’ or ‘lcd’ commands, it may confuse lftp. Instead
do the cd/lcd before ‘queue’ command, and it will remember the place in which
the command is to be done. It is possible to queue up an already running job
by ‘queue wait <jobno>’, but the job will continue execution even if it is not
the first in queue.


‘queue stop’ will stop the queue, it will not execute any new commands,
but already running jobs will continue to run. You can use ‘queue stop’ to
create an empty stopped queue. ‘queue start’ will resume queue execution.
When you exit lftp, it will start all stopped queues automatically.


‘queue’ with no arguments will either create a stopped queue or print queue
status.


queue --delete|-d [index or wildcard expression] 

Delete one or more items from the queue. If no argument is given, the last
entry in the queue is deleted.


queue --move|-m <index or wildcard expression> [index] 

Move the given items before the given queue index, or to the end if no
destination is given.






-q      Be quiet.
-v      Be verbose.
-Q      Output in a format that can be used to re-queue.
        Useful with --delete.






> get file &
[1] get file
> queue wait 1
> queue get another_file
> cd a_directory
> queue get yet_another_file






queue -d 3              Delete the third item in the queue.
queue -m 6 4            Move the sixth item in the queue before the fourth.
queue -m "get*zip" 1    Move all commands matching "get*zip" to the beginning
                        of the queue.  (The order of the items is preserved.)
queue -d "get*zip"      Delete all commands matching "get*zip".


quote cmd


For FTP - send the command uninterpreted. Use with caution - it can lead to
unknown remote state and thus will cause reconnect. You cannot
be sure that any change of remote state because of quoted command
is solid - it can be reset by reconnect at any time.


For HTTP - specific to HTTP action. Syntax: ‘‘quote <command> [<args>]’’.
Command may be ‘‘set-cookie’’ or ‘‘post’’.




open http://www.site.net
quote set-cookie "variable=value; othervar=othervalue"
set http:post-content-type application/x-www-form-urlencoded
quote post /cgi-bin/script.cgi "var=value&othervar=othervalue" > local_file


For FISH - send the command uninterpreted. This can be used to execute
arbitrary commands on server. The command must not take input or print ###
at new line beginning. If it does, the protocol will become out of sync.




open fish://server
quote find -name \*.zip


reget rfile [-o lfile] 

Same as ‘get -c’.


rels [args]


Same as ‘ls’, but ignores the cache.


renlist [args]


Same as ‘nlist’, but ignores the cache.


repeat [ -c <count>] [[-d] delay] [command] 

Repeat the command. Between the commands a delay is inserted, by default 1 second.
Option ‘-c’ limits number of repeations. Option ‘--while-ok’ breaks loop when
command returns non-zero exit code; ‘--until-ok’ breaks on zero exit code.

Examples:




repeat at tomorrow -- mirror
repeat 1d mirror


reput lfile [-o rfile] 

Same as ‘put -c’.


rm [-r] [-f] files


Remove remote files.  Does not expand wildcards, use mrm for
that. -r is for recursive directory remove. Be careful, if something goes
wrong you can lose files. -f suppress error messages.


rmdir dir(s)


Remove remote directories.


scache [session]


List cached sessions or switch to specified session.


set [var [val]]


Set variable to given value. If the value is omitted, unset the variable.
Variable name has format ‘‘name/closure’’, where closure can specify
exact application of the setting. See below for details.
If set is called with no variable then only altered settings are listed.
It can be changed by options:






-a      list all settings, including default values
-d      list only default values, not necessary current ones




site site_cmd


Execute site command site_cmd and output the result.
You can redirect its output.


sleep interval 

Sleep given time interval and exit. Interval is in seconds by default, but
can be suffixed with ’m’, ’h’, ’d’ for minutes, hours and days respectively.
See also at.


slot [name] 

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


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).


source file

source -e command


Execute commands recorded in file file or returned by specified external command.




source ~/.lftp/rc
source -e echo help


suspend 

Stop lftp process. Note that transfers will be also stopped until you
continue the process with shell’s fg or bg commands.


user user [pass]

user URL [pass]


Use specified info for remote login. If you specify an URL with user name,
the entered password will be cached so that future URL references can use it.


version 

Print lftp version.


wait [jobno]

wait all 

Wait for specified job to terminate. If jobno is omitted, wait for last
backgrounded job.


‘wait all’ waits for all jobs termination.


zcat files


Same as cat, but filter each file through zcat. (See also cat,
more and zmore)


zmore files


Same as more, but filter each file through zcat. (See also cat,
zcat and more)




On startup, lftp executes
~/.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.


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):








set cmd:verify-path/hftp://* false
cd directory &




set sftp:connect-program rsh
set sftp:server-program /usr/libexec/openssh/sftp-server




The closure for ‘dns:’, ‘net:’, ‘ftp:’, ‘http:’, ‘hftp:’ domain variables
is currently just the host name as you specify it in the ‘open’ command
(with some exceptions where closure is meaningless, e.g. dns:cache-size).
For some ‘cmd:’ domain variables the closure is current URL without path.
For other variables it is not currently used. See examples in the sample
lftp.conf.


Certain commands and settings take a time interval parameter. It has
the format Nx[Nx...], where N is time amount (floating point) and x is time unit: d - days,
h - hours, m - minutes, s - seconds. Default unit is second. E.g. 5h30m or 5.5h.
Also the interval can be ‘infinity’, ‘inf’, ‘never’, ‘forever’ - it means
infinite interval. E.g. ‘sleep forever’ or ‘set dns:cache-expire never’.


Boolean settings can be one of (true, on, yes, 1, +) for a True value
or one of (false, off, no, 0, -) for a False value.


Integer settings can have a suffix: k - kibi, m - mebi, g - gigi, etc.
They can also have a prefix: 0 - octal, 0x - hexadecimal.




Lftp can speed up ftp operations by sending several commands at once and
then checking all the responses. See ftp:sync-mode variable. Sometimes
this does not work, thus synchronous mode is the default. You can try
to turn synchronous mode off and see if it works for you. It is known
that some network software dealing with address translation works
incorrectly in the case of several FTP commands in one network packet.


RFC959 says: ‘‘The user-process sending another command before the
completion reply would be in violation of protocol; but server-FTP
processes should queue any commands that arrive while a preceding
command is in progress’’. Also, RFC1123 says: ‘‘Implementors MUST
NOT assume any correspondence between READ boundaries on the control
connection and the Telnet EOL sequences (CR LF).’’ and ‘‘a single READ
from the control connection may include more than one FTP command’’.


So it must be safe to send several commands at once, which speeds up
operation a lot and seems to work with all Unix and VMS based ftp
servers. Unfortunately, windows based servers often cannot handle
several commands in one packet, and so cannot some broken routers.











ftpd (1)
ftpd (1)


Alexander V. Lukyanov
lav@yars.free.net




Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page