29 #include <sys/types.h>
77 #include "configmake.h"
95 #ifdef MODULE_CMD_MIRROR
98 #ifdef MODULE_CMD_SLEEP
101 # define cmd_repeat 0
103 #ifdef MODULE_CMD_TORRENT
104 # define cmd_torrent 0
109 const struct CmdExec::cmd_rec
CmdExec::static_cmd_table[]=
111 {
"!", cmd_shell,
N_(
"!<shell-command>"),
112 N_(
"Launch shell or shell command\n")},
113 {
"(", cmd_subsh,
N_(
"(commands)"),
114 N_(
"Group commands together to be executed as one command\n"
115 "You can launch such a group in background\n")},
116 {
"?", cmd_help, 0,
"help"},
117 {
"alias", cmd_alias,
N_(
"alias [<name> [<value>]]"),
118 N_(
"Define or undefine alias <name>. If <value> omitted,\n"
119 "the alias is undefined, else is takes the value <value>.\n"
120 "If no argument is given the current aliases are listed.\n")},
121 {
"anon", cmd_anon, 0,
122 N_(
"anon - login anonymously (by default)\n")},
124 {
"bookmark",cmd_bookmark,
N_(
"bookmark [SUBCMD]"),
125 N_(
"bookmark command controls bookmarks\n\n"
126 "The following subcommands are recognized:\n"
127 " add <name> [<loc>] - add current place or given location to bookmarks\n"
128 " and bind to given name\n"
129 " del <name> - remove bookmark with the name\n"
130 " edit - start editor on bookmarks file\n"
131 " import <type> - import foreign bookmarks\n"
132 " list - list bookmarks (default)\n")},
133 {
"bye", cmd_exit, 0,
"exit"},
134 {
"cache", cmd_cache,
N_(
"cache [SUBCMD]"),
135 N_(
"cache command controls local memory cache\n\n"
136 "The following subcommands are recognized:\n"
137 " stat - print cache status (default)\n"
138 " on|off - turn on/off caching\n"
139 " flush - flush cache\n"
140 " size <lim> - set memory limit\n"
141 " expire <Nx> - set cache expiration time to N seconds (x=s)\n"
142 " minutes (x=m) hours (x=h) or days (x=d)\n")},
143 {
"cat", cmd_cat,
N_(
"cat [-b] <files>"),
144 N_(
"cat - output remote files to stdout (can be redirected)\n"
145 " -b use binary mode (ascii is the default)\n")},
146 {
"cd", cmd_cd,
N_(
"cd <rdir>"),
147 N_(
"Change current remote directory to <rdir>. The previous remote directory\n"
148 "is stored as `-'. You can do `cd -' to change the directory back.\n"
149 "The previous directory for each site is also stored on disk, so you can\n"
150 "do `open site; cd -' even after lftp restart.\n")},
151 {
"chmod", cmd_chmod,
N_(
"chmod [OPTS] mode file..."),
152 N_(
"Change the mode of each FILE to MODE.\n"
154 " -c, --changes - like verbose but report only when a change is made\n"
155 " -f, --quiet - suppress most error messages\n"
156 " -v, --verbose - output a diagnostic for every file processed\n"
157 " -R, --recursive - change files and directories recursively\n"
159 "MODE can be an octal number or symbolic mode (see chmod(1))\n")},
160 {
"close", cmd_close,
"close [-a]",
161 N_(
"Close idle connections. By default only with current server.\n"
162 " -a close idle connections with all servers\n")},
163 {
"cls", cmd_cls,
N_(
"[re]cls [opts] [path/][pattern]"),
164 N_(
"List remote files. You can redirect output of this command to file\n"
165 "or via pipe to external command.\n"
172 " -1 - single-column output\n"
173 " -a, --all - show dot files\n"
174 " -B, --basename - show basename of files only\n"
175 " --block-size=SIZ - use SIZ-byte blocks\n"
176 " -d, --directory - list directory entries instead of contents\n"
177 " -F, --classify - append indicator (one of /@) to entries\n"
178 " -h, --human-readable - print sizes in human readable format (e.g., 1K)\n"
179 " --si - likewise, but use powers of 1000 not 1024\n"
180 " -k, --kilobytes - like --block-size=1024\n"
181 " -l, --long - use a long listing format\n"
182 " -q, --quiet - don't show status\n"
183 " -s, --size - print size of each file\n"
184 " --filesize - if printing size, only print size for files\n"
185 " -i, --nocase - case-insensitive pattern matching\n"
186 " -I, --sortnocase - sort names case-insensitively\n"
187 " -D, --dirsfirst - list directories first\n"
188 " --sort=OPT - \"name\", \"size\", \"date\"\n"
189 " -S - sort by file size\n"
190 " --user, --group, --perms, --date, --linkcount, --links\n"
191 " - show individual fields\n"
192 " --time-style=STYLE - use specified time format\n"
194 "By default, cls output is cached, to see new listing use `recls' or\n"
197 "The variables cls-default and cls-completion-default can be used to\n"
198 "specify defaults for cls listings and completion listings, respectively.\n"
199 "For example, to make completion listings show file sizes, set\n"
200 "cls-completion-default to \"-s\".\n"
207 "Tips: Use --filesize with -D to pack the listing better. If you don't\n"
208 "always want to see file sizes, --filesize in cls-default will affect the\n"
209 "-s flag on the commandline as well. Add `-i' to cls-completion-default\n"
210 "to make filename completion case-insensitive.\n"
212 {
"connect", cmd_open, 0,
"open"},
213 {
"command", cmd_command},
214 {
"debug", cmd_debug,
N_(
"debug [<level>|off] [-o <file>]"),
215 N_(
"Set debug level to given value or turn debug off completely.\n"
216 " -o <file> redirect debug output to the file.\n")},
217 {
"du", cmd_du,
N_(
"du [options] <dirs>"),
218 N_(
"Summarize disk usage.\n"
219 " -a, --all write counts for all files, not just directories\n"
220 " --block-size=SIZ use SIZ-byte blocks\n"
221 " -b, --bytes print size in bytes\n"
222 " -c, --total produce a grand total\n"
223 " -d, --max-depth=N print the total for a directory (or file, with --all)\n"
224 " only if it is N or fewer levels below the command\n"
225 " line argument; --max-depth=0 is the same as\n"
227 " -F, --files print number of files instead of sizes\n"
228 " -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)\n"
229 " -H, --si likewise, but use powers of 1000 not 1024\n"
230 " -k, --kilobytes like --block-size=1024\n"
231 " -m, --megabytes like --block-size=1048576\n"
232 " -S, --separate-dirs do not include size of subdirectories\n"
233 " -s, --summarize display only a total for each argument\n"
234 " --exclude=PAT exclude files that match PAT\n")},
235 {
"echo", cmd_echo, 0},
236 {
"eval", cmd_eval, 0},
237 {
"exit", cmd_exit,
N_(
"exit [<code>|bg]"),
238 N_(
"exit - exit from lftp or move to background if jobs are active\n\n"
239 "If no jobs active, the code is passed to operating system as lftp\n"
240 "termination status. If omitted, exit code of last command is used.\n"
241 "`bg' forces moving to background if cmd:move-background is false.\n")},
242 {
"fg", cmd_wait, 0,
"wait"},
244 N_(
"Usage: find [OPTS] [directory]\n"
245 "Print contents of specified directory or current directory recursively.\n"
246 "Directories in the list are marked with trailing slash.\n"
247 "You can redirect output of this command.\n"
248 " -d, --maxdepth=LEVELS Descend at most LEVELS of directories.\n")},
249 {
"get", cmd_get,
N_(
"get [OPTS] <rfile> [-o <lfile>]"),
250 N_(
"Retrieve remote file <rfile> and store it to local file <lfile>.\n"
251 " -o <lfile> specifies local file name (default - basename of rfile)\n"
252 " -c continue, resume transfer\n"
253 " -E delete remote files after successful transfer\n"
254 " -a use ascii mode (binary is the default)\n"
255 " -O <base> specifies base directory or URL where files should be placed\n")},
256 {
"get1", cmd_get1, 0,0},
257 {
"glob", cmd_glob,
N_(
"glob [OPTS] <cmd> <args>"),
259 "Expand wildcards and run specified command.\n"
260 "Options can be used to expand wildcards to list of files, directories,\n"
261 "or both types. Type selection is not very reliable and depends on server.\n"
262 "If entry type cannot be determined, it will be included in the list.\n"
263 " -f plain files (default)\n"
266 {
"help", cmd_help,
N_(
"help [<cmd>]"),
267 N_(
"Print help for command <cmd>, or list of available commands\n")},
268 {
"jobs", cmd_jobs,
"jobs [-v] [<job_no...>]",
269 N_(
"List running jobs. -v means verbose, several -v can be specified.\n"
270 "If <job_no> is specified, only list a job with that number.\n")},
271 {
"kill", cmd_kill,
N_(
"kill all|<job_no>"),
272 N_(
"Delete specified job with <job_no> or all jobs\n")},
273 {
"lcd", cmd_lcd,
N_(
"lcd <ldir>"),
274 N_(
"Change current local directory to <ldir>. The previous local directory\n"
275 "is stored as `-'. You can do `lcd -' to change the directory back.\n")},
276 {
"lftp", cmd_lftp,
N_(
"lftp [OPTS] <site>"),
277 N_(
"`lftp' is the first command executed by lftp after rc files\n"
278 " -f <file> execute commands from the file and exit\n"
279 " -c <cmd> execute the commands and exit\n"
280 " --help print this help and exit\n"
281 " --version print lftp version and exit\n"
282 "Other options are the same as in `open' command\n"
283 " -e <cmd> execute the command just after selecting\n"
284 " -u <user>[,<pass>] use the user/password for authentication\n"
285 " -p <port> use the port for connection\n"
286 " <site> host name, URL or bookmark name\n")},
287 {
"ln", cmd_ln,
N_(
"ln [-s] <file1> <file2>"),
288 N_(
"Link <file1> to <file2>\n")},
290 {
"local", cmd_local},
291 {
"login", cmd_user, 0,
"user"},
292 {
"ls", cmd_ls,
N_(
"ls [<args>]"),
293 N_(
"List remote files. You can redirect output of this command to file\n"
294 "or via pipe to external command.\n"
295 "By default, ls output is cached, to see new listing use `rels' or\n"
297 "See also `help cls'.\n")},
298 {
"mget", cmd_get,
N_(
"mget [OPTS] <files>"),
299 N_(
"Gets selected files with expanded wildcards\n"
300 " -c continue, resume transfer\n"
301 " -d create directories the same as in file names and get the\n"
302 " files into them instead of current directory\n"
303 " -E delete remote files after successful transfer\n"
304 " -a use ascii mode (binary is the default)\n"
305 " -O <base> specifies base directory or URL where files should be placed\n")},
306 {
"mirror", cmd_mirror,
N_(
"mirror [OPTS] [remote [local]]"),
307 N_(
"\nMirror specified remote directory to local directory\n\n"
308 " -c, --continue continue a mirror job if possible\n"
309 " -e, --delete delete files not present at remote site\n"
310 " --delete-first delete old files before transferring new ones\n"
311 " -s, --allow-suid set suid/sgid bits according to remote site\n"
312 " --allow-chown try to set owner and group on files\n"
313 " --ignore-time ignore time when deciding whether to download\n"
314 " -n, --only-newer download only newer files (-c won't work)\n"
315 " -r, --no-recursion don't go to subdirectories\n"
316 " -p, --no-perms don't set file permissions\n"
317 " --no-umask don't apply umask to file modes\n"
318 " -R, --reverse reverse mirror (put files)\n"
319 " -L, --dereference download symbolic links as files\n"
320 " -N, --newer-than=SPEC download only files newer than specified time\n"
321 " -P, --parallel[=N] download N files in parallel\n"
322 " -i RX, --include RX include matching files\n"
323 " -x RX, --exclude RX exclude matching files\n"
324 " RX is extended regular expression\n"
325 " -v, --verbose[=N] verbose operation\n"
326 " --log=FILE write lftp commands being executed to FILE\n"
327 " --script=FILE write lftp commands to FILE, but don't execute them\n"
328 " --just-print, --dry-run same as --script=-\n"
330 "When using -R, the first directory is local and the second is remote.\n"
331 "If the second directory is omitted, basename of first directory is used.\n"
332 "If both directories are omitted, current local and remote directories are used.\n"
334 {
"mkdir", cmd_mkdir,
N_(
"mkdir [-p] <dirs>"),
335 N_(
"Make remote directories\n"
336 " -p make all levels of path\n")},
337 {
"module", cmd_module,
N_(
"module name [args]"),
338 N_(
"Load module (shared object). The module should contain function\n"
339 " void module_init(int argc,const char *const *argv)\n"
340 "If name contains a slash, then the module is searched in current\n"
341 "directory, otherwise in directories specified by setting module:path.\n")},
342 {
"more", cmd_cat,
N_(
"more <files>"),
343 N_(
"Same as `cat <files> | more'. if PAGER is set, it is used as filter\n")},
344 {
"mput", cmd_get,
N_(
"mput [OPTS] <files>"),
345 N_(
"Upload files with wildcard expansion\n"
346 " -c continue, reput\n"
347 " -d create directories the same as in file names and put the\n"
348 " files into them instead of current directory\n"
349 " -E delete local files after successful transfer (dangerous)\n"
350 " -a use ascii mode (binary is the default)\n"
351 " -O <base> specifies base directory or URL where files should be placed\n")},
352 {
"mrm", cmd_mrm,
N_(
"mrm <files>"),
353 N_(
"Removes specified files with wildcard expansion\n")},
354 {
"mv", cmd_mv,
N_(
"mv <file1> <file2>"),
355 N_(
"Rename <file1> to <file2>\n")},
356 {
"nlist", cmd_ls,
N_(
"[re]nlist [<args>]"),
357 N_(
"List remote file names.\n"
358 "By default, nlist output is cached, to see new listing use `renlist' or\n"
359 "`cache flush'.\n")},
360 {
"open", cmd_open,
N_(
"open [OPTS] <site>"),
361 N_(
"Select a server, URL or bookmark\n"
362 " -e <cmd> execute the command just after selecting\n"
363 " -u <user>[,<pass>] use the user/password for authentication\n"
364 " -p <port> use the port for connection\n"
365 " -s <slot> assign the connection to this slot\n"
366 " <site> host name, URL or bookmark name\n")},
367 {
"pget", cmd_get,
N_(
"pget [OPTS] <rfile> [-o <lfile>]"),
368 N_(
"Gets the specified file using several connections. This can speed up transfer,\n"
369 "but loads the net heavily impacting other users. Use only if you really\n"
370 "have to transfer the file ASAP.\n"
372 " -c continue transfer. Requires <lfile>.lftp-pget-status file.\n"
373 " -n <maxconn> set maximum number of connections (default is is taken from\n"
374 " pget:default-n setting)\n"
375 " -O <base> specifies base directory where files should be placed\n")},
376 {
"put", cmd_get,
N_(
"put [OPTS] <lfile> [-o <rfile>]"),
377 N_(
"Upload <lfile> with remote name <rfile>.\n"
378 " -o <rfile> specifies remote file name (default - basename of lfile)\n"
379 " -c continue, reput\n"
380 " it requires permission to overwrite remote files\n"
381 " -E delete local files after successful transfer (dangerous)\n"
382 " -a use ascii mode (binary is the default)\n"
383 " -O <base> specifies base directory or URL where files should be placed\n")},
384 {
"pwd", cmd_pwd,
"pwd [-p]",
385 N_(
"Print current remote URL.\n"
386 " -p show password\n")},
387 {
"queue", cmd_queue,
N_(
"queue [OPTS] [<cmd>]"),
389 " queue [-n num] <command>\n\n"
390 "Add the command to queue for current site. Each site has its own command\n"
391 "queue. `-n' adds the command before the given item in the queue. It is\n"
392 "possible to queue up a running job by using command `queue wait <jobno>'.\n"
394 " queue --delete|-d [index or wildcard expression]\n\n"
395 "Delete one or more items from the queue. If no argument is given, the last\n"
396 "entry in the queue is deleted.\n"
398 " queue --move|-m <index or wildcard expression> [index]\n\n"
399 "Move the given items before the given queue index, or to the end if no\n"
400 "destination is given.\n"
405 " -Q Output in a format that can be used to re-queue.\n"
406 " Useful with --delete.\n"
408 {
"quit", cmd_exit, 0,
"exit"},
409 {
"quote", cmd_ls,
N_(
"quote <cmd>"),
410 N_(
"Send the command uninterpreted. Use with caution - it can lead to\n"
411 "unknown remote state and thus will cause reconnect. You cannot\n"
412 "be sure that any change of remote state because of quoted command\n"
413 "is solid - it can be reset by reconnect at any time.\n")},
414 {
"recls", cmd_cls, 0,
415 N_(
"recls [<args>]\n"
416 "Same as `cls', but don't look in cache\n")},
417 {
"reget", cmd_get, 0,
418 N_(
"Usage: reget [OPTS] <rfile> [-o <lfile>]\n"
419 "Same as `get -c'\n")},
421 N_(
"Usage: rels [<args>]\n"
422 "Same as `ls', but don't look in cache\n")},
423 {
"renlist", cmd_ls, 0,
424 N_(
"Usage: renlist [<args>]\n"
425 "Same as `nlist', but don't look in cache\n")},
426 {
"repeat",
cmd_repeat,
N_(
"repeat [OPTS] [delay] [command]"),
427 N_(
"Repeat specified command with a delay between iterations.\n"
428 "Default delay is one second, default command is empty.\n"
429 " -c <count> maximum number of iterations\n"
430 " -d <delay> delay between iterations\n"
431 " --while-ok stop when command exits with non-zero code\n"
432 " --until-ok stop when command exits with zero code\n"
433 " --weak stop when lftp moves to background.\n")},
434 {
"reput", cmd_get, 0,
435 N_(
"Usage: reput <lfile> [-o <rfile>]\n"
436 "Same as `put -c'\n")},
437 {
"rm", cmd_rm,
N_(
"rm [-r] [-f] <files>"),
438 N_(
"Remove remote files\n"
439 " -r recursive directory removal, be careful\n"
440 " -f work quietly\n")},
441 {
"rmdir", cmd_rm,
N_(
"rmdir [-f] <dirs>"),
442 N_(
"Remove remote directories\n")},
443 {
"scache", cmd_scache,
N_(
"scache [<session_no>]"),
444 N_(
"List cached sessions or switch to specified session number\n")},
445 {
"set", cmd_set,
N_(
"set [OPT] [<var> [<val>]]"),
446 N_(
"Set variable to given value. If the value is omitted, unset the variable.\n"
447 "Variable name has format ``name/closure'', where closure can specify\n"
448 "exact application of the setting. See lftp(1) for details.\n"
449 "If set is called with no variable then only altered settings are listed.\n"
450 "It can be changed by options:\n"
451 " -a list all settings, including default values\n"
452 " -d list only default values, not necessary current ones\n")},
453 {
"shell", cmd_shell, 0,
"!"},
454 {
"site", cmd_ls,
N_(
"site <site-cmd>"),
455 N_(
"Execute site command <site_cmd> and output the result\n"
456 "You can redirect its output\n")},
458 N_(
"Usage: sleep <time>[unit]\n"
459 "Sleep for given amount of time. The time argument can be optionally\n"
460 "followed by unit specifier: d - days, h - hours, m - minutes, s - seconds.\n"
461 "By default time is assumed to be seconds.\n")},
462 {
"slot", cmd_slot, 0,
463 N_(
"Usage: slot [<label>]\n"
464 "List assigned slots.\n"
465 "If <label> is specified, switch to the slot named <label>.\n")},
466 {
"source", cmd_source,
N_(
"source <file>"),
467 N_(
"Execute commands recorded in file <file>\n")},
468 {
"suspend", cmd_suspend},
469 {
"torrent", cmd_torrent,
N_(
"torrent [-O <dir>] <file|URL>...")},
470 {
"user", cmd_user,
N_(
"user <user|URL> [<pass>]"),
471 N_(
"Use specified info for remote login. If you specify URL, the password\n"
472 "will be cached for future usage.\n")},
473 {
"version", cmd_ver, 0,
474 N_(
"Shows lftp version\n")},
475 {
"wait", cmd_wait,
N_(
"wait [<jobno>]"),
476 N_(
"Wait for specified job to terminate. If jobno is omitted, wait\n"
477 "for last backgrounded job.\n")},
478 {
"zcat", cmd_cat,
N_(
"zcat <files>"),
479 N_(
"Same as cat, but filter each file through zcat\n")},
480 {
"zmore", cmd_cat,
N_(
"zmore <files>"),
481 N_(
"Same as more, but filter each file through zcat\n")},
482 {
"bzcat", cmd_cat, 0,
483 N_(
"Same as cat, but filter each file through bzcat\n")},
484 {
"bzmore", cmd_cat, 0,
485 N_(
"Same as more, but filter each file through bzcat\n")},
487 {
".tasks", cmd_tasks, 0,0},
489 const int CmdExec::static_cmd_table_length=
sizeof(static_cmd_table)/
sizeof(static_cmd_table[0]);
491 #define charcasecmp(a,b) (tolower((unsigned char)(a))-tolower((unsigned char)(b)))
496 int find_command(
const char *unprec_name,
const char *
const *names,
500 for( ; *names; names++)
503 for(s=*names,u=unprec_name; *s && !
charcasecmp(*u,*s); s++,u++)
541 if(!strcmp(cd_to,
"-"))
553 eprintf(
"No current local directory, use absolute path.\n");
558 int res=chdir(cd_to);
572 eprintf(
_(
"lcd ok, local cwd=%s\n"),name?name:
"?");
588 eprintf(
_(
"Usage: cd remote-dir\n"));
611 bool same_site=
session->SameSiteAs(new_session);
629 else if(cache_is_dir==0)
634 new_cwd.
Change(dir,is_file);
666 if(!strcmp(a,
"top") || !strcmp(a,
"bg"))
669 exec=
top.get_non_const();
671 else if(!strcmp(a,
"kill"))
676 else if(sscanf(a,
"%i",&code)!=1)
687 "There are running jobs and `cmd:move-background' is not set.\n"
688 "Use `exit bg' to force moving to background or `kill all' to terminate jobs.\n"
703 "lftp now tricks the shell to move it to background process group.\n"
704 "lftp continues to run in the background despite the `Stopped' message.\n"
705 "lftp will automatically terminate when all jobs are finished.\n"
706 "Use `fg' shell command to return to lftp if it is still running.\n"
709 switch(pid_t pid=fork()) {
712 ::kill(getppid(),SIGCONT);
747 static struct option lftp_options[]=
760 cmd.
set(
"help lftp;");
788 if(
Done() && lftp_feeder)
810 const char *port=
NULL;
811 const char *host=
NULL;
812 const char *path=
NULL;
813 const char *user=
NULL;
814 const char *pass=
NULL;
818 const char *op=
args->
a0();
826 static struct option open_options[]=
880 if(!strcmp(op,
"lftp"))
886 if(!strcmp(op,
"lftp"))
887 eprintf(
_(
"Try `%s --help' for more information\n"),op);
889 eprintf(
_(
"Usage: %s [-e cmd] [-p port] [-u user[,pass]] <host|url>\n"),
895 if(optind<args->count())
940 bool no_proto=(!url->
proto);
942 if(no_proto && url->
host)
984 _(
" - not supported protocol"));
993 if(!pass && (user || no_proto))
1007 else if(host && !host[0])
1011 if(host && host[0] &&
session->GetHostName()==0)
1018 eprintf(
_(
"%s: GetPass() failed -- assume anonymous login\n"),
1024 session->SetPasswordGlobal(pass);
1025 session->InsecurePassword(insecure && !no_bm);
1033 builtin=BUILTIN_OPEN;
1046 const char *old_url=0;
1080 if(builtin==BUILTIN_OPEN)
1083 ReuseSavedSession();
1091 builtin=BUILTIN_EXEC_RESTART;
1097 const char *op=
args->
a0();
1115 eprintf(
_(
"Try `help %s' for more information.\n"),op);
1123 eprintf(
_(
"Usage: %s [OPTS] command args...\n"),op);
1126 assert(args_glob==0 &&
glob==0);
1127 args_glob=
new ArgV();
1135 return cmd_command(
this);
1138 RevertToSavedSession();
1139 builtin=BUILTIN_GLOB;
1145 static struct option queue_options[]=
1154 enum { ins, del, move } mode = ins;
1156 const char *arg =
NULL;
1171 if(!isdigit((
unsigned char)
optarg[0]) || atoi(
optarg) == 0)
1210 if(mode == ins || mode == move)
1219 CmdExec *queue=GetQueue(
false);
1220 if(args_remaining==0)
1225 printf(
_(
"Created a stopped queue.\n"));
1226 queue=GetQueue(
true);
1239 queue=GetQueue(
true);
1266 CmdExec *queue=GetQueue(
false);
1274 else if(atoi(arg) != 0)
1287 if(a1 && !isdigit((
unsigned char)a1[0])) {
1288 eprintf(
_(
"%s: -m: Number expected as second argument. "),
args->
a0());
1292 int to = a1? atoi(a1)-1:-1;
1294 CmdExec *queue=GetQueue(
false);
1300 if(atoi(arg) != 0) {
1314 #define args (parent->args)
1315 #define exit_code (parent->exit_code)
1316 #define output (parent->output)
1317 #define session (parent->session)
1318 #define eprintf parent->eprintf
1322 return parent->builtin_lcd();
1330 const char *op=
args->a0();
1334 if(!strncmp(op,
"re",2))
1336 if(!strcmp(op,
"quote") || !strcmp(op,
"site"))
1338 if(
args->count()<=1)
1340 eprintf(
_(
"Usage: %s <cmd>\n"),op);
1346 if(!strcmp(op,
"site"))
1347 args->insarg(1,
"SITE");
1353 if(!nlist &&
args->count()==1 && var_ls[0])
1354 args->Append(var_ls);
1403 static struct option cls_options[] = {
1434 while((opt=a->
getopt_long(
":a1BdFhiklqsDISrt", cls_options))!=EOF)
1442 else return _(
"invalid argument for `--sort'");
1469 case OPT_BLOCK_SIZE:
1472 return _(
"invalid block size");
1523 case OPT_TIME_STYLE:
1533 if(time_style && time_style[0]) {
1536 if(time_style[0]==
'+')
1538 else if(!strcmp(time_style,
"full-iso"))
1541 else if(!strcmp(time_style,
"long-iso"))
1543 else if(!strcmp(time_style,
"iso"))
1561 const char *op=
args->a0();
1568 if(!strncmp(op,
"re",2))
1575 eprintf(
_(
"Try `help %s' for more information.\n"),op);
1588 const char *op=
args->a0();
1591 bool auto_ascii=
true;
1593 while((opt=
args->getopt(
"+bau"))!=EOF)
1606 eprintf(
_(
"Try `help %s' for more information.\n"),op);
1610 while(
args->getindex()>1)
1613 if(
args->count()<=1)
1615 eprintf(
_(
"Usage: %s [OPTS] files...\n"),op);
1634 const char *opts=
"+cEeuaO:";
1635 const char *op=
args->a0();
1639 bool del_target=
false;
1642 bool make_dirs=
false;
1646 if(!strncmp(op,
"re",2))
1651 if(!strcmp(op,
"pget"))
1656 else if(!strcmp(op,
"put") || !strcmp(op,
"reput"))
1660 else if(!strcmp(op,
"mget"))
1665 else if(!strcmp(op,
"mput"))
1677 while((opt=
args->getopt(opts))!=EOF)
1685 if(!isdigit((
unsigned char)
optarg[0]))
1687 eprintf(
_(
"%s: -n: Number expected. "),op);
1709 eprintf(
_(
"Try `help %s' for more information.\n"),op);
1716 if(
args->getcurr()==0)
1725 while(
args->getindex()>1)
1739 const char *
a=
args->getnext();
1741 goto file_name_missed;
1747 if(a && !strcmp(a,
"-o"))
1749 dst=
args->getnext();
1776 if(
args->count()<=1)
1788 args->setarg(0,
"glob");
1789 args->insarg(1,
"rm");
1790 return parent->builtin_restart();
1797 const char *opts=
"+rf";
1800 if(!strcmp(
args->a0(),
"rmdir"))
1806 while((opt=
args->getopt(opts))!=EOF)
1818 eprintf(
_(
"Usage: %s %s[-f] files...\n"),
args->a0(), rmdir?
"":
"[-r] ");
1823 if(
args->getcurr()==0)
1851 while((opt=
args->getopt(
"+e"))!=EOF)
1861 eprintf(
_(
"Usage: %s [-e] <file|command>\n"),
args->a0());
1865 if(
args->getindex()>=
args->count())
1895 while((opt=
args->getopt(
"+v"))!=EOF)
1910 const char *op=
args->a0();
1911 const char *arg=
args->getnext();
1914 parent->top->FormatJobs(s,v);
1916 for(; arg; arg=
args->getnext()) {
1917 if(!isdigit((
unsigned char)*arg)) {
1918 eprintf(
_(
"%s: %s - not a number\n"),op,arg);
1923 Job *
j=parent->FindJob(n);
1925 eprintf(
_(
"%s: %d - no such job\n"),op,n);
1941 return parent->builtin_cd();
1948 while((opt=
args->getopt(
"p"))!=EOF)
1953 flags|=FA::WITH_PASSWORD;
1961 const char *url_c=
session->GetConnectURL(flags);
1963 int len=strlen(url_c);
1974 return parent->builtin_exit();
1979 const char *op=
args->a0();
1981 char *debug_file_name=0;
1984 bool show_pid=
false;
1985 bool show_time=
false;
1986 bool show_context=
false;
1989 while((opt=
args->getopt(
"o:ptc"))!=EOF)
1997 fd=
open(debug_file_name,O_WRONLY|O_CREAT|O_APPEND,0600);
2000 perror(debug_file_name);
2016 eprintf(
_(
"Try `help %s' for more information.\n"),op);
2026 const char *
a=
args->getcurr();
2058 printf(
_(
"debug level is %d, output goes to %s\n"),new_dlevel,
2059 debug_file_name?debug_file_name:
"<stderr>");
2061 printf(
_(
"debug is off\n"));
2070 if(
args->count()<2 ||
args->count()>3)
2072 eprintf(
_(
"Usage: %s <user|URL> [<pass>]\n"),
args->getarg(0));
2075 const char *user=
args->getarg(1);
2076 const char *pass=
args->getarg(2);
2077 bool insecure=(pass!=0);
2097 FA *
s=FA::New(&u,
false);
2100 s->SetPasswordGlobal(pass);
2101 s->InsecurePassword(insecure);
2107 _(
" - not supported protocol"));
2114 session->SetPasswordGlobal(pass);
2115 session->InsecurePassword(insecure);
2129 return parent->builtin_lftp();
2134 return parent->builtin_open();
2140 const char *op=
args->a0();
2143 #if 0 // too dangerous to kill last job. Better require explicit number.
2147 eprintf(
_(
"%s: no current job\n"),op);
2150 printf(
"%s %d\n",op,n);
2157 eprintf(
_(
"%s: %d - no such job\n"),op,n);
2159 eprintf(
_(
"Usage: %s <jobno> ... | all\n"),
args->getarg(0));
2173 const char *arg=
args->getnext();
2176 if(!isdigit((
unsigned char)arg[0]))
2178 eprintf(
_(
"%s: %s - not a number\n"),op,arg);
2187 eprintf(
_(
"%s: %d - no such job\n"),op,n);
2196 const char *op=
args->a0();
2197 bool with_defaults=
false;
2198 bool only_defaults=
false;
2201 while((c=
args->getopt(
"+ad"))!=EOF)
2212 eprintf(
_(
"Try `help %s' for more information.\n"),op);
2217 const char *ac=
args->getnext();
2241 eprintf(
_(
"%s: %s. Use `set -a' to look at all variables.\n"),a,msg);
2267 else if(
args->count()==2)
2282 const char *op=
args->a0();
2285 eprintf(
_(
"Usage: %s [<jobno>]\n"),op);
2289 const char *jn=
args->getnext();
2294 parent->WaitForAllChildren();
2295 parent->AllWaitingFg();
2299 if(!isdigit((
unsigned char)jn[0]))
2301 eprintf(
_(
"%s: %s - not a number\n"),op,jn);
2311 eprintf(
_(
"%s: no current job\n"),op);
2314 printf(
"%s %d\n",op,n);
2316 Job *
j=parent->FindJob(n);
2319 eprintf(
_(
"%s: %d - no such job\n"),op,n);
2324 eprintf(
_(
"%s: some other job waits for job %d\n"),op,n);
2327 if(j->Job::CheckForWaitLoop(parent))
2329 eprintf(
_(
"%s: wait loop detected\n"),op);
2341 const char *
c=
args->getarg(1);
2350 if(
args->count()!=3)
2353 eprintf(
_(
"Usage: mv <file1> <file2>\n"));
2362 FA::open_mode
m=FA::LINK;
2363 const char *op=
args->a0();
2365 while((c=
args->getopt(
"+s"))!=EOF)
2374 eprintf(
_(
"Try `help %s' for more information.\n"),op);
2379 const char *file1=
args->getnext();
2380 const char *file2=
args->getnext();
2381 if(!file1 || !file2)
2388 "status",
"flush",
"on",
"off",
"size",
"expire",
2394 const char *op=
args->getnext();
2398 else if(!find_command(op,cache_subcmd,&op))
2402 eprintf(
_(
"Try `help %s' for more information.\n"),
args->a0());
2409 eprintf(
_(
"Try `help %s' for more information.\n"),
args->a0());
2427 eprintf(
_(
"%s: Operand missed for size\n"),
args->a0());
2444 eprintf(
_(
"%s: Operand missed for `expire'\n"),
args->a0());
2461 if(
args->count()==1)
2468 const char *
a=
args->getarg(1);
2469 if(!isdigit((
unsigned char)a[0]))
2477 eprintf(
_(
"%s: %s - no such cached session. Use `scache' to look at session list.\n"),
args->a0(),
a);
2480 parent->ChangeSession(new_session);
2488 int part=find_cmd(cmd,&c);
2492 if(c->long_desc==0 && c->short_desc==0)
2494 printf(
_(
"Sorry, no help for %s\n"),cmd);
2497 if(c->short_desc==0 && !
strchr(c->long_desc,
' '))
2499 printf(
_(
"%s is a built-in alias for %s\n"),cmd,c->long_desc);
2504 printf(
_(
"Usage: %s\n"),
_(c->short_desc));
2512 printf(
_(
"%s is an alias to `%s'\n"),cmd,a);
2516 printf(
_(
"No such command `%s'. Use `help' to see available commands.\n"),cmd);
2518 printf(
_(
"Ambiguous command `%s'. Use `help' to see available commands.\n"),cmd);
2524 const cmd_rec *cmd_table=dyn_cmd_table?dyn_cmd_table.
get():static_cmd_table;
2525 const int count=dyn_cmd_table?dyn_cmd_table.
count():static_cmd_table_length;
2529 const int first_align=4;
2532 while(i<count && !cmd_table[i].short_desc)
2536 const char *c1=
gettext(cmd_table[i].short_desc);
2542 pad=first_align-pos;
2543 else if(pos>first_align)
2544 pad=align-(pos-first_align)%align;
2545 if(pos>first_align && pos+pad+w1>=width) {
2551 printf(
"%*s%s",pad,
"",c1);
2564 const char *cmd=
args->getnext();
2567 parent->print_cmd_help(cmd);
2572 parent->print_cmd_index();
2581 _(
"LFTP | Version %s | Copyright (c) 1996-%d Alexander V. Lukyanov\n"),VERSION,2013);
2584 _(
"LFTP is free software: you can redistribute it and/or modify\n"
2585 "it under the terms of the GNU General Public License as published by\n"
2586 "the Free Software Foundation, either version 3 of the License, or\n"
2587 "(at your option) any later version.\n"
2589 "This program is distributed in the hope that it will be useful,\n"
2590 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
2591 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
2592 "GNU General Public License for more details.\n"
2594 "You should have received a copy of the GNU General Public License\n"
2595 "along with LFTP. If not, see <http://www.gnu.org/licenses/>.\n"));
2598 _(
"Send bug reports and questions to the mailing list <%s>.\n"),
"lftp@uniyar.ac.ru");
2600 #if defined(HAVE_DLOPEN) && defined(RTLD_DEFAULT)
2604 const char *msg=
_(
"Libraries used: ");
2607 int width=parent->status_line?parent->status_line->GetWidth():80;
2612 const char *lib_name;
2614 enum type_t { STRING_PTR, FUNC0, INT8_8 } type;
2615 const char *skip_prefix;
2616 typedef const char *(*func0)(int);
2617 const char *query()
const
2620 void *sym_ptr=dlsym(RTLD_DEFAULT,symbol);
2627 str=*(
const char**)sym_ptr;
2630 str=((func0)sym_ptr)(0);
2638 if(skip_prefix && !strncmp(str,skip_prefix,strlen(skip_prefix)))
2639 str+=strlen(skip_prefix);
2643 static const libs[]=
2645 {
"Readline",
"rl_library_version", VersionInfo::STRING_PTR,0},
2646 {
"Expat",
"XML_ExpatVersion", VersionInfo::FUNC0,
"expat_"},
2647 {
"OpenSSL",
"SSL_version_str", VersionInfo::STRING_PTR,
"OpenSSL "},
2648 {
"GnuTLS",
"gnutls_check_version", VersionInfo::FUNC0, 0},
2649 {
"libiconv",
"_libiconv_version", VersionInfo::INT8_8, 0},
2650 {
"zlib",
"zlibVersion", VersionInfo::FUNC0, 0},
2654 bool need_comma=
false;
2655 for(
const VersionInfo *scan=libs; scan->lib_name; scan++)
2657 const char *v=scan->query();
2661 snprintf(buf,
sizeof(buf),
", %s %s",scan->lib_name,v);
2662 int skip=need_comma?0:2;
2672 printf(
"%s",buf+skip);
2676 #endif // HAVE_DLOPEN
2684 const char *op=
args->a0();
2687 while((opt=
args->getopt(
"a"))!=EOF)
2695 eprintf(
_(
"Try `help %s' for more information.\n"),op);
2708 {
"add",
"delete",
"list",
"list-p",
"edit",
"import",0};
2709 static ResDecl res_save_passwords
2714 const char *op=
args->getnext();
2718 else if(!find_command(op,bookmark_subcmd,&op))
2722 eprintf(
_(
"Try `help %s' for more information.\n"),
args->a0());
2729 eprintf(
_(
"Try `help %s' for more information.\n"),
args->a0());
2742 const char *key=
args->getnext();
2743 if(key==0 || key[0]==0)
2747 const char *value=
args->getnext();
2750 flags|=
session->WITH_PASSWORD;
2753 value=
session->GetConnectURL(flags);
2760 if(value==0 || value[0]==0)
2764 eprintf(
_(
"%s: spaces in bookmark name are not allowed\n"),
args->a0());
2773 const char *key=
args->getnext();
2774 if(key==0 || key[0]==0)
2777 eprintf(
_(
"%s: no such bookmark `%s'\n"),
args->a0(),key);
2787 parent->PrependCmd(
"shell \"/bin/sh -c 'exec ${EDITOR:-vi} ${LFTP_HOME:-$HOME/.lftp}/bookmarks'\"\n");
2793 eprintf(
_(
"%s: import type required (netscape,ncftp)\n"),
args->a0());
2796 parent->PrependCmd(
xstring::cat(
"shell " PKGDATADIR
"/import-",op,
"\n",
NULL));
2817 if(
args->count()>1 && !strcmp(
args->getarg(1),
"-n"))
2838 kill(getpid(),SIGSTOP);
2844 static struct option find_options[]=
2851 const char *op=
args->a0();
2853 while((opt=
args->getopt_long(
"+d:",find_options))!=EOF)
2858 if(!isdigit((
unsigned char)*
optarg))
2866 eprintf(
_(
"Usage: %s [-d #] dir\n"),op);
2871 if(!
args->getcurr())
2884 static struct option du_options[]=
2905 bool max_depth_specified =
false;
2906 int blocksize = 1024;
2907 bool separate_dirs =
false;
2908 bool summarize_only =
false;
2909 bool print_totals=
false;
2910 bool all_files=
false;
2911 bool file_count=
false;
2912 const char *exclude=0;
2917 const char *op=
args->a0();
2920 while((opt=
args->getopt_long(
"+abcd:FhHkmsS",du_options))!=EOF)
2934 if(!isdigit((
unsigned char)*
optarg))
2940 max_depth_specified =
true;
2957 blocksize = 1024*1024;
2960 summarize_only =
true;
2963 separate_dirs =
true;
2965 case OPT_BLOCK_SIZE:
2966 blocksize = atoi(
optarg);
2978 eprintf(
_(
"Usage: %s [options] <dirs>\n"),op);
2983 if (summarize_only && max_depth_specified && maxdepth == 0)
2984 eprintf(
_(
"%s: warning: summarizing is the same as using --max-depth=0\n"), op);
2986 if (summarize_only && max_depth_specified && maxdepth != 0)
2988 eprintf(
_(
"%s: summarizing conflicts with --max-depth=%i\n"), op, maxdepth);
2996 if (file_count && all_files)
3006 if(!
args->getcurr())
3021 if(separate_dirs && maxdepth != -1)
3040 return parent->builtin_restart();
3045 const char *
op=
args->a0();
3049 eprintf(
_(
"Try `help %s' for more information.\n"),op);
3066 eprintf(
"%s: %s\n",
args->a0(),
_(
"cannot get current directory"));
3069 const char *name=
parent->cwd->GetName();
3077 return parent->builtin_local();
3082 return parent->builtin_glob();
3088 bool recurse =
false,
quiet =
false;
3090 static struct option chmod_options[]=
3102 while((opt=
args->getopt_long(
"vcRfrwxXstugoa,+-=",chmod_options))!=EOF)
3106 case 'r':
case 'w':
case 'x':
3107 case 'X':
case 's':
case 't':
3108 case 'u':
case 'g':
case 'o':
3130 eprintf(
_(
"Usage: %s [OPTS] mode file...\n"),
args->a0());
3136 modeind =
args->getindex();
3138 const char *arg =
args->getarg(modeind);
3142 args->delarg(modeind);
3144 if(!
args->getcurr())
3150 eprintf(
_(
"invalid mode string: %s\n"), arg);
3166 return parent->builtin_queue();
3171 static struct option get1_options[]=
3187 long long source_region_begin=0,source_region_end=
FILE_END;
3188 long long target_region_begin=0,target_region_end=
FILE_END;
3191 while((opt=
args->getopt_long(
"arco:",get1_options))!=EOF)
3206 n=sscanf(
optarg,
"%lld%n-%lld",&source_region_begin,&p,&source_region_end);
3209 eprintf(
"%s\n",
_(
"Invalid range format. Format is min-max, e.g. 10-20."));
3215 n=sscanf(
optarg,
"%lld",&target_region_begin);
3218 eprintf(
"%s\n",
_(
"Invalid range format. Format is min-max, e.g. 10-20."));
3228 src=
args->getcurr();
3231 if(
args->getnext()!=0)
3234 bool auto_rename=
false;
3235 if(dst==0 || dst[0]==0)
3255 if(dst_url.
proto==0)
3260 if(stat(dst,&st)!=-1)
3264 const char *slash=
strrchr(src,
'/');
3278 if(!cont && (source_region_begin>0 || source_region_end!=
FILE_END))
3279 src_peer->
SetRange(source_region_begin,source_region_end);
3281 if(dst_url.
proto==0)
3286 if(!cont && (target_region_begin>0 || target_region_end!=
FILE_END))
3287 dst_peer->
SetRange(target_region_begin,target_region_end);
3299 const char *
n=
args->getarg(1);
3302 parent->ChangeSlot(n);
3326 const char *op=
args->getarg(0);
3327 while((opt=
args->getopt(
"+f:"))!=EOF)
3335 eprintf(
_(
"Try `%s --help' for more information\n"),op);
3347 if(*fmt==
'\\' && (fmt[1]==
'$' || fmt[1]==
'\\'))
3353 if(*fmt==
'$' && fmt[1]>=
'0' && fmt[1]<=
'9')
3356 if(n+base<args->count())
3361 if(*fmt==
'$' && fmt[1]==
'@')
3368 if(*fmt==
'$' && fmt[1]==
'$')
3370 cmd.
appendf(
"%d",(
int)getpid());
3378 parent->PrependCmd(cmd);