/* * lftp - file transfer program * * Copyright (c) 1996-2017 by Alexander V. Lukyanov (lav@yars.free.net) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include "modconfig.h" #include "trio.h" #include #include #include #include #include #include #include #include #include #ifdef HAVE_DLFCN_H # include #endif #include #include #include "CmdExec.h" #include "GetJob.h" #include "CatJob.h" #include "LsCache.h" #include "mgetJob.h" #include "mkdirJob.h" #include "rmJob.h" #include "SysCmdJob.h" #include "mvJob.h" #include "pgetJob.h" #include "SleepJob.h" #include "FindJob.h" #include "FindJobDu.h" #include "ChmodJob.h" #include "CopyJob.h" #include "OutputJob.h" #include "echoJob.h" #include "EditJob.h" #include "mmvJob.h" #include "misc.h" #include "alias.h" #include "netrc.h" #include "url.h" #include "GetPass.h" #include "SignalHook.h" #include "FileFeeder.h" #include "bookmark.h" #include "log.h" #include "module.h" #include "FileCopy.h" #include "DummyProto.h" #include "QueueFeeder.h" #include "lftp_rl.h" #include "FileSetOutput.h" #include "PatternSet.h" #include "LocalDir.h" #include "ConnectionSlot.h" #include "configmake.h" History cwd_history; CMD(alias); CMD(anon); CMD(at); CMD(bookmark); CMD(cache); CMD(cat); CMD(cd); CMD(chmod); CMD(close); CMD(cls); CMD(command); CMD(debug); CMD(du); CMD(echo); CMD(edit); CMD(eval); CMD(exit); CMD(find); CMD(get); CMD(get1); CMD(glob); CMD(help); CMD(jobs); CMD(kill); CMD(lcd); CMD(lftp); CMD(ln); CMD(local); CMD(lpwd); CMD(ls); CMD(mirror); CMD(mkdir); CMD(module); CMD(mrm); CMD(mv); CMD(open); CMD(pwd); CMD(queue); CMD(repeat); CMD(rm); CMD(scache); CMD(set); CMD(shell); CMD(sleep); CMD(slot); CMD(source); CMD(subsh); CMD(suspend); CMD(tasks); CMD(torrent); CMD(user); CMD(ver); CMD(wait); CMD(empty); CMD(notempty); CMD(true); CMD(false); CMD(mmv); #define HELP_IN_MODULE "m" #define ALIAS_FOR(cmd) cmd_##cmd,0,#cmd #define ALIAS_FOR2(a,cmd) cmd_##cmd,0,a #ifdef MODULE_CMD_MIRROR # define cmd_mirror 0 #endif #ifdef MODULE_CMD_SLEEP # define cmd_sleep 0 # define cmd_at 0 # define cmd_repeat 0 #endif #ifdef MODULE_CMD_TORRENT # define cmd_torrent 0 #endif enum { DEFAULT_DEBUG_LEVEL=9 }; const struct CmdExec::cmd_rec CmdExec::static_cmd_table[]= { {"!", cmd_shell, N_("!"), N_("Launch shell or shell command\n")}, {"(", cmd_subsh, N_("(commands)"), N_("Group commands together to be executed as one command\n" "You can launch such a group in background\n")}, {"?", ALIAS_FOR(help)}, {"alias", cmd_alias, N_("alias [ []]"), N_("Define or undefine alias . If omitted,\n" "the alias is undefined, else is takes the value .\n" "If no argument is given the current aliases are listed.\n")}, {"anon", cmd_anon, 0, N_("anon - login anonymously (by default)\n")}, {"at", cmd_at, 0, HELP_IN_MODULE}, {"bookmark",cmd_bookmark,N_("bookmark [SUBCMD]"), N_("bookmark command controls bookmarks\n\n" "The following subcommands are recognized:\n" " add [] - add current place or given location to bookmarks\n" " and bind to given name\n" " del - remove bookmark with the name\n" " edit - start editor on bookmarks file\n" " import - import foreign bookmarks\n" " list - list bookmarks (default)\n")}, {"bye", ALIAS_FOR(exit)}, {"cache", cmd_cache, N_("cache [SUBCMD]"), N_("cache command controls local memory cache\n\n" "The following subcommands are recognized:\n" " stat - print cache status (default)\n" " on|off - turn on/off caching\n" " flush - flush cache\n" " size - set memory limit\n" " expire - set cache expiration time to N seconds (x=s)\n" " minutes (x=m) hours (x=h) or days (x=d)\n")}, {"cat", cmd_cat, N_("cat [-b] "), N_("cat - output remote files to stdout (can be redirected)\n" " -b use binary mode (ascii is the default)\n")}, {"cd", cmd_cd, N_("cd "), N_("Change current remote directory to . The previous remote directory\n" "is stored as `-'. You can do `cd -' to change the directory back.\n" "The previous directory for each site is also stored on disk, so you can\n" "do `open site; cd -' even after lftp restart.\n")}, {"chmod", cmd_chmod, N_("chmod [OPTS] mode file..."), N_("Change the mode of each FILE to MODE.\n" "\n" " -c, --changes - like verbose but report only when a change is made\n" " -f, --quiet - suppress most error messages\n" " -v, --verbose - output a diagnostic for every file processed\n" " -R, --recursive - change files and directories recursively\n" "\n" "MODE can be an octal number or symbolic mode (see chmod(1))\n")}, {"close", cmd_close, "close [-a]", N_("Close idle connections. By default only with current server.\n" " -a close idle connections with all servers\n")}, {"cls", cmd_cls, N_("[re]cls [opts] [path/][pattern]"), N_("List remote files. You can redirect output of this command to file\n" "or via pipe to external command.\n" "\n" /* note: I've tried to keep options which are likely to be always * turned on (via cmd:cls-default, etc) capital, to leave lowercase * available for options more commonly used manually. -s/-S is an * exception; they both seem to be options used manually, so I made * them align with GNU ls options. */ " -1 - single-column output\n" " -a, --all - show dot files\n" " -B, --basename - show basename of files only\n" " --block-size=SIZ - use SIZ-byte blocks\n" " -d, --directory - list directory entries instead of contents\n" " -F, --classify - append indicator (one of /@) to entries\n" " -h, --human-readable - print sizes in human readable format (e.g., 1K)\n" " --si - likewise, but use powers of 1000 not 1024\n" " -k, --kilobytes - like --block-size=1024\n" " -l, --long - use a long listing format\n" " -q, --quiet - don't show status\n" " -s, --size - print size of each file\n" " --filesize - if printing size, only print size for files\n" " -i, --nocase - case-insensitive pattern matching\n" " -I, --sortnocase - sort names case-insensitively\n" " -D, --dirsfirst - list directories first\n" " --sort=OPT - \"name\", \"size\", \"date\"\n" " -S - sort by file size\n" " --user, --group, --perms, --date, --linkcount, --links\n" " - show individual fields\n" " --time-style=STYLE - use specified time format\n" "\n" "By default, cls output is cached, to see new listing use `recls' or\n" "`cache flush'.\n" "\n" "The variables cls-default and cls-completion-default can be used to\n" "specify defaults for cls listings and completion listings, respectively.\n" "For example, to make completion listings show file sizes, set\n" "cls-completion-default to \"-s\".\n" "\n" /* FIXME: poorly worded. another explanation of --filesize: if a person * wants to only see file sizes for files (not dirs) when he uses -s, * add --filesize; it won't have any effect unless -s is also used, so * it can be enabled all the time. (that's also poorly worded, and too * long.) */ "Tips: Use --filesize with -D to pack the listing better. If you don't\n" "always want to see file sizes, --filesize in cls-default will affect the\n" "-s flag on the commandline as well. Add `-i' to cls-completion-default\n" "to make filename completion case-insensitive.\n" )}, {"connect", ALIAS_FOR(open)}, {"command", cmd_command}, {"debug", cmd_debug, N_("debug [OPTS] [|off]"), N_("Set debug level to given value or turn debug off completely.\n" " -o redirect debug output to the file\n" " -c show message context\n" " -p show PID\n" " -t show timestamps\n")}, {"du", cmd_du, N_("du [options] "), N_("Summarize disk usage.\n" " -a, --all write counts for all files, not just directories\n" " --block-size=SIZ use SIZ-byte blocks\n" " -b, --bytes print size in bytes\n" " -c, --total produce a grand total\n" " -d, --max-depth=N print the total for a directory (or file, with --all)\n" " only if it is N or fewer levels below the command\n" " line argument; --max-depth=0 is the same as\n" " --summarize\n" " -F, --files print number of files instead of sizes\n" " -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)\n" " -H, --si likewise, but use powers of 1000 not 1024\n" " -k, --kilobytes like --block-size=1024\n" " -m, --megabytes like --block-size=1048576\n" " -S, --separate-dirs do not include size of subdirectories\n" " -s, --summarize display only a total for each argument\n" " --exclude=PAT exclude files that match PAT\n")}, {"echo", cmd_echo, 0}, {"edit", cmd_edit, N_("edit [OPTS] "), N_("Retrieve remote file to a temporary location, run a local editor on it\n" "and upload the file back if changed.\n" " -k keep the temporary file\n" " -o explicit temporary file location\n")}, {"eval", cmd_eval, 0}, {"exit", cmd_exit, N_("exit [|bg]"), N_("exit - exit from lftp or move to background if jobs are active\n\n" "If no jobs active, the code is passed to operating system as lftp\n" "termination status. If omitted, exit code of last command is used.\n" "`bg' forces moving to background if cmd:move-background is false.\n")}, {"fg", ALIAS_FOR(wait)}, {"find", cmd_find,0, N_("Usage: find [OPTS] [directory]\n" "Print contents of specified directory or current directory recursively.\n" "Directories in the list are marked with trailing slash.\n" "You can redirect output of this command.\n" " -d, --maxdepth=LEVELS Descend at most LEVELS of directories.\n")}, {"get", cmd_get, N_("get [OPTS] [-o ]"), N_("Retrieve remote file and store it to local file .\n" " -o specifies local file name (default - basename of rfile)\n" " -c continue, resume transfer\n" " -E delete remote files after successful transfer\n" " -a use ascii mode (binary is the default)\n" " -O specifies base directory or URL where files should be placed\n")}, {"get1", cmd_get1, 0,0}, {"glob", cmd_glob, N_("glob [OPTS] "), N_( "Expand wildcards and run specified command.\n" "Options can be used to expand wildcards to list of files, directories,\n" "or both types. Type selection is not very reliable and depends on server.\n" "If entry type cannot be determined, it will be included in the list.\n" " -f plain files (default)\n" " -d directories\n" " -a all types\n" " --exist return zero exit code when the patterns expand to non-empty list\n" " --not-exist return zero exit code when the patterns expand to an empty list\n")}, {"help", cmd_help, N_("help []"), N_("Print help for command , or list of available commands\n")}, {"jobs", cmd_jobs, "jobs [-v] []", N_("List running jobs. -v means verbose, several -v can be specified.\n" "If is specified, only list a job with that number.\n")}, {"kill", cmd_kill, N_("kill all|"), N_("Delete specified job with or all jobs\n")}, {"lcd", cmd_lcd, N_("lcd "), N_("Change current local directory to . The previous local directory\n" "is stored as `-'. You can do `lcd -' to change the directory back.\n")}, {"lftp", cmd_lftp, N_("lftp [OPTS] "), N_("`lftp' is the first command executed by lftp after rc files\n" " -f execute commands from the file and exit\n" " -c execute the commands and exit\n" " --norc don't execute rc files from the home directory\n" " --help print this help and exit\n" " --version print lftp version and exit\n" "Other options are the same as in `open' command:\n" " -e execute the command just after selecting\n" " -u [,] use the user/password for authentication\n" " -p use the port for connection\n" " -s assign the connection to this slot\n" " -d switch on debugging mode\n" " host name, URL or bookmark name\n")}, {"ln", cmd_ln, N_("ln [-s] "), N_("Link to \n")}, {"lpwd", cmd_lpwd}, {"local", cmd_local}, {"login", ALIAS_FOR(user)}, {"ls", cmd_ls, N_("ls []"), N_("List remote files. You can redirect output of this command to file\n" "or via pipe to external command.\n" "By default, ls output is cached, to see new listing use `rels' or\n" "`cache flush'.\n" "See also `help cls'.\n")}, {"mget", cmd_get, N_("mget [OPTS] "), N_("Gets selected files with expanded wildcards\n" " -c continue, resume transfer\n" " -d create directories the same as in file names and get the\n" " files into them instead of current directory\n" " -E delete remote files after successful transfer\n" " -a use ascii mode (binary is the default)\n" " -O specifies base directory or URL where files should be placed\n")}, {"mirror", cmd_mirror, N_("mirror [OPTS] [remote [local]]"), HELP_IN_MODULE}, {"mkdir", cmd_mkdir, N_("mkdir [OPTS] "), N_("Make remote directories\n" " -p make all levels of path\n" " -f be quiet, suppress messages\n")}, {"module", cmd_module, N_("module name [args]"), N_("Load module (shared object). The module should contain function\n" " void module_init(int argc,const char *const *argv)\n" "If name contains a slash, then the module is searched in current\n" "directory, otherwise in directories specified by setting module:path.\n")}, {"more", cmd_cat, N_("more "), N_("Same as `cat | more'. if PAGER is set, it is used as filter\n")}, {"mput", cmd_get, N_("mput [OPTS] "), N_("Upload files with wildcard expansion\n" " -c continue, reput\n" " -d create directories the same as in file names and put the\n" " files into them instead of current directory\n" " -E delete local files after successful transfer (dangerous)\n" " -a use ascii mode (binary is the default)\n" " -O specifies base directory or URL where files should be placed\n")}, {"mrm", cmd_mrm, N_("mrm "), N_("Removes specified files with wildcard expansion\n")}, {"mv", cmd_mv, N_("mv "), N_("Rename to \n")}, {"mmv", cmd_mmv, N_("mmv [OPTS] "), N_("Move to with wildcard expansion\n" " -O specifies the target directory (alternative way)\n")}, {"nlist", cmd_ls, N_("[re]nlist []"), N_("List remote file names.\n" "By default, nlist output is cached, to see new listing use `renlist' or\n" "`cache flush'.\n")}, {"open", cmd_open, N_("open [OPTS] "), N_("Select a server, URL or bookmark\n" " -e execute the command just after selecting\n" " -u [,] use the user/password for authentication\n" " -p use the port for connection\n" " -s assign the connection to this slot\n" " -d switch on debugging mode\n" " host name, URL or bookmark name\n")}, {"pget", cmd_get, N_("pget [OPTS] [-o ]"), N_("Gets the specified file using several connections. This can speed up transfer,\n" "but loads the net heavily impacting other users. Use only if you really\n" "have to transfer the file ASAP.\n" "\nOptions:\n" " -c continue transfer. Requires .lftp-pget-status file.\n" " -n set maximum number of connections (default is is taken from\n" " pget:default-n setting)\n" " -O specifies base directory where files should be placed\n")}, {"put", cmd_get, N_("put [OPTS] [-o ]"), N_("Upload with remote name .\n" " -o specifies remote file name (default - basename of lfile)\n" " -c continue, reput\n" " it requires permission to overwrite remote files\n" " -E delete local files after successful transfer (dangerous)\n" " -a use ascii mode (binary is the default)\n" " -O specifies base directory or URL where files should be placed\n")}, {"pwd", cmd_pwd, "pwd [-p]", N_("Print current remote URL.\n" " -p show password\n")}, {"queue", cmd_queue, N_("queue [OPTS] []"), N_("\n" " queue [-n num] \n\n" "Add the command to queue for current site. Each site has its own command\n" "queue. `-n' adds the command before the given item in the queue. It is\n" "possible to queue up a running job by using command `queue wait '.\n" "\n" " queue --delete|-d [index or wildcard expression]\n\n" "Delete one or more items from the queue. If no argument is given, the last\n" "entry in the queue is deleted.\n" "\n" " queue --move|-m [index]\n\n" "Move the given items before the given queue index, or to the end if no\n" "destination is given.\n" "\n" "Options:\n" " -q Be quiet.\n" " -v Be verbose.\n" " -Q Output in a format that can be used to re-queue.\n" " Useful with --delete.\n" )}, {"quit", ALIAS_FOR(exit)}, {"quote", cmd_ls, N_("quote "), N_("Send the command uninterpreted. Use with caution - it can lead to\n" "unknown remote state and thus will cause reconnect. You cannot\n" "be sure that any change of remote state because of quoted command\n" "is solid - it can be reset by reconnect at any time.\n")}, {"recls", cmd_cls, 0, N_("recls []\n" "Same as `cls', but don't look in cache\n")}, {"reget", cmd_get, 0, N_("Usage: reget [OPTS] [-o ]\n" "Same as `get -c'\n")}, {"rels", cmd_ls, 0, N_("Usage: rels []\n" "Same as `ls', but don't look in cache\n")}, {"renlist", cmd_ls, 0, N_("Usage: renlist []\n" "Same as `nlist', but don't look in cache\n")}, {"repeat", cmd_repeat, N_("repeat [OPTS] [delay] [command]"), HELP_IN_MODULE}, {"reput", cmd_get, 0, N_("Usage: reput [-o ]\n" "Same as `put -c'\n")}, {"rm", cmd_rm, N_("rm [-r] [-f] "), N_("Remove remote files\n" " -r recursive directory removal, be careful\n" " -f work quietly\n")}, {"rmdir", cmd_rm, N_("rmdir [-f] "), N_("Remove remote directories\n")}, {"scache", cmd_scache, N_("scache []"), N_("List cached sessions or switch to specified session number\n")}, {"set", cmd_set, N_("set [OPT] [ []]"), N_("Set variable to given value. If the value is omitted, unset the variable.\n" "Variable name has format ``name/closure'', where closure can specify\n" "exact application of the setting. See lftp(1) for details.\n" "If set is called with no variable then only altered settings are listed.\n" "It can be changed by options:\n" " -a list all settings, including default values\n" " -d list only default values, not necessary current ones\n")}, {"shell", ALIAS_FOR2("!",shell)}, {"site", cmd_ls, N_("site "), N_("Execute site command and output the result\n" "You can redirect its output\n")}, {"sleep", cmd_sleep, 0, HELP_IN_MODULE}, {"slot", cmd_slot, 0, N_("Usage: slot [