├── doc ├── .gitignore ├── Makefile.am ├── lftp.conf.5 ├── lftpget.1 └── ftpget.1 ├── lib ├── uniwidth │ └── .gitignore ├── unistr │ └── .gitignore └── hstrerror.c ├── po ├── ja.po ├── ko.po ├── zh_CN.po ├── .gitignore ├── POTFILES.in └── Makevars ├── src ├── .gitignore ├── example1-cmd.cc ├── example-module1.cc ├── modconfig.h ├── plural.h ├── import-ncftp ├── xdg-move ├── attach.cc ├── lftp_tinfo.h ├── GetPass.h ├── import-netscape ├── example1.cc ├── lftp_pty.h ├── module.h ├── complete.h ├── StringPool.h ├── buffer_std.h ├── example2.cc ├── FtpListInfo.h ├── Error.cc ├── rmJob.h ├── FileFeeder.h ├── LocalDir.h ├── CharReader.h ├── netrc.h ├── Error.h ├── SysCmdJob.h ├── buffer_std.cc ├── FileCopyOutputJob.h ├── ProtoLog.h ├── echoJob.h ├── FtpDirList.h ├── ascii_ctype.h ├── CatJob.h ├── buffer_ssl.h ├── StringPool.cc ├── buffer_zlib.h ├── lftpget ├── EditJob.h ├── FileCopyFtp.h ├── mgetJob.h ├── History.h ├── DummyProto.h ├── PtyShell.h ├── ftpget ├── mvJob.h ├── TreatFileJob.h ├── DirColors.h ├── mkdirJob.h ├── xmalloc.h ├── FileFeeder.cc ├── ProcWait.h ├── bookmark.h ├── CharReader.cc ├── ConnectionSlot.h ├── Cache.cc ├── fg.cc ├── Cache.h ├── ChmodJob.h ├── Speedometer.h ├── SignalHook.h ├── SSH_Access.h ├── convert-mozilla-cookies ├── SleepJob.h ├── HttpDir.h ├── alias.h ├── LocalAccess.h ├── ProtoLog.cc ├── RateLimit.h ├── GetJob.h ├── PollVec.h ├── ColumnOutput.h ├── echoJob.cc ├── lftp_rl.h ├── FileCopyOutputJob.cc ├── StatusLine.h ├── rmJob.cc ├── log.h ├── Ref.h ├── fg.h ├── StringSet.h ├── PollVec.cc ├── DummyProto.cc ├── GetPass.cc ├── LocalDir.cc ├── lftp_tinfo.cc ├── Bencode.h ├── FindJobDu.h ├── GetFileInfo.h ├── StringSet.cc ├── pgetJob.h ├── PatternSet.h ├── Timer.h ├── ConnectionSlot.cc ├── SignalHook.cc ├── ArgV.h ├── SysCmdJob.cc ├── mvJob.cc └── TreatFileJob.cc ├── contrib ├── lftp-icon.png └── get-all-torrents ├── AUTHORS ├── trio ├── Makefile.am └── trionan.h ├── m4 ├── Makefile.am ├── terminfo.m4 ├── _inttypes_h.m4 ├── pty.m4 ├── cxx-dynamic-initializers.m4 ├── needtrio.m4 ├── ssl.m4 └── readline.m4 ├── MIRRORS ├── BUGS ├── .travis.yml ├── .gitignore ├── README.md ├── README.compile ├── README.modules ├── lftp.lsm ├── lftp.spec ├── FAQ ├── README.debug-levels ├── TODO └── Makefile.am /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /parse-datetime.texi 2 | *.ps 3 | -------------------------------------------------------------------------------- /lib/uniwidth/.gitignore: -------------------------------------------------------------------------------- 1 | /cjk.h 2 | /width.c 3 | -------------------------------------------------------------------------------- /po/ja.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/lftp/master/po/ja.po -------------------------------------------------------------------------------- /po/ko.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/lftp/master/po/ko.po -------------------------------------------------------------------------------- /po/zh_CN.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/lftp/master/po/zh_CN.po -------------------------------------------------------------------------------- /lib/unistr/.gitignore: -------------------------------------------------------------------------------- 1 | /u8-mbtoucr.c 2 | /u8-uctomb-aux.c 3 | /u8-uctomb.c 4 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | lftp 2 | example1 3 | example2 4 | example1-cmd 5 | .libs 6 | -------------------------------------------------------------------------------- /contrib/lftp-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/lftp/master/contrib/lftp-icon.png -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | man_MANS = lftp.1 lftpget.1 lftp.conf.5 2 | EXTRA_DIST = $(man_MANS) 3 | 4 | lftp.ps: lftp.1 5 | groff -t -man -Tps $< > $@ 6 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Primary author (idea, most of the code): 2 | Alexander V. Lukyanov 3 | 4 | Major contributors: 5 | Glenn F. Maynard 6 | -------------------------------------------------------------------------------- /trio/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libtrio.la 2 | libtrio_la_SOURCES = trio.c triodef.h trio.h trionan.c trionan.h triop.h triostr.c triostr.h 3 | AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib 4 | -------------------------------------------------------------------------------- /m4/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = cxx-dynamic-initializers.m4 lftp.m4 needtrio.m4 pty.m4 \ 2 | quotearg.m4 quote.m4 readline.m4 ssl.m4 terminfo.m4 va_copy.m4 \ 3 | ax_check_zlib.m4 ax_lib_expat.m4 lftp_lib_readline.m4 4 | -------------------------------------------------------------------------------- /MIRRORS: -------------------------------------------------------------------------------- 1 | ftp://ftp.st.ryukoku.ac.jp/pub/network/ftp/lftp/ Japan 2 | ftp://ftp.tuwien.ac.at/infosys/browsers/ftp/lftp/ Austria 3 | ftp://ftp.cs.tu-berlin.de/pub/net/ftp/lftp/ Berlin, Germany 4 | http://lftp.cybermirror.org/ Karlsruhe, Germany 5 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | This file describes some limitations or misfeatures lftp has. 2 | 3 | * FISH upload to Digital Unix V5.1 does not work correctly (dd bug?). 4 | 5 | * sftp:connect-program and fish:connect-program cannot have shell quoting 6 | in the value. 7 | 8 | * glob does not work with aliases. 9 | -------------------------------------------------------------------------------- /po/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.in 2 | Makefile 3 | POTFILES 4 | *.mo 5 | *.gmo 6 | stamp-cat-id 7 | cat-id-tbl.c 8 | Makefile.in.in 9 | Makevars.template 10 | Rules-quot 11 | boldquot.sed 12 | en@boldquot.header 13 | en@quot.header 14 | insert-header.sin 15 | quot.sed 16 | remove-potcdate.sin 17 | remove-potcdate.sed 18 | stamp-po 19 | -------------------------------------------------------------------------------- /src/example1-cmd.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "CmdExec.h" 4 | 5 | char *program_name; 6 | 7 | int main(int argc,char **argv) 8 | { 9 | program_name=argv[0]; 10 | JobRef exec(new CmdExec(0,0)); 11 | exec->FeedCmd("open ftp://ftp.yar.ru/pub/source/lftp/\n"); 12 | exec->FeedCmd("cls -l\n"); 13 | exec->WaitDone(); 14 | return exec->ExitCode(); 15 | } 16 | -------------------------------------------------------------------------------- /src/example-module1.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CmdExec.h" 3 | 4 | Job *cmd_test1(CmdExec *parent) 5 | { 6 | parent->printf("test1 called with %d arguments\n",parent->args->count()); 7 | parent->exit_code=0; 8 | return 0; 9 | } 10 | 11 | CDECL void module_init(int argc,const char *const *argv) 12 | { 13 | CmdExec::RegisterCommand("test1",cmd_test1,"test1 [args]","This test command prints the number of arguments\n"); 14 | } 15 | -------------------------------------------------------------------------------- /contrib/get-all-torrents: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RATE_LIMIT="2m:1m" 4 | 5 | if [ $# -lt 2 ]; then 6 | echo "Usage: $0 index-URL store-directory" 7 | exit 1 8 | fi 9 | 10 | index="$1" # e.g. https://kat.cr/movies/ 11 | store="$2" 12 | 13 | urls="$(lynx "$index" -dump -listonly | grep magnet: | awk 'BEGIN {ORS=" "} {print "\""$2"\""}')" 14 | exec lftp -e "set limit-total-rate $RATE_LIMIT; set cmd:interactive yes; \ 15 | torrent -O \"$store\" --only-new $urls &" 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c++ 2 | sudo: false 3 | 4 | compiler: 5 | - clang 6 | - gcc 7 | 8 | addons: 9 | apt: 10 | packages: 11 | - libncurses5-dev 12 | - libreadline-dev 13 | - openssl 14 | - libgnutls-dev 15 | - libexpat1-dev 16 | - zlib1g-dev 17 | - build-essential 18 | - automake 19 | - autoconf 20 | - autopoint 21 | - gperf 22 | 23 | script: 24 | - ./bootstrap 25 | - ./configure 26 | - make release-check 27 | -------------------------------------------------------------------------------- /src/modconfig.h: -------------------------------------------------------------------------------- 1 | #ifdef WITH_MODULES 2 | # define MODULE_NETWORK 1 3 | # define MODULE_PROTO_FTP 1 4 | # define MODULE_PROTO_HTTP 1 5 | # define MODULE_PROTO_FILE 1 6 | # define MODULE_PROTO_FISH 1 7 | # define MODULE_PROTO_SFTP 1 8 | # define MODULE_CMD_MIRROR 1 9 | # define MODULE_CMD_SLEEP 1 10 | # define MODULE_CMD_TORRENT 1 11 | #endif 12 | /* declarations for use in modules */ 13 | CDECL_BEGIN 14 | extern const char *module_depend[]; 15 | extern void module_init(); 16 | CDECL_END 17 | -------------------------------------------------------------------------------- /m4/terminfo.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([lftp_TERMINFO], 2 | [ 3 | AC_CHECK_HEADERS(curses.h term.h ncurses/curses.h ncurses/term.h) 4 | 5 | # Get a library with terminal caps if needed; prefer one with tigetstr. 6 | AC_SEARCH_LIBS(tigetstr, [tinfo curses ncurses], [ 7 | AC_DEFINE(HAVE_TIGETSTR, 1, [Define to 1 if you have the `tigetstr' function.]) 8 | AC_CHECK_FUNCS(tgetstr) 9 | ], [AC_SEARCH_LIBS(tgetstr, termcap, 10 | [AC_DEFINE(HAVE_TGETSTR, 1)], 11 | [AC_MSG_WARN(No terminfo, termcap or curses library found)])]) 12 | ]) 13 | -------------------------------------------------------------------------------- /src/plural.h: -------------------------------------------------------------------------------- 1 | /* 2 | * plural word form chooser for i18n 3 | * 4 | * Copyright (c) 1998 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This file is in public domain. 7 | */ 8 | 9 | #ifndef PLURAL_H 10 | #define PLURAL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #ifndef FORMAT_ARG 17 | # ifdef __GNUC__ 18 | # define FORMAT_ARG(n) __attribute__((format_arg(n))) 19 | # else 20 | # define FORMAT_ARG(n) 21 | # endif 22 | #endif 23 | 24 | const char *plural(const char *format,...) FORMAT_ARG(1); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* PLURAL_H */ 31 | -------------------------------------------------------------------------------- /m4/_inttypes_h.m4: -------------------------------------------------------------------------------- 1 | # _inttypes_h.m4 serial 4 2 | dnl Copyright (C) 2006 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Derek Price. 8 | 9 | AC_DEFUN([gl_INTTYPES_H], 10 | [AC_REQUIRE([gl_INCLUDE_NEXT])dnl 11 | AC_LIBSOURCES([inttypes.h]) 12 | if test $gl_cv_have_include_next = no; then 13 | gl_ABSOLUTE_HEADER([inttypes.h]) 14 | fi 15 | AC_CHECK_DECLS_ONCE([strtoimax])dnl 16 | AC_CHECK_DECLS_ONCE([strtoumax])dnl 17 | ]) 18 | -------------------------------------------------------------------------------- /doc/lftp.conf.5: -------------------------------------------------------------------------------- 1 | .TH LFTP.CONF 5 2 | .SH NAME 3 | lftp.conf \- the global configuration file for lftp 4 | 5 | .SH "DESCRIPTION" 6 | the /etc/lftp.conf configuration file changes the default behavior of lftp and affects the settings for all users. User-specific options should be set in either the ~/.lftprc or ~/.lftp/rc file. These configuration files are read when lftp starts up and the parameters defined therein take affect at that time. 7 | 8 | In addition to lftp's configuration options, aliases and 'set' commands can be defined in any of these configuration files. Refer to the Command and Settings sections of the lftp man page for more details. 9 | 10 | .SH SEE ALSO 11 | .BR lftp (1) 12 | -------------------------------------------------------------------------------- /m4/pty.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([LFTP_PTY_CHECK],[ 2 | case "$host" in 3 | *-*-linux*) no_dev_ptmx=1; no_dev_ptc=1;; 4 | *-*-sco3.2v4*) no_dev_ptmx=1;; 5 | *-*-sco3.2v5*) no_dev_ptmx=1;; 6 | esac 7 | if test -z "$no_dev_ptmx" ; then 8 | AC_CHECK_FILE("/dev/ptmx", [ 9 | AC_DEFINE(HAVE_DEV_PTMX,1,[define if you have /dev/ptmx device])]) 10 | fi 11 | if test -z "$no_dev_ptc" ; then 12 | AC_CHECK_FILE("/dev/ptc", [ 13 | AC_DEFINE(HAVE_DEV_PTS_AND_PTC,1,[define if you have /dev/ptc device])]) 14 | fi 15 | AC_CHECK_HEADERS([util.h sys/stropts.h pty.h]) 16 | AC_SEARCH_LIBS(openpty,util, 17 | [AC_DEFINE(HAVE_OPENPTY,1,[define if you have openpty function])]) 18 | AC_CHECK_FUNCS([_getpty]) 19 | ]) 20 | -------------------------------------------------------------------------------- /m4/cxx-dynamic-initializers.m4: -------------------------------------------------------------------------------- 1 | dnl check if c++ compiler can use dynamic initializers for static variables 2 | AC_DEFUN([CXX_DYNAMIC_INITIALIZERS], 3 | [ 4 | AC_LANG_PUSH(C++) 5 | AC_MSG_CHECKING(if c++ compiler can handle dynamic initializers) 6 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ 7 | int f() { return 1; } 8 | int a=f(); 9 | int main() 10 | { 11 | return(1-a); 12 | } 13 | ]])],[cxx_dynamic_init=yes],[cxx_dynamic_init=no],[cxx_dynamic_init=yes]) 14 | AC_MSG_RESULT($cxx_dynamic_init) 15 | if test x$cxx_dynamic_init = xno; then 16 | AC_MSG_ERROR(C++ compiler cannot handle dynamic initializers of static objects) 17 | fi 18 | AC_LANG_POP(C++) 19 | ]) 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | 9 | # Compiled Static libraries 10 | *.lai 11 | *.la 12 | *.a 13 | 14 | libtool 15 | .deps 16 | /.version 17 | 18 | # backup files 19 | *~ 20 | 21 | # http://www.gnu.org/software/automake 22 | Makefile.in 23 | 24 | # http://www.gnu.org/software/autoconf 25 | Makefile 26 | autom4te.cache/ 27 | /aclocal.m4 28 | /configure 29 | /config.cache 30 | /config.log 31 | /config.status 32 | /build-aux/ar-lib 33 | /build-aux/depcomp 34 | /build-aux/install-sh 35 | /build-aux/mdate-sh 36 | /build-aux/missing 37 | /build-aux/texinfo.tex 38 | /INSTALL 39 | 40 | # LE editor 41 | .le.ini 42 | 43 | # gettext 44 | /ABOUT-NLS 45 | /po/Makevars 46 | -------------------------------------------------------------------------------- /src/import-ncftp: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script is based on draft by Sam Steingold 4 | # Copyright (c) 1998 by Alexander V. Lukyanov 5 | # This script can be distributed and modified freely under GNU GPL, see COPYING 6 | 7 | set -e 8 | 9 | NCFTP="$HOME/.ncftp/bookmarks" 10 | OLD="${LFTP_HOME:-$HOME/.lftp}/bookmarks" 11 | NEW="$OLD.new.$$" 12 | 13 | grep "," "$NCFTP" | cut -d, -f1,2,3,6 | sed \ 14 | -e "s?,,?/?" \ 15 | -e "s?//?/?" \ 16 | -e "s?,? ftp://?" \ 17 | -e "s?ftp://\([^,]*\),\([^,]*\),/*?ftp://\2@\1/?" \ 18 | -e "s?^?NC-?" > "$NEW" 19 | 20 | if [ -f "$OLD" ]; then 21 | sort -u "$OLD" "$NEW" -o "$NEW" 22 | mv -f "$OLD" "$OLD~" # backup 23 | else 24 | sort -u "$NEW" -o "$NEW" 25 | fi 26 | mv -f "$NEW" "$OLD" 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LFTP 2 | ==== 3 | Command line driven, shell-like, reliable file transfer program. It supports a number of protocols and even BitTorrent with DHT! IPv6 is fully supported too. 4 | 5 | To build from GIT sources, run `autogen.sh` script to create Makefiles. You will need autoconf, libtool, gettext-devel, automake, gnulib. 6 | You can get gnulib using `git clone git://git.savannah.gnu.org/gnulib`. 7 | 8 | Also for compiling lftp you will need these libraries: 9 | * readline-devel 10 | * zlib-devel 11 | * gnutls-devel or openssl-devel (optional) 12 | * expat-devel (optional) 13 | 14 | [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=lavv17&url=https://github.com/lavv17/lftp&title=LFTP+-+sophisticated+file+transfer+program&language=en_GB&tags=github&category=software) 15 | -------------------------------------------------------------------------------- /README.compile: -------------------------------------------------------------------------------- 1 | Some hints about lftp compilation 2 | --------------------------------- 3 | * ncurses or termcap development is required. If you get undefined 4 | references to tputs or tgetent, install ncurses-devel package. 5 | * invalid exception specifications in rltypedefs.h 6 | Solution: install a newer readline library. 7 | * multiple declarations of rl_dispatching during linking 8 | Solution: install a newer readline library. 9 | * g++ cannot create executables 10 | You probably have not installed libstdc++ (or libg++). As a 11 | workaround, you can try `CXX=gcc configure' to avoid linking with 12 | libstdc++. 13 | * lftp cannot resolve host names 14 | Try `configure --without-libresolv' - it can sometimes help. 15 | * Sun C++ v5.0 compiler can be used to compile lftp. Use 16 | CXX=CC CXXFLAGS="-compat=4 -features=bool" ./configure 17 | * you need GNU TLS 1.0 or newer to compile with SSL support. 18 | -------------------------------------------------------------------------------- /src/xdg-move: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script moves ~/.lftp (or $LFTP_HOME) files to XDG directories. 4 | # ~/.lftp should be removed after execution of this script. 5 | # 6 | 7 | src=${LFTP_HOME:-$HOME/.lftp} 8 | if ! [ -d "$src" ]; then 9 | echo "Nothing to move (no $src directory found)." >&2 10 | exit 0 11 | fi 12 | 13 | function move() { 14 | test -a "$src/$1" || return 15 | test -d "$2" || mkdir -p "$2" || exit 1 16 | mv "$src/$1" "$2/" 17 | } 18 | 19 | function move_data() { 20 | move "$1" "${XDG_DATA_HOME:-$HOME/.local/share}/lftp" 21 | } 22 | function move_config() { 23 | move "$1" "${XDG_CONFIG_HOME:-$HOME/.config}/lftp" 24 | } 25 | function move_cache() { 26 | move "$1" "${XDG_CACHE_HOME:-$HOME/.cache}/lftp" 27 | } 28 | 29 | move_data bg 30 | move_data bookmarks 31 | move_data cwd_history 32 | move_cache DHT 33 | move_data log 34 | move_config rc 35 | move_data rl_history 36 | move_data transfer_log 37 | 38 | rmdir "$src" 39 | -------------------------------------------------------------------------------- /doc/lftpget.1: -------------------------------------------------------------------------------- 1 | .TH "lftpget" "1" "31 December 2005" 2 | 3 | .SH "NAME" 4 | lftpget \- get a file with lftp(1) 5 | 6 | .SH "SYNOPSIS" 7 | .PP 8 | .B lftpget 9 | [-c] [-d] [-v] 10 | .I URL 11 | [URL...] 12 | 13 | .SH "DESCRIPTION" 14 | .PP 15 | This manual page documents briefly the 16 | .B lftpget 17 | command. 18 | .PP 19 | .B lftpget 20 | is a shell script for downloading by URL, it calls `lftp -c'. It supports 21 | the same set of protocols as lftp does, including ftp, http, fish, sftp. 22 | 23 | .SH "OPTIONS" 24 | .TP 25 | .B \-c 26 | Continue a previous download. 27 | .TP 28 | .B \-d 29 | Debug output. 30 | .TP 31 | .B \-v 32 | Verbose messages. 33 | 34 | .SH "SEE ALSO" 35 | .PP 36 | .BR lftp (1), 37 | .BR wget (1). 38 | 39 | .SH "AUTHOR" 40 | .PP 41 | .B lftpget 42 | is Copyright (c) 1999-2000 Alexander V. Lukyanov . 43 | .PP 44 | This manual page was initially written by Francois Wendling 45 | and later updated by Alexander V. Lukyanov. 46 | -------------------------------------------------------------------------------- /src/attach.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "attach.h" 22 | 23 | // this limits SendTermFD to a single instance, but we don't need more yet. 24 | pid_t SendTermFD::pass_pid; 25 | -------------------------------------------------------------------------------- /src/lftp_tinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LFTP_TINFO_H 21 | #define LFTP_TINFO_H 22 | 23 | const char *get_string_term_cap(const char *terminfo_cap, const char *tcap_cap=NULL); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/GetPass.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef GETPASS_H 21 | #define GETPASS_H 22 | 23 | #include "trio.h" 24 | 25 | const char *GetPass(const char *p); 26 | char *readline_from_file(int fd); 27 | 28 | #endif//GETPASS_H 29 | -------------------------------------------------------------------------------- /src/import-netscape: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script is based on draft by Sam Steingold 4 | # Copyright (c) 1998 by Alexander V. Lukyanov 5 | # This script can be distributed and modified freely under GNU GPL, see COPYING 6 | 7 | set -e 8 | 9 | NS="$HOME/.netscape/bookmarks.html" 10 | OLD="${LFTP_HOME:-$HOME/.lftp}/bookmarks" 11 | NEW="$OLD.new.$$" 12 | 13 | prepend_hash() 14 | { 15 | n=$$ 16 | while read line; do 17 | u=`echo $line | sed -e 's|\(ftp://[^:]*\):[^@]*@|\1|'` 18 | t=`expr "$u" : "ftp://\([^.]*\)"` 19 | if [ "$t" = ftp -o -z "$t" ]; then 20 | t=`expr "$u" : "ftp://[^.]*.\([^.]*\)"` 21 | if [ "$t" = ftp -o -z "$t" ]; then 22 | t="$n" 23 | n=`expr $n + 1` 24 | fi 25 | fi 26 | echo "NS-$t $line" 27 | done 28 | } 29 | 30 | grep ftp:// "$NS" | cut "-d\"" -f2 | prepend_hash > "$NEW" 31 | 32 | if [ -f "$OLD" ]; then 33 | sort -u "$OLD" "$NEW" -o "$NEW" 34 | mv -f "$OLD" "$OLD~" # backup 35 | else 36 | sort -u "$NEW" -o "$NEW" 37 | fi 38 | mv -f "$NEW" "$OLD" 39 | -------------------------------------------------------------------------------- /src/example1.cc: -------------------------------------------------------------------------------- 1 | /* 2 | This example shows blocking usage of Ftp class 3 | */ 4 | 5 | #include 6 | #include 7 | #include "FileAccess.h" 8 | 9 | char *program_name; 10 | 11 | int main(int argc,char **argv) 12 | { 13 | program_name=argv[0]; 14 | 15 | FileAccess *f=FileAccess::New("ftp","ftp.yar.ru"); 16 | if(!f) 17 | { 18 | fprintf(stderr,"ftp: unknown protocol, cannot create ftp session\n"); 19 | return 1; 20 | } 21 | f->Open("/pub/source/lftp",f->LONG_LIST); 22 | Buffer buf; 23 | for(;;) 24 | { 25 | SMTask::Schedule(); 26 | 27 | int res=f->Read(&buf,1024); 28 | if(res<0) 29 | { 30 | if(res==f->DO_AGAIN) 31 | { 32 | SMTask::Block(); 33 | continue; 34 | } 35 | fprintf(stderr,"Error: %s\n",f->StrError(res)); 36 | return 1; 37 | } 38 | if(res==0) // eof 39 | { 40 | f->Close(); 41 | break; 42 | } 43 | buf.SpaceAdd(res); 44 | write(1,buf.Get(),res); 45 | buf.Skip(res); 46 | } 47 | SMTask::Delete(f); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /src/lftp_pty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LFTP_PTY_H 21 | #define LFTP_PTY_H 22 | 23 | CDECL_BEGIN 24 | 25 | /* opens a pseudo-tty, returns slave tty name if successful */ 26 | const char *open_pty(int *ptyfd, int *ttyfd); 27 | 28 | CDECL_END 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2015 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef MODULE_H 21 | #define MODULE_H 22 | 23 | void *module_load(const char *name,int argc,const char *const *argv); 24 | const char *module_error_message(); 25 | bool module_init_preloaded(const char *prefix); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/complete.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef COMPLETE_H 21 | #define COMPLETE_H 22 | 23 | #include "trio.h" 24 | #include "CmdExec.h" 25 | 26 | extern CmdExec *completion_shell; 27 | extern int remote_completion; 28 | int lftp_rl_getc(FILE *); 29 | extern "C" void lftp_line_complete(); 30 | 31 | #endif //COMPLETE_H 32 | -------------------------------------------------------------------------------- /src/StringPool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef STRINGPOOL_H 21 | #define STRINGPOOL_H 22 | 23 | #include "xarray.h" 24 | 25 | // maybe it is better to have many separate pools with dtors. 26 | class StringPool 27 | { 28 | static xarray_m strings; 29 | 30 | public: 31 | static const char *Get(const char *); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/buffer_std.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BUFFER_STD_H 21 | #define BUFFER_STD_H 22 | 23 | #include "Job.h" 24 | #include "buffer.h" 25 | 26 | class IOBuffer_STDOUT : public IOBuffer 27 | { 28 | Job *master; 29 | int Put_LL(const char *buf,int size); 30 | 31 | public: 32 | IOBuffer_STDOUT(Job *m) : IOBuffer(PUT) { master=m; } 33 | }; 34 | 35 | #endif //BUFFER_STD_H 36 | -------------------------------------------------------------------------------- /src/example2.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "FileAccess.h" 4 | #include "log.h" 5 | 6 | char *program_name; 7 | 8 | int main(int argc,char **argv) 9 | { 10 | program_name=argv[0]; 11 | 12 | Log::global=new Log; 13 | Log::global->SetOutput(2,false); 14 | Log::global->SetLevel(5); 15 | Log::global->Enable(); 16 | Log::global->ShowNothing(); 17 | 18 | FileAccess *f=FileAccess::New("http","lftp.yar.ru"); 19 | if(!f) 20 | { 21 | fprintf(stderr,"http: unknown protocol, cannot create http session\n"); 22 | return 1; 23 | } 24 | f->Open("/ftp/",f->RETRIEVE); 25 | Buffer buf; 26 | for(;;) 27 | { 28 | SMTask::Schedule(); 29 | 30 | int res=f->Read(&buf,sizeof(buf)); 31 | if(res<0) 32 | { 33 | if(res==f->DO_AGAIN) 34 | { 35 | SMTask::Block(); 36 | continue; 37 | } 38 | fprintf(stderr,"Error: %s\n",f->StrError(res)); 39 | return 1; 40 | } 41 | if(res==0) // eof 42 | { 43 | f->Close(); 44 | return 0; 45 | } 46 | buf.SpaceAdd(res); 47 | write(1,buf.Get(),res); 48 | buf.Skip(res); 49 | } 50 | SMTask::Delete(f); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | lib/argmatch.c 2 | lib/error.c 3 | lib/getopt.c 4 | lib/human.c 5 | lib/quotearg.c 6 | lib/strtol.c 7 | lib/xalloc-die.c 8 | src/CatJob.cc 9 | src/ChmodJob.cc 10 | src/CmdExec.cc 11 | src/CopyJob.cc 12 | src/DummyProto.cc 13 | src/FileAccess.cc 14 | src/FileCopy.cc 15 | src/FileCopy.h 16 | src/FileCopyFtp.cc 17 | src/FileSetOutput.cc 18 | src/Filter.cc 19 | src/FindJobDu.cc 20 | src/Fish.cc 21 | src/FtpDirList.cc 22 | src/FtpListInfo.cc 23 | src/GetJob.cc 24 | src/Http.cc 25 | src/HttpDir.cc 26 | src/Job.cc 27 | src/LocalAccess.cc 28 | src/LsCache.cc 29 | src/MirrorJob.cc 30 | src/NetAccess.cc 31 | src/OutputJob.cc 32 | src/PollVec.cc 33 | src/PtyShell.cc 34 | src/QueueFeeder.cc 35 | src/ResMgr.cc 36 | src/Resolver.cc 37 | src/SFtp.cc 38 | src/SMTask.cc 39 | src/SleepJob.cc 40 | src/Speedometer.cc 41 | src/SysCmdJob.cc 42 | src/TreatFileJob.cc 43 | src/buffer.cc 44 | src/commands.cc 45 | src/ftpclass.cc 46 | lib/parse-datetime.c 47 | src/lftp.cc 48 | src/mgetJob.cc 49 | src/mkdirJob.cc 50 | src/module.cc 51 | src/mvJob.cc 52 | src/parsecmd.cc 53 | src/pgetJob.cc 54 | src/plural.c 55 | src/resource.cc 56 | src/rmJob.cc 57 | src/Torrent.cc 58 | src/TorrentTracker.cc 59 | src/DHT.cc 60 | src/attach.h 61 | -------------------------------------------------------------------------------- /src/FtpListInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef FTPLISTINFO_H 21 | #define FTPLISTINFO_H 22 | 23 | #include "NetAccess.h" 24 | 25 | class FtpListInfo : public GenericParseListInfo 26 | { 27 | FileSet *ParseShortList(const char *buf,int len); 28 | public: 29 | virtual FileSet *Parse(const char *buf,int len); 30 | FtpListInfo(FileAccess *session,const char *path) : GenericParseListInfo(session,path) {} 31 | }; 32 | 33 | #endif//FTPLISTINFO_H 34 | -------------------------------------------------------------------------------- /src/Error.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "Error.h" 22 | 23 | Error::Error() : code(0), fatal(false) {} 24 | Error::Error(int c,const char *s,bool f) : text(s), code(c), fatal(f) {} 25 | Error::~Error() {} 26 | 27 | void Error::Set(int c,const char *s,bool f) 28 | { 29 | text.set(s); 30 | code=c; 31 | fatal=f; 32 | } 33 | 34 | Error *Error::Fatal(const char *s,int c) 35 | { 36 | return new Error(c,s,true); 37 | } 38 | -------------------------------------------------------------------------------- /src/rmJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef RMJOB_H 21 | #define RMJOB_H 22 | 23 | #include "TreatFileJob.h" 24 | 25 | class rmJob : public TreatFileJob 26 | { 27 | void TreatCurrent(const char *, const FileInfo *); 28 | 29 | protected: 30 | FA::open_mode mode; 31 | 32 | bool recurse; 33 | 34 | public: 35 | void SayFinal(); 36 | void Recurse(); // rm -r 37 | void Rmdir() { mode=FA::REMOVE_DIR; } 38 | 39 | rmJob(FileAccess *session,ArgV *a); 40 | }; 41 | 42 | #endif // RMJOB_H 43 | -------------------------------------------------------------------------------- /src/FileFeeder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef FILEFEEDER_H 21 | #define FILEFEEDER_H 22 | 23 | #include "CmdExec.h" 24 | 25 | class FileFeeder : public CmdFeeder 26 | { 27 | Ref in; 28 | Ref fg_data; 29 | char buffer[0x1001]; 30 | public: 31 | const char *NextCmd(CmdExec *exec,const char *prompt); 32 | FileFeeder(FDStream *in); 33 | ~FileFeeder(); 34 | void Fg() { if(fg_data) fg_data->Fg(); } 35 | void Bg() { if(fg_data) fg_data->Bg(); } 36 | }; 37 | 38 | #endif//FILEFEEDER_H 39 | -------------------------------------------------------------------------------- /src/LocalDir.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LOCALDIR_H 21 | #define LOCALDIR_H 22 | 23 | #include "xstring.h" 24 | 25 | class LocalDirectory 26 | { 27 | int fd; 28 | xstring_c name; 29 | 30 | public: 31 | LocalDirectory(); 32 | LocalDirectory(const LocalDirectory *); 33 | ~LocalDirectory(); 34 | 35 | const char *GetName(); 36 | const char *Chdir(); // returns error message or NULL 37 | void SetFromCWD(); 38 | void Unset(); 39 | 40 | LocalDirectory *Clone() const; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /m4/needtrio.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([LFTP_NEED_TRIO],[ 2 | AC_CHECK_FUNCS(vsnprintf snprintf) 3 | AC_CACHE_CHECK([if trio library is needed], ac_cv_need_trio, 4 | [ 5 | ac_cv_need_trio=no; 6 | 7 | if test x$ac_cv_func_vsnprintf != xyes -o x$ac_cv_func_snprintf != xyes; then 8 | ac_cv_need_trio="yes (because there is no system snprintf/vsnprintf functions)" 9 | else 10 | 11 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ 12 | int main() 13 | { 14 | unsigned long long x=0,x1; 15 | long long y=0,y1; 16 | char buf[128]; 17 | 18 | x=~x; 19 | sscanf("0","%llu",&x); 20 | if(x!=0) return 1; 21 | 22 | y=~y; 23 | sscanf("0","%lld",&y); 24 | if(y!=0) return 1; 25 | 26 | x=~x; 27 | sprintf(buf,"%lld %llu",y,x); 28 | sscanf (buf,"%lld %llu",&y1,&x1); 29 | if(x!=x1 || y!=y1) 30 | return 1; 31 | 32 | return 0; 33 | }]])],[],[ac_cv_need_trio="yes (because %lld fails)"],[ac_cv_need_trio="no (assumed)"]) 34 | 35 | fi 36 | ]) 37 | case $ac_cv_need_trio in 38 | yes*) 39 | ac_cv_need_trio=yes 40 | AC_DEFINE(TRIO_REPLACE_STDIO, 1, [replace system's printf functions]) 41 | LFTP_CHECK_LIBM 42 | ;; 43 | *) 44 | ac_cv_need_trio=no 45 | ;; 46 | esac 47 | AM_CONDITIONAL(NEED_TRIO, [test "$ac_cv_need_trio" = yes]) 48 | ]) 49 | -------------------------------------------------------------------------------- /src/CharReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CHARREADER_H 21 | #define CHARREADER_H 22 | 23 | #include "SMTask.h" 24 | 25 | // CharReader fetches a single character from given file descriptor. 26 | class CharReader : public SMTask 27 | { 28 | int fd; 29 | int ch; 30 | 31 | int Do(); 32 | 33 | public: 34 | enum { NOCHAR=-2, EOFCHAR=-1 }; 35 | 36 | int GetChar() { return ch; }; 37 | 38 | CharReader(int new_fd) 39 | { 40 | fd=new_fd; 41 | ch=NOCHAR; 42 | } 43 | }; 44 | 45 | #endif//CHARREADER_H 46 | -------------------------------------------------------------------------------- /src/netrc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef NETRC_H 21 | #define NETRC_H 22 | 23 | #include "xstring.h" 24 | 25 | class NetRC 26 | { 27 | public: 28 | class Entry 29 | { 30 | public: 31 | xstring host; 32 | xstring user; 33 | xstring pass; 34 | xstring acct; 35 | 36 | Entry(const char *h=0,const char *u=0,const char *p=0,const char *a=0) 37 | : host(h), user(u), pass(p), acct(a) {} 38 | }; 39 | 40 | static Entry *LookupHost(const char *host,const char *user=0); 41 | }; 42 | 43 | #endif//NETRC_H 44 | -------------------------------------------------------------------------------- /src/Error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef ERROR_H 21 | #define ERROR_H 22 | 23 | #include "xstring.h" 24 | 25 | class Error 26 | { 27 | xstring text; 28 | int code; 29 | bool fatal; 30 | public: 31 | Error(); 32 | Error(int,const char *,bool); 33 | ~Error(); 34 | void Set(int,const char *,bool); 35 | 36 | const char *Text() const { return text; } 37 | int Code() const { return code; } 38 | bool IsFatal() const { return fatal; } 39 | 40 | static Error *Fatal(const char *s,int c=-1); 41 | }; 42 | 43 | #endif//ERROR_H 44 | -------------------------------------------------------------------------------- /src/SysCmdJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef SYSCMDJOB_H 21 | #define SYSCMDJOB_H 22 | 23 | #include "trio.h" 24 | #include "Job.h" 25 | #include "ProcWait.h" 26 | 27 | class SysCmdJob : public Job 28 | { 29 | xstring cmd; 30 | SMTaskRef w; 31 | void PrepareToDie(); 32 | public: 33 | SysCmdJob(const char *new_cmd); 34 | ~SysCmdJob(); 35 | int Do(); 36 | int Done() { return(w && w->GetState()!=w->RUNNING); } 37 | int AcceptSig(int); 38 | int ExitCode() { return w?w->GetInfo()>>8:1; } 39 | }; 40 | 41 | #endif//SYSCMDJOB_H 42 | -------------------------------------------------------------------------------- /src/buffer_std.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "buffer_std.h" 22 | 23 | int IOBuffer_STDOUT::Put_LL(const char *buf,int size) 24 | { 25 | if(size==0) 26 | return 0; 27 | if(!eof) 28 | { 29 | for(int i=size; i>0; i--) 30 | { 31 | if(buf[i-1]=='\n') 32 | { 33 | size=i; 34 | break; 35 | } 36 | if(i==1) 37 | return 0; 38 | } 39 | } 40 | char *str=string_alloca(size+1); 41 | memcpy(str,buf,size); 42 | str[size]=0; 43 | master->printf("%s",str); 44 | return size; 45 | } 46 | -------------------------------------------------------------------------------- /src/FileCopyOutputJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef FILECOPYPEEROUTPUTJOB_H 21 | #define FILECOPYPEEROUTPUTJOB_H 22 | 23 | #include "OutputJob.h" 24 | 25 | class FileCopyPeerOutputJob : public FileCopyPeer 26 | { 27 | const JobRef& o; 28 | int Put_LL(const char *buf,int len); 29 | 30 | public: 31 | FileCopyPeerOutputJob(const JobRef& o); 32 | 33 | int Do(); 34 | void Fg(); 35 | void Bg(); 36 | 37 | const char *GetDescriptionForLog() 38 | { 39 | return "[pipe to other job]"; 40 | } 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/ProtoLog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef PROTOLOG_H 21 | #define PROTOLOG_H 22 | 23 | class ProtoLog 24 | { 25 | static bool WillOutput(int level); 26 | public: 27 | static void Log2(int level,xstring& str); 28 | static void Log3(int level,const char *prefix,const char *str); 29 | static void LogError(int level,const char *fmt,...) PRINTF_LIKE(2,3); 30 | static void LogNote(int level,const char *fmt,...) PRINTF_LIKE(2,3); 31 | static void LogRecv(int level,const char *line); 32 | static void LogSend(int level,const char *line); 33 | }; 34 | 35 | #endif//PROTOLOG_H 36 | -------------------------------------------------------------------------------- /m4/ssl.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([LFTP_OPENSSL_CHECK], 2 | [AC_MSG_CHECKING([for openssl library]) 3 | AC_CACHE_VAL(lftp_cv_openssl, 4 | [ 5 | found_loc=none; 6 | lftp_cv_openssl=none; 7 | for loc in $openssl_loc default /usr/local/ssl; do 8 | old_LIBS="$LIBS" 9 | old_LDFLAGS="$LDFLAGS" 10 | old_CPPFLAGS="$CPPFLAGS" 11 | LIBS="$LIBS -lssl -lcrypto" 12 | if test $loc != default; then 13 | LDFLAGS="$LDFLAGS -L$loc/lib" 14 | CPPFLAGS="$CPPFLAGS -I$loc/include" 15 | fi 16 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include 17 | #include ]], [[static SSL_CTX *ctx; SSL_new(ctx); RAND_status()]])],[found_loc="$loc"],[]) 18 | LIBS="$old_LIBS" 19 | LDFLAGS="$old_LDFLAGS" 20 | CPPFLAGS="$old_CPPFLAGS" 21 | if test $found_loc != "none"; then 22 | lftp_cv_openssl="OPENSSL_LIBS=\"-lssl -lcrypto\"" 23 | if test $found_loc != default; then 24 | lftp_cv_openssl="$lftp_cv_openssl OPENSSL_LDFLAGS=\"-L$found_loc/lib -R$found_loc/lib\"" 25 | lftp_cv_openssl="$lftp_cv_openssl OPENSSL_CPPFLAGS=-I$found_loc/include" 26 | fi 27 | break; 28 | fi 29 | done 30 | ]) 31 | if test "$lftp_cv_openssl" != none; then 32 | eval $lftp_cv_openssl 33 | AC_SUBST(OPENSSL_LIBS) 34 | AC_SUBST(OPENSSL_LDFLAGS) 35 | AC_SUBST(OPENSSL_CPPFLAGS) 36 | AC_DEFINE(USE_OPENSSL, 1, [define if you are using openssl]) 37 | AC_MSG_RESULT($lftp_cv_openssl) 38 | else 39 | AC_MSG_RESULT(none found) 40 | fi 41 | ]) 42 | -------------------------------------------------------------------------------- /src/echoJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef ECHOJOB_H 21 | #define ECHOJOB_H 22 | 23 | #include "Job.h" 24 | #include "StatusLine.h" 25 | #include "OutputJob.h" 26 | 27 | class echoJob : public Job 28 | { 29 | JobRef output; 30 | 31 | public: 32 | int Do() { return STALL; } 33 | int Done(); 34 | int ExitCode(); 35 | 36 | void ShowRunStatus(const SMTaskRef&); 37 | 38 | echoJob(const char *buf, OutputJob *output); 39 | echoJob(const char *buf, int len, OutputJob *output); 40 | ~echoJob(); 41 | 42 | void Fg(); 43 | void Bg(); 44 | }; 45 | 46 | #endif // ECHOJOB_H 47 | -------------------------------------------------------------------------------- /src/FtpDirList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef FTPDIRLIST_H 21 | #define FTPDIRLIST_H 22 | 23 | class FtpDirList : public DirList 24 | { 25 | SMTaskRef ubuf; 26 | xstring_ca pattern; 27 | 28 | bool TryEPLF(const char *line,int len); 29 | bool TryMLSD(const char *line,int len); 30 | bool TryColor(const char *line,int len); 31 | 32 | void FormatGeneric(class FileInfo *); 33 | 34 | public: 35 | FtpDirList(FileAccess *s,ArgV *a) 36 | : DirList(s,a), pattern(args->Combine(1)) {} 37 | const char *Status(); 38 | int Do(); 39 | 40 | void SuspendInternal(); 41 | void ResumeInternal(); 42 | }; 43 | 44 | #endif//FTPDIRLIST_H 45 | -------------------------------------------------------------------------------- /src/ascii_ctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef ASCII_CTYPE_H 21 | #define ASCII_CTYPE_H 22 | 23 | // We need these functions because network protocols should not depend 24 | // on current locale. 25 | 26 | #include "c-ctype.h" 27 | 28 | #define is_ascii_digit(c) c_isdigit((c)) 29 | #define is_ascii_xdigit(c) c_isxdigit((c)) 30 | #define is_ascii_space(c) c_isspace((c)) 31 | #define is_ascii_lower(c) c_islower((c)) 32 | #define is_ascii_upper(c) c_isupper((c)) 33 | #define is_ascii_alpha(c) c_isalpha((c)) 34 | #define is_ascii_alnum(c) c_isalnum((c)) 35 | #define to_ascii_lower(c) c_tolower((c)) 36 | #define to_ascii_upper(c) c_toupper((c)) 37 | 38 | #endif//ASCII_CTYPE_H 39 | -------------------------------------------------------------------------------- /src/CatJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CATJOB_H 21 | #define CATJOB_H 22 | 23 | #include "CopyJob.h" 24 | #include "StatusLine.h" 25 | #include "OutputJob.h" 26 | 27 | class ArgV; 28 | 29 | class CatJob : public CopyJobEnv 30 | { 31 | protected: 32 | JobRef output; 33 | bool ascii; 34 | bool auto_ascii; 35 | 36 | void NextFile(); 37 | 38 | public: 39 | int Do(); 40 | int Done(); 41 | int ExitCode(); 42 | 43 | CatJob(FileAccess *s,OutputJob *output,ArgV *args); 44 | 45 | void Ascii() { ascii=true; } 46 | void Binary() { ascii=auto_ascii=false; } 47 | void ShowRunStatus(const SMTaskRef&); 48 | }; 49 | 50 | #endif /* CATJOB_H */ 51 | -------------------------------------------------------------------------------- /src/buffer_ssl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BUFFER_SSL_H 21 | #define BUFFER_SSL_H 22 | 23 | #include "buffer.h" 24 | 25 | #if USE_SSL 26 | #include "lftp_ssl.h" 27 | class IOBufferSSL : public IOBuffer 28 | { 29 | Ref my_ssl; 30 | const Ref& ssl; 31 | 32 | int Get_LL(int size); 33 | int Put_LL(const char *buf,int size); 34 | int PutEOF_LL(); 35 | 36 | public: 37 | IOBufferSSL(lftp_ssl *s,dir_t m) : IOBuffer(m), my_ssl(s), ssl(my_ssl) {} 38 | IOBufferSSL(const Ref& s,dir_t m) : IOBuffer(m), ssl(s) {} 39 | ~IOBufferSSL(); 40 | int Do(); 41 | bool Done() { return IOBuffer::Done() && ssl->handshake_done; } 42 | }; 43 | #endif 44 | 45 | #endif//BUFFER_SSL_H 46 | -------------------------------------------------------------------------------- /README.modules: -------------------------------------------------------------------------------- 1 | lftp 2.0 and later support loading modules (shared objects) at 2 | runtime. Use command `module' to load a module. 3 | 4 | It also supports loading certain modules (some of protocols and commands) 5 | automatically on demand. To compile modular lftp use: 6 | 7 | configure --with-modules 8 | 9 | You will need GCC and ELF platform (linux, freebsd-3.x, solaris, irix etc). 10 | 11 | 12 | Below are the technical details. 13 | 14 | Module is a shared object, after loading it with dlopen(3) lftp does 15 | dlsym("module_init") and calls this function with parameters argc, argv: 16 | 17 | extern "C" 18 | void module_init(int argc, const char * const *argv); 19 | 20 | The argv vector contains the arguments passed to `module' command after 21 | module name. In case of loading module on demand it is empty. 22 | 23 | Note: function _init of a module is called automatically by dlopen. It can 24 | execute constructors if the module is properly compiled with `gcc -shared'. 25 | 26 | To load modules on demand lftp uses protocol or command name to find 27 | module file. For protocols it looks for proto-.so and for 28 | commands -- cmd-.so. The modules register the protocols and 29 | commands they provide with functions FileAccess::Register and 30 | CmdExec::RegisterCommand. 31 | 32 | lftp searches module for any protocol specified in URL in open command, 33 | and only for certain compile time defined set of commands -- the commands 34 | that have NULL instead of function pointer in command table in commands.cc. 35 | -------------------------------------------------------------------------------- /src/StringPool.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "StringPool.h" 22 | #include "xarray.h" 23 | 24 | xarray_m StringPool::strings; 25 | 26 | const char *StringPool::Get(const char *s) 27 | { 28 | if(!s) 29 | return 0; 30 | 31 | int l=0; 32 | int u=strings.count(); 33 | 34 | while(l0) 43 | u=m; 44 | else 45 | l=m+1; 46 | } 47 | 48 | // not found. 49 | // l==u points to first elementh greater than s or past end of array. 50 | strings.insert(xstrdup(s),u); 51 | return strings[u]; 52 | } 53 | -------------------------------------------------------------------------------- /lib/hstrerror.c: -------------------------------------------------------------------------------- 1 | /* A replacement version of hstrerror 2 | 3 | Copyright (C) 1996 Free Software Foundation, Inc. 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation; either version 2, or (at 8 | your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #ifdef HAVE_CONFIG_H 20 | #include 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #if defined (HAVE_H_ERRLIST) && !defined (HAVE_H_ERRLIST_DECL) 27 | extern int h_nerrs; 28 | extern char *h_errlist[]; 29 | #endif 30 | 31 | /* Return a string describing the host lookup error code HERR. The returned 32 | value may be in a static buffer (and in any case shouldn't be written to). */ 33 | const char * 34 | hstrerror (herr) 35 | int herr; 36 | { 37 | #ifdef HAVE_H_ERRLIST 38 | if (herr >= 0 && herr < h_nerrs && h_errlist[herr]) 39 | return h_errlist[herr]; 40 | else 41 | #endif 42 | { 43 | static char buf[100]; 44 | sprintf (buf, "Host lookup error %d", herr); 45 | return buf; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/buffer_zlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2013 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BUFFER_ZLIB_H 21 | #define BUFFER_ZLIB_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "buffer.h" 28 | 29 | class DataInflator : public DataTranslator 30 | { 31 | z_stream z; 32 | int z_err; 33 | public: 34 | DataInflator(); 35 | ~DataInflator(); 36 | void PutTranslated(Buffer *dst,const char *buf,int size); 37 | void ResetTranslation(); 38 | }; 39 | 40 | class DataDeflator : public DataTranslator 41 | { 42 | z_stream z; 43 | int z_err; 44 | public: 45 | DataDeflator(int level=Z_DEFAULT_COMPRESSION); 46 | ~DataDeflator(); 47 | void PutTranslated(Buffer *dst,const char *buf,int size); 48 | void ResetTranslation(); 49 | }; 50 | 51 | #endif //BUFFER_ZLIB_H 52 | -------------------------------------------------------------------------------- /src/lftpget: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # lftpget - get a file with lftp 4 | # Copyright (c) 1999-2000 Alexander V. Lukyanov 5 | # This file is covered by GNU GPL. See file COPYING for details. 6 | 7 | if [ $# -eq 0 ]; then 8 | echo "Usage: $0 [-c] [-d] [-v] URL [URL...]" 9 | echo " -c continue, reget" 10 | echo " -d debug output" 11 | echo " -v verbose messages" 12 | exit 1 13 | fi 14 | 15 | INTRO="set cmd:at-exit;set xfer:max-redirections 16;" 16 | SCRIPT="" 17 | verbose=false 18 | 19 | while : 20 | do 21 | case "$1" in 22 | -*v*) verbose=true 23 | INTRO="$INTRO set cmd:verbose y;" 24 | ;; 25 | esac 26 | case "$1" in 27 | -*d*) INTRO="$INTRO debug 8;";; 28 | esac 29 | case "$1" in 30 | -*c*) CONT=-c;; 31 | -*[dv]*) ;; 32 | *) break;; 33 | esac 34 | shift 35 | done 36 | 37 | for f 38 | do 39 | need_pass=false 40 | case "$f" in 41 | "*[\"'\\]*") 42 | # need to quote 43 | f="`echo "$f" | sed 's/\([\\\"'\'']\)/\\\1/g'`" 44 | ;; 45 | esac 46 | case "$f" in 47 | "*://*:*@*") ;; 48 | "*://*@*") need_pass=true;; 49 | esac 50 | 51 | if $verbose; then 52 | SCRIPT="$SCRIPT echo Retrieving \`\"$f\"\'...;" 53 | fi 54 | 55 | if $need_pass; then 56 | SCRIPT="$SCRIPT echo \"$f\" needs password;" 57 | fi 58 | SCRIPT="$SCRIPT get1 $CONT \"$f\";" 59 | 60 | if $verbose; then 61 | SCRIPT="$SCRIPT && echo Got \`\"$f\"\'.;" 62 | fi 63 | done 64 | 65 | if [ "$SCRIPT" = "" ]; then 66 | echo "Usage: $0 URL [URL...]" >&2 67 | exit 1 68 | fi 69 | 70 | exec lftp -c "$INTRO $SCRIPT" 71 | -------------------------------------------------------------------------------- /src/EditJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2015 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef EDITJOB_H 21 | #define EDITJOB_H 22 | 23 | #include "Job.h" 24 | 25 | class EditJob : public SessionJob 26 | { 27 | xstring_c file; 28 | xstring_c temp_file; 29 | bool keep; 30 | JobRef get; 31 | JobRef editor; 32 | JobRef put; 33 | time_t mtime; 34 | int exit_code; 35 | bool done; 36 | 37 | int HandleJob(JobRef& j, bool fail=true); 38 | void Finish(int code); 39 | 40 | public: 41 | EditJob(FileAccess *s,const char *f,const char *t) 42 | : SessionJob(s), file(f), temp_file(t), keep(false), 43 | mtime(0), exit_code(0), done(false) {} 44 | int Do(); 45 | int Done() { return done; } 46 | int ExitCode() { return exit_code; } 47 | void KeepTempFile(bool k) { keep=k; } 48 | }; 49 | 50 | #endif//EDITJOB_H 51 | -------------------------------------------------------------------------------- /src/FileCopyFtp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef FILECOPYFTP_H 21 | #define FILECOPYFTP_H 22 | 23 | #include "FileCopy.h" 24 | #include "ftpclass.h" 25 | 26 | class FileCopyFtp : public FileCopy 27 | { 28 | bool no_rest; 29 | bool passive_source; 30 | bool orig_passive_source; 31 | bool disable_fxp; 32 | #if USE_SSL 33 | bool protect; 34 | bool passive_ssl_connect; 35 | bool orig_passive_ssl_connect; 36 | #endif 37 | int src_retries; 38 | int dst_retries; 39 | time_t src_try_time; 40 | time_t dst_try_time; 41 | 42 | void Close(); 43 | 44 | public: 45 | void Init(); 46 | FileCopyFtp(FileCopyPeer *src,FileCopyPeer *dst,bool cont,bool rp); 47 | 48 | int Do(); 49 | 50 | static FileCopy *New(FileCopyPeer *src,FileCopyPeer *dst,bool cont); 51 | }; 52 | 53 | #endif // FILECOPYFTP_H 54 | -------------------------------------------------------------------------------- /lftp.lsm: -------------------------------------------------------------------------------- 1 | Begin3 2 | Title: LFTP command line file transfer program 3 | Version: 4.6.4 4 | Entered-date: 2015-08-20 5 | Description: LFTP is a shell-like command line file transfer program. It is 6 | reliable: can retry operations and does reget automatically. 7 | It can do several transfers simultaneously in background. 8 | You can start a transfer in background and continue browsing 9 | the ftp site or another one. This all is done in one process. 10 | Background jobs will be completed in nohup mode if you exit 11 | or close modem connection. Lftp has reput, mirror, reverse 12 | mirror among its features. Since version 2.0 it also supports 13 | http protocol. Other features include: ipv6 support, context 14 | sensitive completion, output redirection to files or to pipe, 15 | SOCKS support (configure option), ftp and http proxy support, 16 | transfer rate throttling for each connection and for all 17 | connections in sum, job queueing, job execution at specified 18 | time, opie/skey support in ftp protocol, ssl for http and ftp, 19 | fxp transfers. Version 3.0 supports sftp v3 and v4 protocols. 20 | Version 4.0 supports BitTorrent protocol. 21 | Keywords: ftp, client, readline, reliable, background, parallel, http, 22 | protocol, network, fish, sftp, https, ftps, torrent 23 | Author: lav@yars.free.net (Alexander V. Lukyanov) 24 | Maintained-by: lav@yars.free.net (Alexander V. Lukyanov) 25 | Primary-site: ftp.yars.free.net /pub/source/lftp 26 | 2593 kB lftp-4.6.4.tar.gz 27 | Alternate-site: metalab.unc.edu /pub/Linux/system/network/file-transfer 28 | Platforms: Unix, G++ 29 | Copying-policy: GNU GPL 30 | End 31 | -------------------------------------------------------------------------------- /src/mgetJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef MGETJOB_H 21 | #define MGETJOB_H 22 | 23 | #include "GetJob.h" 24 | #include "FileGlob.h" 25 | #include "mkdirJob.h" 26 | 27 | class mgetJob : public GetJob 28 | { 29 | Ref rg; 30 | JobRef mkdir_job; 31 | Ref mkdir_args; 32 | int mkdir_base_arg; 33 | Ref m_args; 34 | xstring_c output_dir; 35 | 36 | bool make_dirs; 37 | void make_directory(const char *d); 38 | 39 | void LocalGlob(const char *p); 40 | 41 | public: 42 | int Do(); 43 | xstring& FormatStatus(xstring&,int,const char *); 44 | void ShowRunStatus(const SMTaskRef&); 45 | 46 | mgetJob(FileAccess *session,ArgV *args,bool c,bool md); 47 | ~mgetJob(); 48 | 49 | void OutputDir(char *o) { output_dir.set_allocated(o); } 50 | }; 51 | 52 | #endif // MGETJOB_H 53 | -------------------------------------------------------------------------------- /src/History.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef HISTORY_H 21 | #define HISTORY_H 22 | 23 | #include "keyvalue.h" 24 | #include "FileAccess.h" 25 | 26 | class History : public KeyValueDB 27 | { 28 | KeyValueDB *full; 29 | time_t stamp; 30 | 31 | xstring file; 32 | int fd; 33 | bool modified; 34 | 35 | void Load(); 36 | void Close(); 37 | void Refresh(); 38 | 39 | const char *extract_url(const char *res); 40 | time_t extract_stamp(const char *res); 41 | 42 | public: 43 | void Set(const FileAccess *s,const FileAccess::Path &p); 44 | void Set(const FileAccess *s) { Set(s,s->GetCwd()); } 45 | const char *Lookup(const FileAccess *s); 46 | void Save(); 47 | History(); 48 | ~History(); 49 | 50 | void Rewind() 51 | { 52 | Refresh(); 53 | KeyValueDB::Rewind(); 54 | } 55 | }; 56 | 57 | #endif //HISTORY_H 58 | -------------------------------------------------------------------------------- /src/DummyProto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DUMMYPROTO_H 21 | #define DUMMYPROTO_H 22 | 23 | #include "FileAccess.h" 24 | 25 | class DummyProto : public FileAccess 26 | { 27 | public: 28 | int Do(); 29 | int Done(); 30 | const char *GetProto() const; 31 | FileAccess *Clone() const; 32 | int Read(Buffer *buf,int size); 33 | int Write(const void *buf,int size); 34 | int StoreStatus(); 35 | void Reconfig(const char *) {} 36 | 37 | ListInfo *MakeListInfo(const char *path); 38 | DirList *MakeDirList(ArgV *); 39 | 40 | DummyProto(); 41 | ~DummyProto(); 42 | }; 43 | 44 | class DummyNoProto : public DummyProto 45 | { 46 | xstring_c proto; 47 | public: 48 | DummyNoProto(const char *p) : proto(p) {} 49 | 50 | const char *GetProto() const; 51 | FileAccess *Clone() const; 52 | const char *StrError(int err); 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/PtyShell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef PTYSHELL_H 21 | #define PTYSHELL_H 22 | 23 | #include "Filter.h" 24 | 25 | class PtyShell : public FDStream 26 | { 27 | Ref a; 28 | SMTaskRef w; 29 | pid_t pg; 30 | 31 | xstring_c oldcwd; 32 | 33 | bool closed; 34 | bool use_pipes; 35 | int pipe_in; 36 | int pipe_out; 37 | 38 | void Init(); 39 | 40 | public: 41 | PtyShell(const char *filter); 42 | PtyShell(ArgV *a); 43 | ~PtyShell(); 44 | 45 | void SetCwd(const char *); 46 | void UsePipes() { use_pipes=true; } 47 | 48 | int getfd(); 49 | int getfd_pipe_in() { return pipe_in; } 50 | int getfd_pipe_out() { return pipe_out; } 51 | bool Done(); 52 | 53 | void Kill(int sig=SIGTERM) { if(w) w->Kill(sig); } 54 | pid_t GetProcGroup() const { return pg; } 55 | 56 | bool broken(); 57 | }; 58 | 59 | #endif // PTYSHELL_H 60 | -------------------------------------------------------------------------------- /src/ftpget: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ftpget - script replacement for old utility 4 | # Copyright (c) 2000 Alexander V. Lukyanov 5 | # This file is covered by GNU GPL. See file COPYING for details. 6 | 7 | usage() 8 | { 9 | echo "Usage: $0 [OPTS] host filename [-o local] [filename...]" 10 | echo " -p set port number" 11 | echo " -u login as user using pass as password" 12 | echo " -l get listing of specified directory(ies)" 13 | echo " -c reget specified file(s)" 14 | echo " -q quiet (no output)" 15 | echo " -v verbose (lots of output)" 16 | echo " -o output to this file (default - base name of filename)" 17 | exit 1 18 | } 19 | 20 | port="" 21 | user="" 22 | list=false 23 | cont="" 24 | verb="" 25 | final="set verbose yes; " 26 | 27 | while getopts +p:u:lcv opt 28 | do 29 | case $opt in 30 | \?) usage;; 31 | p) port=":$OPTARG";; 32 | u) user="-u $OPTARG ";; 33 | l) list=true;; 34 | c) cont=" -c";; 35 | v) verb="debug 5; ";; 36 | q) final="";; 37 | esac 38 | done 39 | while [ $OPTIND -gt 1 ] 40 | do 41 | OPTIND=$(($OPTIND-1)) 42 | shift 43 | done 44 | host="$1" 45 | shift 46 | 47 | if [ -z "$host" ]; then 48 | usage 49 | fi 50 | 51 | cmd="get$cont" 52 | ok=false 53 | $list && { cmd="ls"; ok=true; } 54 | 55 | for f 56 | do 57 | case "$f" in 58 | "*[\"'\\]*") 59 | # need to quote 60 | f="`echo "$f" | sed 's/\([\\\"'\'']\)/\\\1/g'`" 61 | ;; 62 | esac 63 | cmd="$cmd \"$f\"" 64 | ok=true; 65 | done 66 | 67 | $ok || { usage; } 68 | 69 | exec lftp -c "$final${verb}open $user$host$port; $cmd" 70 | -------------------------------------------------------------------------------- /src/mvJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef MVJOB_H 21 | #define MVJOB_H 22 | 23 | #include "Job.h" 24 | #include "StatusLine.h" 25 | #include "ArgV.h" 26 | #include "trio.h" 27 | 28 | class mvJob : public SessionJob 29 | { 30 | xstring_c from; 31 | xstring to; 32 | FA::open_mode m; 33 | bool remove_target; 34 | bool failed; 35 | bool done; 36 | 37 | public: 38 | int Do(); 39 | int Done() { return done; } 40 | int ExitCode() { return failed; } 41 | 42 | xstring& FormatStatus(xstring&,int,const char *); 43 | void ShowRunStatus(const SMTaskRef&); 44 | void SayFinal(); 45 | 46 | void doOpen() const; 47 | const char *cmd() const { return m==FA::RENAME ? "mv" : "ln"; } 48 | 49 | mvJob(FileAccess *session,const char *f,const char *t,FA::open_mode m=FA::RENAME); 50 | void RemoveTargetFirst() { remove_target=true; } 51 | }; 52 | 53 | #endif // MVJOB_H 54 | -------------------------------------------------------------------------------- /m4/readline.m4: -------------------------------------------------------------------------------- 1 | dnl Check for libreadline of proper version 2 | AC_DEFUN([READLINE_CHECK], 3 | [AC_MSG_CHECKING(for readline) 4 | dnl AC_ARG_WITH(included-readline, 5 | dnl [ --with-included-readline use supplied readline instead of system one], 6 | dnl [with_included_readline=$withval],[with_included_readline=auto]) 7 | case "$with_included_readline" in 8 | yes) lftp_cv_precompiled_readline=no;; 9 | no) lftp_cv_precompiled_readline=yes;; 10 | *) 11 | AC_CACHE_VAL(lftp_cv_precompiled_readline, 12 | [ 13 | old_LIBS="$LIBS" 14 | LIBS="-lreadline $READLINE_SUPPLIB $LIBS" 15 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern int (*rl_getc_function)();]], [[rl_getc_function=0; 16 | rl_completion_matches(0,0);]])],[AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include ]])],[lftp_cv_precompiled_readline=yes],[lftp_cv_precompiled_readline=no]) 17 | ],[lftp_cv_precompiled_readline=no]) 18 | LIBS="$old_LIBS" 19 | ]) 20 | ;; 21 | esac 22 | if test $lftp_cv_precompiled_readline = yes; then 23 | READLINE_DIR='' 24 | AC_MSG_RESULT(yes) 25 | READLINE='-lreadline' 26 | READLINE_DEPEND='' 27 | COMPILE_READLINE=no 28 | else 29 | READLINE_DIR=readline-4.3 30 | if ! test -d $READLINE_DIR; then 31 | AC_MSG_ERROR(need installed readline-devel package) 32 | fi 33 | dnl AC_CONFIG_SUBDIRS(readline-4.3) 34 | AC_MSG_RESULT(no - will compile) 35 | AC_CONFIG_LINKS([include/readline:$READLINE_DIR]) 36 | READLINE='$(top_builddir)/$(READLINE_DIR)/libreadline.a' 37 | READLINE_DEPEND='$(top_builddir)/$(READLINE_DIR)/libreadline.a' 38 | COMPILE_READLINE=yes 39 | fi 40 | AC_SUBST(COMPILE_READLINE) 41 | AC_SUBST(READLINE_DIR) 42 | AC_SUBST(READLINE_DEPEND) 43 | AC_SUBST(READLINE) 44 | ]) 45 | -------------------------------------------------------------------------------- /src/TreatFileJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef TREATFILEJOB_H 21 | #define TREATFILEJOB_H 22 | 23 | #include "Job.h" 24 | #include "FindJob.h" 25 | 26 | class StatusLine; 27 | class ArgV; 28 | 29 | class TreatFileJob : public FinderJob 30 | { 31 | protected: 32 | Ref args; 33 | const FileInfo *curr; 34 | Ref first; 35 | int failed,file_count; 36 | 37 | virtual void TreatCurrent(const char *d,const FileInfo *fi) = 0; 38 | virtual void CurrentFinished(const char *d,const FileInfo *fi) { } 39 | 40 | void Begin(const char *d); 41 | 42 | /* virtuals */ 43 | void Finish(); 44 | prf_res ProcessFile(const char *d,const FileInfo *fi); 45 | 46 | public: 47 | xstring& FormatStatus(xstring&,int,const char *); 48 | void ShowRunStatus(const SMTaskRef&); 49 | 50 | TreatFileJob(FileAccess *session,ArgV *a); 51 | virtual ~TreatFileJob(); 52 | }; 53 | 54 | #endif // TREATFILEJOB_H 55 | -------------------------------------------------------------------------------- /src/DirColors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DIRCOLORS_H 21 | #define DIRCOLORS_H 22 | 23 | #include "SMTask.h" 24 | #include "keyvalue.h" 25 | #include "buffer.h" 26 | 27 | class FileInfo; 28 | 29 | class DirColors : public ResClient, public KeyValueDB 30 | { 31 | static DirColors *instance; 32 | 33 | static const char resource[]; 34 | void Parse(const char *); 35 | 36 | public: 37 | void Reconfig(const char *name); 38 | 39 | DirColors(); 40 | 41 | const char *GetColor(const FileInfo *); 42 | const char *GetColor(const char *,int); 43 | void PutColored(const Ref& buf,const char *name,int type); 44 | void PutReset(const Ref& buf); 45 | 46 | static DirColors *GetInstance() 47 | { 48 | if(!instance) 49 | instance=new DirColors(); 50 | return instance; 51 | } 52 | static void DeleteInstance() 53 | { 54 | delete instance; 55 | instance=0; 56 | } 57 | }; 58 | #endif 59 | -------------------------------------------------------------------------------- /src/mkdirJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef MKDIRJOB_H 21 | #define MKDIRJOB_H 22 | 23 | #include "Job.h" 24 | #include "StatusLine.h" 25 | #include "ArgV.h" 26 | #include "trio.h" 27 | 28 | class mkdirJob : public SessionJob 29 | { 30 | Ref args; 31 | const char *curr,*first; 32 | FileAccessRef my_session; 33 | FileAccessRefC session; 34 | int failed,file_count; 35 | bool quiet; 36 | bool opt_p; 37 | 38 | public: 39 | int Do(); 40 | int Done() { return curr==0; } 41 | int ExitCode() { return failed!=0; } 42 | 43 | xstring& FormatStatus(xstring&,int,const char *); 44 | void ShowRunStatus(const SMTaskRef&); 45 | void SayFinal(); 46 | 47 | mkdirJob(FileAccess *session,ArgV *a); 48 | void PrepareToDie() { session->Close(); SessionJob::PrepareToDie(); } 49 | 50 | void BeQuiet() { quiet=true; } 51 | 52 | void Fg(); 53 | void Bg(); 54 | }; 55 | 56 | #endif // MKDIRJOB_H 57 | -------------------------------------------------------------------------------- /src/xmalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMALLOC_H 21 | #define XMALLOC_H 22 | 23 | #include 24 | 25 | #ifdef DBMALLOC 26 | #include "dbmalloc.h" 27 | #endif 28 | 29 | void *xmalloc(size_t); 30 | void *xrealloc(void *,size_t); 31 | char *xstrdup(const char *s,int spare=0); 32 | char *xstrset(char *&mem,const char *s); 33 | char *xstrset(char *&mem,const char *s,size_t n); 34 | #define alloca_strdup(s) alloca_strdup2((s),0) 35 | #define alloca_strdup2(s,n) ((s)?strcpy((char*)alloca(strlen((s))+1+(n)),(s)) \ 36 | :((n)==0?0:(char*)alloca((n)))) 37 | #define alloca_append(s1,s2) strcat(alloca_strdup2((s1),strlen((s2))),(s2)); 38 | 39 | void xfree(void *p); 40 | void xmalloc_register_block(void *); 41 | 42 | #include "xstring.h" 43 | 44 | static inline void *xmemdup(const void *m,int len) 45 | { 46 | if(!m) return 0; 47 | void *buf=xmalloc(len); 48 | memcpy(buf,m,len); 49 | return buf; 50 | } 51 | 52 | #endif /* XMALLOC_H */ 53 | -------------------------------------------------------------------------------- /src/FileFeeder.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "FileFeeder.h" 24 | 25 | const char *FileFeeder::NextCmd(CmdExec *exec, const char *) 26 | { 27 | int fd=in->getfd(); 28 | if(fd<0) 29 | { 30 | if(in->error()) 31 | { 32 | fprintf(stderr,"source: %s\n",in->error_text.get()); 33 | return 0; 34 | } 35 | return ""; 36 | } 37 | if(fg_data==0) 38 | fg_data=new FgData(in->GetProcGroup(),true); 39 | int res=read(fd,buffer,sizeof(buffer)-1); 40 | if(res==0) 41 | { 42 | return 0; 43 | } 44 | if(res<0) 45 | { 46 | if(E_RETRY(errno)) 47 | { 48 | exec->Block(fd,POLLIN); 49 | return ""; 50 | } 51 | if(SMTask::NonFatalError(errno)) 52 | return ""; 53 | perror("source"); 54 | return 0; 55 | } 56 | buffer[res]=0; 57 | return buffer; 58 | } 59 | 60 | FileFeeder::FileFeeder(FDStream *in) 61 | : in(in) 62 | { 63 | } 64 | FileFeeder::~FileFeeder() 65 | { 66 | } 67 | -------------------------------------------------------------------------------- /lftp.spec: -------------------------------------------------------------------------------- 1 | %define version 4.6.4 2 | %define release 1 3 | %define use_modules 0 4 | 5 | Summary: Sophisticated CLI file transfer program 6 | Name: lftp 7 | Version: %{version} 8 | Release: %{release} 9 | URL: http://lftp.yar.ru/ 10 | Source: http://lftp.yar.ru/ftp/lftp-%{version}.tar.gz 11 | Group: Applications/Internet 12 | BuildRoot: %{_tmppath}/%{name}-buildroot 13 | BuildRequires: readline-devel zlib-devel ncurses-devel expat-devel gnutls-devel 14 | License: GNU GPL 15 | #Packager: Manoj Kasichainula 16 | 17 | %description 18 | lftp is CLI file transfer program. It supports FTP, HTTP, FISH and 19 | SFTP protocols, has lots of features including mirror. It was designed 20 | with reliability in mind. GNU Readline library is used for input. 21 | There is also support for secure variants of FTP and HTTP. 22 | 23 | %prep 24 | %setup 25 | 26 | %build 27 | 28 | # Make sure that all message catalogs are built 29 | if [ "$LINGUAS" ]; then 30 | unset LINGUAS 31 | fi 32 | 33 | # The lftp maintainer seems to use a newer version of libtool than Red 34 | # Hat (even 7.0) ships with. So make sure that we don't muck with 35 | # ltconfig 36 | %define __libtoolize : 37 | %if %use_modules 38 | %configure --with-modules 39 | %else 40 | %configure 41 | %endif 42 | make DESTDIR=%{buildroot} 43 | 44 | %install 45 | rm -rf %{buildroot} 46 | make install DESTDIR=%{buildroot} 47 | rm -f %{buildroot}%{_libdir}/*.{so,la,a} 48 | 49 | %clean 50 | rm -rf %{buildroot} 51 | 52 | %files 53 | %defattr(644 root root 755) 54 | %doc ABOUT-NLS BUGS COPYING FAQ FEATURES NEWS README* THANKS TODO lftp.lsm 55 | %config /etc/lftp.conf 56 | %attr(755 root root) %{_bindir}/* 57 | %if %use_modules 58 | %{_libdir}/lftp/*/*.so 59 | %{_libdir}/*.so.* 60 | %endif 61 | %{_mandir}/man*/* 62 | %attr(755 root root) %{_datadir}/lftp/* 63 | %{_datadir}/locale/*/*/* 64 | -------------------------------------------------------------------------------- /src/ProcWait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef PROCWAIT_H 21 | #define PROCWAIT_H 22 | 23 | #include 24 | #include 25 | #include "SMTask.h" 26 | #include "xmap.h" 27 | 28 | class ProcWait : public SMTask 29 | { 30 | public: 31 | enum State 32 | { 33 | TERMINATED, 34 | RUNNING, 35 | ERROR 36 | }; 37 | 38 | protected: 39 | static xmap all_proc; 40 | static const xstring& proc_key(pid_t p); // make key for xmap 41 | 42 | const pid_t pid; 43 | State status; 44 | int term_info; 45 | int saved_errno; 46 | bool auto_die; 47 | 48 | bool handle_info(int info); // true if finished 49 | 50 | ~ProcWait(); 51 | 52 | public: 53 | int Do(); 54 | State GetState() { return status; } 55 | int GetInfo() { return term_info; } 56 | int Kill(int sig=SIGTERM); 57 | 58 | void Auto() { auto_die=true; } 59 | 60 | ProcWait(pid_t p); 61 | 62 | static void Signal(bool yes); 63 | 64 | static void DeleteAll(); 65 | }; 66 | 67 | #endif /* PROCWAIT_H */ 68 | -------------------------------------------------------------------------------- /src/bookmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2015 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BOOKMARK_H 21 | #define BOOKMARK_H 22 | 23 | #include 24 | #include "keyvalue.h" 25 | 26 | class Bookmark : public KeyValueDB 27 | { 28 | xstring bm_file; 29 | int bm_fd; 30 | time_t stamp; 31 | 32 | void Save(); 33 | void Load(); 34 | void Refresh(); 35 | int Lock(int type) { return KeyValueDB::Lock(bm_fd,type); } 36 | void PreModify(); 37 | void PostModify(); 38 | void Close(); 39 | void AutoSync(); 40 | public: 41 | void Add(const char *id,const char *value); 42 | void Remove(const char *id); 43 | const char *Lookup(const char *id); 44 | char *Format(); 45 | char *FormatHidePasswords(); 46 | void UserLoad() { Load(); Close(); } 47 | void UserSave(); 48 | 49 | Bookmark(); 50 | ~Bookmark(); 51 | 52 | void Rewind() 53 | { 54 | Refresh(); 55 | KeyValueDB::Rewind(); 56 | } 57 | 58 | const xstring& GetFilePath() const { return bm_file; } 59 | }; 60 | 61 | extern Bookmark lftp_bookmarks; 62 | 63 | #endif //BOOKMARK_H 64 | -------------------------------------------------------------------------------- /src/CharReader.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include "trio.h" 26 | #include "CharReader.h" 27 | 28 | int CharReader::Do() 29 | { 30 | int m=STALL; 31 | if(ch!=NOCHAR) 32 | return m; 33 | if(!Ready(fd,POLLIN)) 34 | { 35 | Block(fd,POLLIN); 36 | return m; 37 | } 38 | 39 | int oldfl=fcntl(fd,F_GETFL); 40 | if(!(oldfl&O_NONBLOCK)) 41 | fcntl(fd,F_SETFL,oldfl|O_NONBLOCK); 42 | 43 | unsigned char c; 44 | int res=read(fd,&c,1); 45 | if(res==-1 && errno==EAGAIN) 46 | Block(fd,POLLIN); 47 | else if(res==-1 && errno==EINTR) 48 | m=MOVED; 49 | else if(res>0) 50 | { 51 | ch=c; 52 | m=MOVED; 53 | } 54 | else // eof or error. 55 | { 56 | ch=EOFCHAR; 57 | m=MOVED; 58 | } 59 | 60 | if(!(oldfl&O_NONBLOCK)) 61 | fcntl(fd,F_SETFL,oldfl); 62 | 63 | if(res==-1 && ch==EOFCHAR) 64 | fprintf(stderr,"read(%d): %s\n",fd,strerror(errno)); 65 | 66 | return m; 67 | } 68 | -------------------------------------------------------------------------------- /src/ConnectionSlot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CONNECTIONSLOT_H 21 | #define CONNECTIONSLOT_H 22 | 23 | #include "FileAccess.h" 24 | #include "keyvalue.h" 25 | 26 | class ConnectionSlot : public KeyValueDB 27 | { 28 | static ConnectionSlot lftp_slots; 29 | 30 | class SlotValue : public KeyValueDB::Pair 31 | { 32 | public: 33 | FileAccessRef session; 34 | SlotValue(const char *n,const FileAccess *s); 35 | SlotValue(const char *n,const char *v); 36 | }; 37 | 38 | Pair *NewPair(const char *n,const char *v) 39 | { 40 | return new SlotValue(n,v); 41 | } 42 | 43 | public: 44 | static ConnectionSlot::SlotValue *Find(const char *n); 45 | static const FileAccess *FindSession(const char *n); 46 | static void Set(const char *n,const FileAccess *s); 47 | static void SetCwd(const char *n,const FileAccess::Path &cwd); 48 | static void Remove(const char *n); 49 | static char *Format(); 50 | char *FormatThis(); 51 | static void Cleanup(); 52 | ConnectionSlot(); 53 | ~ConnectionSlot(); 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/Cache.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "Cache.h" 22 | 23 | void Cache::Trim() 24 | { 25 | long sizelimit=res_max_size->Query(0); 26 | 27 | long size=0; 28 | CacheEntry **scan=&chain; 29 | while(scan[0]) 30 | { 31 | if(scan[0]->Stopped()) 32 | delete replace_value(scan[0],scan[0]->next); 33 | else 34 | { 35 | size+=scan[0]->EstimateSize(); 36 | scan=&scan[0]->next; 37 | } 38 | } 39 | // printf("Cache::Trim size=%ld, limit=%ld\n",size,sizelimit); 40 | while(chain && size>sizelimit) 41 | { 42 | size-=chain->EstimateSize(); 43 | delete replace_value(chain,chain->next); 44 | } 45 | } 46 | void Cache::Flush() 47 | { 48 | while(chain) 49 | delete replace_value(chain,chain->next); 50 | } 51 | CacheEntry *Cache::IterateFirst() 52 | { 53 | curr=&chain; 54 | return *curr; 55 | } 56 | CacheEntry *Cache::IterateNext() 57 | { 58 | curr=&curr[0]->next; 59 | return *curr; 60 | } 61 | CacheEntry *Cache::IterateDelete() 62 | { 63 | delete replace_value(curr[0],curr[0]->next); 64 | return *curr; 65 | } 66 | -------------------------------------------------------------------------------- /src/fg.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "trio.h" 24 | #include "fg.h" 25 | 26 | void FgData::cont() 27 | { 28 | if(!pg) 29 | return; 30 | if(kill(-pg,SIGCONT)==-1) 31 | kill(pg,SIGCONT); 32 | } 33 | 34 | FgData::FgData(pid_t npg,bool fg) 35 | { 36 | old_pgrp=0; 37 | pg=npg; 38 | if(!pg) 39 | return; 40 | if(fg) 41 | Fg(); 42 | else 43 | cont(); 44 | } 45 | 46 | FgData::~FgData() 47 | { 48 | if(old_pgrp) 49 | Bg(); 50 | } 51 | 52 | void FgData::Fg() 53 | { 54 | if(!pg) 55 | return; 56 | pid_t tc_grp=tcgetpgrp(0); 57 | if(tc_grp==-1 || tc_grp==getpgrp()) 58 | { 59 | old_pgrp=getpgrp(); 60 | #ifdef FG_DEBUG 61 | printf("fg: tcsetpgrp(%d)\n",(int)pg); 62 | #endif 63 | tcsetpgrp(0,pg); 64 | } 65 | cont(); 66 | } 67 | 68 | void FgData::Bg() 69 | { 70 | if(old_pgrp) 71 | { 72 | #ifdef FG_DEBUG 73 | printf("bg: tcsetpgrp(%d)\n",(int)old_pgrp); 74 | #endif 75 | tcsetpgrp(0,old_pgrp); 76 | old_pgrp=0; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /FAQ: -------------------------------------------------------------------------------- 1 | Q: I have compile/link problems. 2 | A: Some common installation problems are described in the INSTALL file. 3 | If your case is not covered, please send a problem report. 4 | 5 | Q: How can I see the greeting message from the server? 6 | A: Try `debug 3'. It is disabled by default to keep the screen clear in case 7 | of several simultaneous connections. 8 | 9 | Q: Why doesn't lftp download files like this: `lftp ftp://host/path/file'? 10 | A: It expects an URL of a directory. To download a file use `lftpget URL'. 11 | 12 | Q: What is the %2F in ftp URL's? 13 | A: RFC1738 specifies that clients handling ftp URL's should interpret them 14 | as HOME relative by default. %2F stands for leading slash pointing to 15 | the root directory. 16 | 17 | Q: Why do the secure protocols https and ftps give the "PRNG not seeded" error 18 | message? 19 | A: Your system probably lacks a /dev/random-like device. Create a ~/.rnd file 20 | containing random characters and SSL will work. See also the OpenSSL FAQ 21 | about this. 22 | 23 | Q: Why does lftp say that locking fails all the time? (on linux) 24 | A: You have compiled lftp with large file support (>2G) but your kernel 25 | does not support 64-bit file-locking. Either install a better kernel 26 | (e.g. linux-2.4.x) or compile lftp without large file support 27 | (configure --disable-largefile) 28 | 29 | Q: Where is lls? 30 | A: !ls 31 | 32 | Q: Why doesn't `mirror' download files starting with a dot (or re-uploads 33 | them all the time)? I can see the files on the server using `ls -a'. 34 | A: Try `set ftp:list-options -a'. 35 | 36 | Q: ^Z doesn't work in Cygwin. 37 | A: Use "SET CYGWIN=TTY". This must be done before starting a shell, if any. 38 | 39 | Q: lftp consumes 100% CPU on MacOS X Tiger just waiting at the command prompt. 40 | A: See http://www.mail-archive.com/lftp%40uniyar.ac.ru/msg02101.html for 41 | a workaround for MacOS X bug. 42 | -------------------------------------------------------------------------------- /src/Cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CACHE_H 21 | #define CACHE_H 22 | 23 | #include "Timer.h" 24 | 25 | class CacheEntry : public Timer 26 | { 27 | friend class Cache; 28 | CacheEntry *next; 29 | public: 30 | CacheEntry() { next=0; } 31 | virtual int EstimateSize() const { return 1; } 32 | virtual ~CacheEntry() {} 33 | }; 34 | class Cache 35 | { 36 | const ResType *res_max_size; 37 | const ResType *res_enable; 38 | protected: 39 | CacheEntry *chain; 40 | CacheEntry **curr; 41 | CacheEntry *IterateFirst(); 42 | CacheEntry *IterateNext(); 43 | CacheEntry *IterateDelete(); 44 | public: 45 | void Trim(); 46 | void Flush(); 47 | Cache(const ResType *s,const ResType *e) { 48 | res_max_size=s; 49 | res_enable=e; 50 | chain=0; 51 | curr=0; 52 | } 53 | ~Cache() { Flush(); } 54 | bool IsEnabled(const char *closure) { return res_enable->QueryBool(closure); } 55 | long SizeLimit() { return res_max_size->Query(0); } 56 | void AddCacheEntry(CacheEntry *e) { 57 | e->next=chain; 58 | chain=e; 59 | } 60 | }; 61 | 62 | #endif//CACHE_H 63 | -------------------------------------------------------------------------------- /src/ChmodJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef CHMODJOB_H 21 | #define CHMODJOB_H 22 | 23 | #include "TreatFileJob.h" 24 | #include "FileSet.h" 25 | CDECL_BEGIN 26 | #include "modechange.h" 27 | CDECL_END 28 | 29 | class ChmodJob : public TreatFileJob 30 | { 31 | public: 32 | enum verbosity { V_NONE, V_CHANGES, V_ALL }; 33 | 34 | private: 35 | void TreatCurrent(const char *d,const FileInfo *fi); 36 | void CurrentFinished(const char *d,const FileInfo *fi); 37 | 38 | void Init(); 39 | void Report(const char *d,const FileInfo *fi, bool success); 40 | bool RelativeMode(const mode_change *m) const; 41 | 42 | verbosity verbose; 43 | mode_change *m; 44 | int simple_mode; 45 | int GetMode(const FileInfo *fi) const; 46 | 47 | public: 48 | /* if you use this constructor, also set a mode with SetMode() */ 49 | ChmodJob(FileAccess *s,ArgV *a); 50 | /* simple "chmod 123" interface: */ 51 | ChmodJob(FileAccess *s,int m,ArgV *a); 52 | ~ChmodJob(); 53 | 54 | void SetVerbosity(verbosity v); 55 | void SetMode(mode_change *newm); 56 | void Recurse(); 57 | }; 58 | 59 | #endif//CHMODJOB_H 60 | -------------------------------------------------------------------------------- /src/Speedometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef SPEEDOMETER_H 21 | #define SPEEDOMETER_H 22 | 23 | #include "SMTask.h" 24 | #include "ResMgr.h" 25 | 26 | class Speedometer : public ResClient 27 | { 28 | int period; 29 | float rate; 30 | Time last_second; 31 | Time last_bytes; 32 | Time start; 33 | bool terse; 34 | const char *period_resource; 35 | public: 36 | Speedometer(const char *p="xfer:rate-period"); 37 | float Get(); 38 | float Get() const { return rate; } 39 | static xstring& GetStr(float r); 40 | static xstring& GetStrProper(float r); 41 | xstring& GetStr(); 42 | static const char *GetStrS(float r); 43 | const char *GetStrS(); 44 | xstring& GetETAStrFromSize(off_t s); 45 | const char *GetETAStrSFromSize(off_t s); 46 | xstring& GetETAStrFromTime(long t); 47 | const char *GetETAStrSFromTime(long t); 48 | bool Valid(); 49 | void Add(int bytes); 50 | void Reset(); 51 | void SetPeriod(int p) { period=p; } 52 | void SetPeriodName(const char *p) { period_resource=p; Reconfig(0); } 53 | void SetTerseETA(bool t) { terse=t; } 54 | void Reconfig(const char *s); 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/SignalHook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef SIGNALHOOK_H 21 | #define SIGNALHOOK_H 22 | 23 | #include 24 | 25 | typedef void (*signal_handler)(int); 26 | 27 | class SignalHook 28 | { 29 | static int *counts; 30 | static struct sigaction *old_handlers; 31 | static bool *old_saved; 32 | 33 | static void cnt_handler(int sig); 34 | static void set_signal(int sig,signal_handler handler); 35 | public: 36 | static void DoCount(int sig) { set_signal(sig,&SignalHook::cnt_handler); } 37 | static int GetCount(int sig) { return counts[sig]; } 38 | static void ResetCount(int sig) { counts[sig]=0; } 39 | static void IncreaseCount(int sig) { counts[sig]++; } 40 | static void Handle(int sig,void (*h)(int)) { set_signal(sig,h); } 41 | static void Ignore(int sig) { set_signal(sig,(signal_handler)SIG_IGN); } 42 | static void Default(int sig) { set_signal(sig,(signal_handler)SIG_DFL); } 43 | static void Restore(int sig); 44 | static void Block(int sig); 45 | static void Unblock(int sig); 46 | static void RestoreAll(); 47 | 48 | static void ClassInit(); 49 | static void Cleanup(); 50 | }; 51 | 52 | #endif//SIGNALHOOK_H 53 | -------------------------------------------------------------------------------- /README.debug-levels: -------------------------------------------------------------------------------- 1 | Date: Wed, 22 Dec 1999 13:46:30 +0000 (GMT) 2 | Subject: Debug Levels 3 | From: Robert de Bath 4 | 5 | ... 6 | 7 | Level 0 8 | Errors and states that cause a significant change in program flow. 9 | => Anything that causes a Discon+Retry or a "giveup" message. 10 | 11 | Level 1 12 | Important or inaccessible state information. 13 | => Connection start, Idle disconnection. 14 | 15 | Level 2 16 | Rare things that cause a minor program flow adjustment. 17 | => No REST, No PASV, etc. 18 | 19 | Level 3 20 | Errors and useful messages that are slightly too verbose or common 21 | for 0-2 or don't quite fit in the classifications. 22 | => Login banner 23 | 24 | Level 4 25 | All remote responses or major results. (Trace results) 26 | => All "999 Xyzzy" responses received. 27 | 28 | Level 5 29 | All remote commands or major tasks. (Trace jobs) 30 | => All commands sent to server. 31 | 32 | Level 6 33 | General information that will not be too verbose but is normally a 34 | little less important. (Trace state) 35 | 36 | Level 7 37 | Similar to level 3 but verbose or not as useful. 38 | 39 | Level 8 40 | Very verbose information that'll probably be useful sometime. 41 | 42 | Level 9 43 | Anything and everything else, debugs that probably won't be useful 44 | ever again. (unclassified) 45 | 46 | Notes: 47 | If the programmer doesn't set the debug level this is not an important 48 | debug message or is only important right now. 49 | => default debug level == 9 50 | 51 | If something fits in one of the lower levels but is very verbose 52 | it should nevertheless be moved upto level 3 or levels 7-9. 53 | (Possibly leaving a single line 'oops' at the lower level) 54 | 55 | The general idea is that debug levels 0-3 should not scroll too fast 56 | to read and nothing below level 7 should be much more verbose than 57 | levels 4 or 5. 58 | 59 | ... 60 | -------------------------------------------------------------------------------- /src/SSH_Access.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef SSH_ACCESS_H 21 | #define SSH_ACCESS_H 22 | 23 | #include "NetAccess.h" 24 | #include "PtyShell.h" 25 | 26 | class SSH_Access : public NetAccess 27 | { 28 | protected: 29 | SMTaskRef pty_send_buf; 30 | SMTaskRef pty_recv_buf; 31 | SMTaskRef send_buf; 32 | SMTaskRef recv_buf; 33 | Ref ssh; 34 | int password_sent; 35 | const char *greeting; 36 | bool received_greeting; 37 | 38 | xstring last_ssh_message; 39 | time_t last_ssh_message_time; 40 | 41 | void MoveConnectionHere(SSH_Access *o); 42 | void DisconnectLL(); 43 | 44 | void MakePtyBuffers(); 45 | int HandleSSHMessage(); 46 | void LogSSHMessage(); /* it's called after the greeting is received 47 | * (or internally from HandleSSHMessage). */ 48 | 49 | SSH_Access(const char *g) : 50 | password_sent(0), 51 | greeting(g), received_greeting(false), 52 | last_ssh_message_time(0) {} 53 | 54 | SSH_Access(const SSH_Access *o) : NetAccess(o), 55 | password_sent(0), 56 | greeting(o->greeting), received_greeting(false), 57 | last_ssh_message_time(0) {} 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | The items with a question mark are questionable. I'm not sure whether they 2 | are really needed. If you think it is a good feature do it yourself :) or 3 | at least tell me what you think. Items marked with - are hard to implement 4 | currently; other work needs to be done. Items marked with + are partially 5 | implemented. 6 | 7 | * OpenStack Swift 8 | * GlusterFS 9 | 10 | ?* document variables in on-line help 11 | 12 | * mirror --config 13 | 14 | * update process title 15 | 16 | * implement Queueing in FileAccess. fa->AddQueue(new FAQueueOp(args)). 17 | (Done()==true when queue is empty) 18 | This way ARRAY_* can be obsoleted. 19 | 20 | * there are many interesting protocols which can be used to transfer 21 | files/data: smb, fsp, imap, irc, pop3... 22 | 23 | -* put -n (only if newer) Maybe it would be better to add a command to compare 24 | times? 25 | mirror can be used: mirror -Rr -I file 26 | 27 | * http: ls -a to see all links, even off-site. 28 | 29 | * mirror: add more settings. 30 | 31 | * more intelligently squeeze file name in status line. 32 | 33 | * parallel get's in mget 34 | +* make a command get1 to get a single file with extra options. 35 | 36 | * tail command 37 | 38 | * make a class FileAccessLocation (class url?) 39 | 40 | * job suspend/resume. 41 | 42 | * motd. if it is not yet known, connect/login and get it. (use class Buffer). 43 | 44 | * use NDIR (from RFC1127) in FtpListInfo, when long list cannot be parsed. 45 | 46 | ?* optimize help text, introduce a phrase separator for separate translations. 47 | ?* help in external files 48 | 49 | * a setting to make commands quiet (cmd:quiet? or cmd:verbose with int value) 50 | 51 | * redirect error messages 52 | * stdout/stderr analogues, use class IOBuffer. 53 | 54 | * mirror option to check an alternative directory(ies) for existing files. 55 | (overlay filesystem replacement?) 56 | * mirror: multiple source and target dirs. 57 | 58 | * APPE support. 59 | 60 | * better debug message subsystem 61 | -------------------------------------------------------------------------------- /src/convert-mozilla-cookies: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Copyright (c) 2001,2005,2007,2010 Alexander V. Lukyanov 3 | # See COPYING file (GNU GPL) for complete license. 4 | 5 | # This script converts mozilla-style cookies to lftp set commands. 6 | 7 | use strict; 8 | use DBI; 9 | 10 | my $file=$ARGV[0] if defined $ARGV[0]; 11 | $file=qx{ 12 | ls -t \$HOME/.netscape/cookies \\ 13 | `find \$HOME/.mozilla -name cookies.txt -or -name cookies.sqlite` | head -1 14 | },chomp $file if !defined $file; 15 | 16 | print "# converted from $file\n"; 17 | my %cookie; 18 | sub add_cookie($$$$$) { 19 | my ($domain,$path,$secure_bool,$name,$value)=@_; 20 | for($domain,$path,$name,$value) { s/"/\\"/g; s/'/\\'/g; s/ /%20/g; } 21 | my $secure=''; 22 | $secure=';secure' if $secure_bool eq 'TRUE' || $secure_bool eq '1'; 23 | $domain="*$domain" if $domain =~ /^\./; 24 | $path='' if $path eq '/'; 25 | $path=";path=$path" if $path ne ''; 26 | $value="=$value" if $name ne ''; 27 | $cookie{"$domain$path$secure"}.=" $name$value"; 28 | } 29 | if($file=~/\.sqlite$/) { 30 | my $file1="$file.$$.tmp"; 31 | $SIG{__DIE__}=sub { unlink $file1 }; 32 | system('cp',$file,$file1); 33 | my $dbh=DBI->connect("dbi:SQLite:dbname=$file1",'',''); 34 | unlink $file1; 35 | my $q=$dbh->prepare("select host,path,isSecure,name,value from moz_cookies"); 36 | $q->execute; 37 | $q->bind_columns(\my($domain,$path,$secure_bool,$name,$value)); 38 | while($q->fetch) { 39 | add_cookie($domain,$path,$secure_bool,$name,$value); 40 | } 41 | } else { 42 | open COOKIES,'<',$file or die "open($file): $!"; 43 | while() 44 | { 45 | chomp; 46 | next if /^#/ or /^$/; 47 | my ($domain,undef,$path,$secure_bool,$expires,$name,$value)=split /\t/; 48 | add_cookie($domain,$path,$secure_bool,$name,$value); 49 | } 50 | } 51 | foreach(sort keys %cookie) 52 | { 53 | $cookie{$_}=~s/^ //; 54 | my $c=($_=~/;/?qq{"$_"}:$_); 55 | print qq{set http:cookie/$c "$cookie{$_}"\n}; 56 | } 57 | -------------------------------------------------------------------------------- /src/SleepJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef SLEEPJOB_H 21 | #define SLEEPJOB_H 22 | 23 | #include "Job.h" 24 | #include "ResMgr.h" 25 | #include "LocalDir.h" 26 | #include "CmdExec.h" 27 | 28 | class SleepJob : public SessionJob, public Timer 29 | { 30 | xstring cmd; 31 | int exit_code; 32 | bool done; 33 | Ref saved_cwd; 34 | JobRef exec; 35 | bool repeat; 36 | bool weak; // terminate on `exit bg'. 37 | int repeat_count; 38 | int max_repeat_count; 39 | int continue_code; 40 | int break_code; 41 | 42 | public: 43 | int Do(); 44 | int Done() { return done; } 45 | int ExitCode() { return exit_code; } 46 | 47 | SleepJob(const TimeInterval &when,FileAccess *s=0,LocalDirectory *cwd=0,char *what=0); 48 | ~SleepJob(); 49 | 50 | const char *Status(); 51 | xstring& FormatStatus(xstring&,int v,const char *); 52 | void ShowRunStatus(const SMTaskRef& s); 53 | 54 | void Repeat(int m) { repeat=true; max_repeat_count=m; Stop(); } 55 | void SetWeak(bool w) { weak=w; } 56 | void ContinueCode(int c) { continue_code=c; } 57 | void BreakCode(int c) { break_code=c; } 58 | 59 | void lftpMovesToBackground(); 60 | }; 61 | 62 | #endif//SLEEPJOB_H 63 | -------------------------------------------------------------------------------- /src/HttpDir.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef HTTPDIR_H 21 | #define HTTPDIR_H 22 | 23 | #include "Http.h" 24 | #if USE_EXPAT 25 | # include 26 | #endif 27 | 28 | class HttpListInfo : public GenericParseListInfo 29 | { 30 | FileSet *Parse(const char *buf,int len); 31 | public: 32 | HttpListInfo(Http *session,const char *path) 33 | : GenericParseListInfo(session,path) 34 | { 35 | get_time_for_dirs=false; 36 | } 37 | static FileSet *ParseProps(const char *buf,int len,const char *base_dir); 38 | }; 39 | 40 | class ParsedURL; 41 | 42 | class HttpDirList : public DirList 43 | { 44 | SMTaskRef ubuf; 45 | const char *curr; 46 | Ref curr_url; 47 | FileSet all_links; 48 | int mode; 49 | bool parse_as_html; 50 | xstring_c base_href; 51 | 52 | #if USE_EXPAT 53 | XML_Parser xml_p; 54 | struct xml_context *xml_ctx; 55 | #endif 56 | 57 | LsOptions ls_options; 58 | 59 | void ParsePropsFormat(const char *b,int len,bool eof); 60 | 61 | public: 62 | HttpDirList(FileAccess *s,ArgV *a); 63 | ~HttpDirList(); 64 | const char *Status(); 65 | int Do(); 66 | 67 | void SuspendInternal(); 68 | void ResumeInternal(); 69 | }; 70 | 71 | #endif//HTTPDIR_H 72 | -------------------------------------------------------------------------------- /src/alias.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef ALIAS_H 21 | #define ALIAS_H 22 | 23 | #include "xstring.h" 24 | 25 | class Alias 26 | { 27 | Alias *next; 28 | xstring_c alias; 29 | xstring_c value; 30 | 31 | static Alias *base; 32 | 33 | Alias(const char *alias,const char *value,Alias *next) 34 | : next(next), alias(alias), value(value) {} 35 | 36 | public: 37 | static const char *Find(const char *alias); 38 | 39 | static void Add(const char *alias,const char *value); 40 | static void Del(const char *alias); 41 | 42 | static char *Format(); 43 | 44 | friend char *command_generator(const char *text,int state); 45 | }; 46 | 47 | class TouchedAlias 48 | { 49 | xstring_c alias; 50 | TouchedAlias *next; 51 | public: 52 | TouchedAlias(const char *a,TouchedAlias *n) 53 | : alias(a), next(n) {} 54 | static void FreeChain(TouchedAlias *chain) 55 | { 56 | while(chain) 57 | delete replace_value(chain,chain->next); 58 | } 59 | static bool IsTouched(const char *a,TouchedAlias *chain) 60 | { 61 | while(chain) 62 | { 63 | if(chain->alias.eq(a)) 64 | return true; 65 | chain=chain->next; 66 | } 67 | return false; 68 | } 69 | }; 70 | 71 | #endif//ALIAS_H 72 | -------------------------------------------------------------------------------- /src/LocalAccess.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LOCALACCESS_H 21 | #define LOCALACCESS_H 22 | 23 | #include "FileAccess.h" 24 | #include "Filter.h" 25 | 26 | class LocalAccess : public FileAccess 27 | { 28 | Ref stream; 29 | bool done; 30 | void errno_handle(); 31 | void fill_array_info(); 32 | 33 | public: 34 | void Init(); 35 | LocalAccess(); 36 | LocalAccess(const LocalAccess *); 37 | 38 | void Connect(const char *host,const char *port) {} 39 | void AnonymousLogin() {} 40 | void Login(const char *u,const char *p) {} 41 | void ResetLocationData() {} 42 | 43 | const char *GetProto() const { return "file"; } 44 | FileAccess *Clone() const { return new LocalAccess(this); } 45 | static FileAccess *New(); 46 | bool SameLocationAs(const FileAccess *fa) const; 47 | 48 | int Read(Buffer *buf,int size); 49 | int Write(const void *buf,int size); 50 | int StoreStatus(); 51 | int Do(); 52 | int Done(); 53 | void Close(); 54 | 55 | const char *CurrentStatus(); 56 | 57 | static void ClassInit(); 58 | 59 | ListInfo *MakeListInfo(const char *path); 60 | Glob *MakeGlob(const char *pattern); 61 | DirList *MakeDirList(ArgV *a); 62 | }; 63 | 64 | #endif//LOCALACCESS_H 65 | -------------------------------------------------------------------------------- /src/ProtoLog.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "log.h" 22 | #include "ProtoLog.h" 23 | 24 | bool ProtoLog::WillOutput(int level) 25 | { 26 | return Log::global && Log::global->WillOutput(level); 27 | } 28 | 29 | void ProtoLog::Log2(int level,xstring& str) 30 | { 31 | if(!WillOutput(level)) 32 | return; 33 | str.chomp('\n'); 34 | str.chomp('\r'); 35 | str.append('\n'); 36 | Log::global->Write(level,str); 37 | } 38 | void ProtoLog::Log3(int level,const char *prefix,const char *str0) 39 | { 40 | if(!WillOutput(level)) 41 | return; 42 | Log2(level,xstring::get_tmp(prefix).append(str0)); 43 | } 44 | void ProtoLog::LogError(int level,const char *fmt,...) 45 | { 46 | if(!WillOutput(level)) 47 | return; 48 | va_list v; 49 | va_start(v,fmt); 50 | Log2(level,xstring::get_tmp("**** ").vappendf(fmt,v)); 51 | va_end(v); 52 | } 53 | void ProtoLog::LogNote(int level,const char *fmt,...) 54 | { 55 | if(!WillOutput(level)) 56 | return; 57 | va_list v; 58 | va_start(v,fmt); 59 | Log2(level,xstring::get_tmp("---- ").vappendf(fmt,v)); 60 | va_end(v); 61 | } 62 | void ProtoLog::LogRecv(int level,const char *line) 63 | { 64 | Log3(level,"<--- ",line); 65 | } 66 | void ProtoLog::LogSend(int level,const char *line) 67 | { 68 | Log3(level,"---> ",line); 69 | } 70 | -------------------------------------------------------------------------------- /src/RateLimit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef RATELIMIT_H 21 | #define RATELIMIT_H 22 | 23 | #include "TimeDate.h" 24 | #include "buffer.h" 25 | 26 | class RateLimit 27 | { 28 | public: 29 | class BytesPool 30 | { 31 | friend class RateLimit; 32 | 33 | int pool; 34 | int rate; 35 | int pool_max; 36 | Time t; 37 | 38 | void AdjustTime(); 39 | void Reset(); 40 | void Used(int); 41 | }; 42 | 43 | private: 44 | static int total_xfer_number; 45 | static bool total_reconfig_needed; 46 | static void ReconfigTotal(); 47 | static BytesPool total[2]; 48 | BytesPool one[2]; 49 | 50 | public: 51 | RateLimit(const char *closure); 52 | ~RateLimit(); 53 | 54 | enum dir_t { GET=0, PUT=1 }; 55 | 56 | int BytesAllowed(dir_t how); 57 | int BytesAllowedToGet() { return BytesAllowed(GET); } 58 | int BytesAllowedToPut() { return BytesAllowed(PUT); } 59 | void BytesUsed(int,dir_t); 60 | void BytesGot(int b) { BytesUsed(b,GET); } 61 | void BytesPut(int b) { BytesUsed(b,PUT); } 62 | bool Relaxed(dir_t dir); 63 | 64 | void Reconfig(const char *name,const char *c); 65 | 66 | int LimitBufferSize(int size,dir_t d) const; 67 | void SetBufferSize(IOBuffer *buf,int size) const; 68 | void SetBufferSize(SMTaskRef& buf,int size) const { SetBufferSize(buf.get_non_const(),size); } 69 | }; 70 | 71 | #endif // RATELIMIT_H 72 | -------------------------------------------------------------------------------- /src/GetJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2015 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef GETJOB_H 21 | #define GETJOB_H 22 | 23 | #include "CopyJob.h" 24 | 25 | class GetJob : public CopyJobEnv, ResClient 26 | { 27 | FileCopyPeer *SrcLocal(const char *src); 28 | FileCopyPeer *DstLocal(const char *dst); 29 | FileCopyPeer *CreateCopyPeer(const ParsedURL &url,const char *path,FA::open_mode mode); 30 | FileCopyPeer *CreateCopyPeer(const char *path,FA::open_mode mode); 31 | bool IsRemoteNonURL(const ParsedURL &url,FA::open_mode mode); 32 | bool IsLocalNonURL(const ParsedURL &url,FA::open_mode mode); 33 | static bool IsLocal(const ParsedURL &url); 34 | 35 | protected: 36 | FileCopyPeer *CreateCopyPeer(FileAccess *session,const char *path,FA::open_mode mode); 37 | FileCopyPeer *CreateCopyPeer(const FileAccessRef& session,const char *path,FA::open_mode mode); 38 | void NextFile(); 39 | 40 | bool delete_files; 41 | bool remove_target_first; 42 | bool truncate_target_first; 43 | xstring backup_file; 44 | mode_t file_mode; 45 | Ref local; 46 | bool reverse; 47 | 48 | void RemoveBackupFile(); 49 | 50 | public: 51 | GetJob(FileAccess *s,ArgV *a,bool c=false); 52 | 53 | int Do(); 54 | 55 | void DeleteFiles() { delete_files=true; } 56 | void RemoveSourceLater() { delete_files=true; } 57 | void Reverse() { reverse=true; } // put 58 | void RemoveTargetFirst() { remove_target_first=true; } 59 | }; 60 | 61 | #endif /* GETJOB_H */ 62 | -------------------------------------------------------------------------------- /src/PollVec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef POLLVEC_H 21 | #define POLLVEC_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | CDECL_BEGIN 28 | #include 29 | CDECL_END 30 | 31 | class PollVec 32 | { 33 | fd_set in; 34 | fd_set out; 35 | fd_set in_polled; 36 | fd_set out_polled; 37 | fd_set in_ready; 38 | fd_set out_ready; 39 | int nfds; 40 | struct timeval tv_timeout; 41 | 42 | public: 43 | PollVec() { 44 | Empty(); 45 | FD_ZERO(&in_polled); 46 | FD_ZERO(&out_polled); 47 | FD_ZERO(&in_ready); 48 | FD_ZERO(&out_ready); 49 | } 50 | 51 | void Empty() 52 | { 53 | FD_ZERO(&in); 54 | FD_ZERO(&out); 55 | nfds=0; 56 | tv_timeout.tv_sec=-1; 57 | tv_timeout.tv_usec=0; 58 | } 59 | void Block(); 60 | 61 | enum { 62 | IN=1, 63 | OUT=4, 64 | }; 65 | 66 | void SetTimeout(const timeval &t) { tv_timeout=t; } 67 | void SetTimeoutU(unsigned t) { 68 | tv_timeout.tv_sec=t/1000000; 69 | tv_timeout.tv_usec=t%1000000; 70 | } 71 | void AddTimeoutU(unsigned t); 72 | void AddFD(int fd,int events); 73 | bool FDReady(int fd,int events); 74 | void FDSetNotReady(int fd,int events); 75 | void NoWait() { tv_timeout.tv_sec=tv_timeout.tv_usec=0; } 76 | bool WillNotBlock() { return tv_timeout.tv_sec==0 && tv_timeout.tv_usec==0; } 77 | }; 78 | 79 | #endif /* POLLVEC_H */ 80 | -------------------------------------------------------------------------------- /src/ColumnOutput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef DISPCOLUMNS_H 21 | #define DISPCOLUMNS_H 22 | 23 | #include "OutputJob.h" 24 | #include "xarray.h" 25 | 26 | class datum 27 | { 28 | int ws, curwidth; 29 | 30 | public: 31 | /* Each entry has a series of strings; each string has a color. */ 32 | StringSet names; 33 | StringSet colors; 34 | datum() : ws(0), curwidth(0) {} 35 | 36 | void append(const char *name, const char *color); 37 | 38 | // get the total display width 39 | int width() const { return curwidth; } 40 | 41 | // print with or without color 42 | void print(const JobRef& o, bool color, int skip, 43 | const char *color_pref, const char *color_suf, const char *color_reset) const; 44 | 45 | /* count leading whitespace in the first name only. */ 46 | int whitespace() const { return ws; } 47 | }; 48 | 49 | class ColumnOutput { 50 | void get_print_info(unsigned width, xarray &col_arr, xarray &ws_arr, int &cols) const; 51 | 52 | public: 53 | enum mode_t { VERT }; 54 | 55 | void append(); 56 | void add(const char *name, const char *color); 57 | void addf(const char *fmt, const char *color, ...); 58 | 59 | void SetWidth(unsigned width); 60 | void SetColor(bool color); 61 | 62 | void print(const JobRef& o, unsigned width, bool color) const; 63 | void set_mode(mode_t m) { mode = m; } 64 | 65 | private: 66 | RefArray lst; 67 | 68 | mode_t mode; 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/echoJob.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "echoJob.h" 23 | #include "misc.h" 24 | 25 | #define super Job 26 | 27 | echoJob::echoJob(const char *buf, int len, OutputJob *_output) 28 | : output(_output) 29 | { 30 | AddWaiting(_output); 31 | output->Put(buf, len); 32 | output->PutEOF(); 33 | } 34 | 35 | echoJob::echoJob(const char *buf, OutputJob *_output) 36 | : output(_output) 37 | { 38 | AddWaiting(_output); 39 | output->Put(buf); 40 | output->PutEOF(); 41 | } 42 | 43 | echoJob::~echoJob() 44 | { 45 | } 46 | 47 | int echoJob::Done() 48 | { 49 | return output->Done(); 50 | } 51 | 52 | int echoJob::ExitCode() 53 | { 54 | /* if the output fails, we failed */ 55 | return output->Error()? 1:0; 56 | } 57 | 58 | /* We have no interesting status for "jobs", so we have no PrintStatus 59 | * override. (The output job will print the output status, if relevant.) */ 60 | 61 | void echoJob::ShowRunStatus(const SMTaskRef& s) 62 | { 63 | if(Done()) 64 | return; 65 | 66 | /* Never call output->ShowStatusLine unless we're really going 67 | * to display something. */ 68 | const char *stat = output->Status(s); 69 | if(*stat && output->ShowStatusLine(s)) 70 | s->Show("echo: %s", stat); 71 | } 72 | 73 | void echoJob::Fg() 74 | { 75 | super::Fg(); 76 | if(output) 77 | output->Fg(); 78 | } 79 | void echoJob::Bg() 80 | { 81 | if(output) 82 | output->Bg(); 83 | super::Bg(); 84 | } 85 | -------------------------------------------------------------------------------- /src/lftp_rl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LFTP_RL_H 21 | #define LFTP_RL_H 22 | 23 | CDECL_BEGIN 24 | 25 | void lftp_readline_init (void); 26 | int lftp_history_expand (const char *, char **); 27 | char *lftp_readline (const char *prompt); 28 | void lftp_add_history_nodups(const char *cmd); 29 | void lftp_history_clear(); 30 | void lftp_history_list(int cnt); 31 | int lftp_history_write(const char *fn); 32 | int lftp_history_read(const char *fn); 33 | void lftp_rl_clear(void); 34 | void lftp_rl_redisplay_maybe(void); 35 | void lftp_rl_set_ignore_some_completions_function(int (*func)(char**)); 36 | char **lftp_rl_completion_matches(const char *text,char *(*compentry)(const char *,int)); 37 | void lftp_rl_add_defun(const char *name,int (*func)(int,int),int key); 38 | void lftp_rl_bind(const char *key,const char *func); 39 | void lftp_rl_set_prompt(const char *p); 40 | void lftp_rl_write_history(); 41 | void lftp_rl_read_history(); 42 | void lftp_rl_history_stifle(int s); 43 | 44 | void lftp_rl_init( 45 | const char *readline_name, 46 | char **(*attempted_completion_function)(const char *,int,int), 47 | int (*getc_function)(FILE*), 48 | const char *completer_quote_characters, 49 | const char *completer_word_break_characters, 50 | const char *filename_quote_characters, 51 | char *(*filename_quoting_function)(char *,int,char *), 52 | char *(*filename_dequoting_function)(const char *,int), 53 | int (*char_is_quoted_p)(const char *,int)); 54 | 55 | CDECL_END 56 | 57 | #endif /* LFTP_RL_H */ 58 | -------------------------------------------------------------------------------- /doc/ftpget.1: -------------------------------------------------------------------------------- 1 | .\" ftpget.1 2 | .\" 3 | .\" This file is part of lftp. 4 | .\" 5 | .\" This program is free software; you can redistribute it and/or modify 6 | .\" it under the terms of the GNU General Public License as published by 7 | .\" the Free Software Foundation; either version 2 of the License , or 8 | .\" (at your option) any later version. 9 | .\" 10 | .\" This program is distributed in the hope that it will be useful, 11 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | .\" GNU General Public License for more details. 14 | .\" 15 | .\" You should have received a copy of the GNU General Public License 16 | .\" along with this program. If not, see . 17 | .\" 18 | .TH ftpget 1 "02 Jun 1999" 19 | .SH NAME 20 | ftpget \- Get files fast from the commandline 21 | .SH SYNTAX 22 | .B ftpget 23 | .RI [ options ] " host filename 24 | .RB [ "\-o" 25 | .IR local "] [" filename "] ..." 26 | .SH VERSION 27 | This man page documents ftpget version 2.0. Note that ftpget is deprecated 28 | and it is recommended to use scripting capabilities of \fBlftp\fP. 29 | .SH "DESCRIPTION" 30 | \fBftpget\fR is a program that gets the given \fIfilename\fR from the 31 | indicated \fIhost\fR. Multiple filenames can be specified. If a 32 | filename needs to be redirected to another local file then use the 33 | \fB-o\fR option. 34 | .SH OPTIONS 35 | .TP 36 | .I \-p, \-\-port 37 | Set port number 38 | .TP 39 | .I \-u, \-\-user 40 | login as user using pass as password 41 | .TP 42 | .I \-l, \-\-list 43 | Get listing of specified directories 44 | .TP 45 | .I \-c, \-\-continue 46 | Reget specified file(s) 47 | .TP 48 | .I \-q, \-\-quiet 49 | Run quietly (no output). 50 | .TP 51 | .I \-v, \-\-verbose 52 | Run verbosely (lots of output). 53 | .TP 54 | .I \-\-async-mode 55 | Use asynchronous mode (faster) 56 | .TP 57 | .I \-\-sync-mode 58 | Use synchronous mode (compatible with bugs) 59 | .TP 60 | .I \-o file 61 | output to local file 'local' (default \- base name of filename) 62 | 63 | .SH SEE ALSO 64 | .BR lftp (1) 65 | 66 | .SH AUTHOR 67 | .nf 68 | Alexander V. Lukyanov 69 | lav@yars.free.net 70 | .fi 71 | 72 | .SH ACKNOWLEDGMENTS 73 | This manual page was originally written by Christoph Lameter 74 | , for the Debian GNU/Linux system. 75 | -------------------------------------------------------------------------------- /src/FileCopyOutputJob.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "FileCopy.h" 22 | #include "FileCopyOutputJob.h" 23 | 24 | FileCopyPeerOutputJob::FileCopyPeerOutputJob(const JobRef& new_o) 25 | : FileCopyPeer(PUT), o(new_o) 26 | { 27 | DontCopyDate(); 28 | } 29 | 30 | int FileCopyPeerOutputJob::Put_LL(const char *buf,int len) 31 | { 32 | off_t io_at=pos; 33 | if(GetRealPos()!=io_at) // GetRealPos can alter pos. 34 | return 0; 35 | 36 | if(len==0 && eof) 37 | return 0; 38 | 39 | if(o->Full()) 40 | return 0; 41 | 42 | o->Put(buf,len); 43 | 44 | seek_pos+=len; // mainly to indicate that there was some output. 45 | return len; 46 | } 47 | 48 | int FileCopyPeerOutputJob::Do() 49 | { 50 | int m=STALL; 51 | 52 | if(broken || done) 53 | return m; 54 | if(o->Error()) 55 | { 56 | broken=true; 57 | return MOVED; 58 | } 59 | if(eof && Size()==0) 60 | { 61 | done=true; 62 | return MOVED; 63 | } 64 | 65 | if(!write_allowed) 66 | return m; 67 | 68 | while(Size()>0) 69 | { 70 | int res=Put_LL(buffer+buffer_ptr,Size()); 71 | if(res>0) 72 | { 73 | buffer_ptr+=res; 74 | m=MOVED; 75 | } 76 | if(res<0) 77 | return MOVED; 78 | if(res==0) 79 | break; 80 | } 81 | return m; 82 | } 83 | 84 | void FileCopyPeerOutputJob::Fg() 85 | { 86 | o->Fg(); 87 | FileCopyPeer::Fg(); 88 | } 89 | void FileCopyPeerOutputJob::Bg() 90 | { 91 | o->Bg(); 92 | FileCopyPeer::Bg(); 93 | } 94 | -------------------------------------------------------------------------------- /src/StatusLine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef STATUSLINE_H 21 | #define STATUSLINE_H 22 | 23 | #include "SMTask.h" 24 | #include "Timer.h" 25 | #include "StringSet.h" 26 | 27 | class StatusLine : public SMTask 28 | { 29 | int fd; 30 | StringSet shown; 31 | bool not_term; 32 | Timer update_timer; 33 | StringSet to_be_shown; 34 | char def_title[0x800]; 35 | bool update_delayed; 36 | void update(const char *const *,int); 37 | void update(const char *s) { update(&s,1); } 38 | int LastWidth; 39 | int LastHeight; 40 | bool next_update_title_only; 41 | static const char *to_status_line, *from_status_line, *prev_line; 42 | 43 | protected: 44 | void WriteTitle(const char *s, int fd) const; 45 | 46 | public: 47 | int GetWidth(); 48 | int GetHeight(); 49 | int GetWidthDelayed() const { return LastWidth; } 50 | int GetHeightDelayed() const { return LastHeight; } 51 | void NextUpdateTitleOnly() { next_update_title_only=true; } 52 | void DefaultTitle(const char *s); 53 | void ShowN(const char *const* newstr,int n); 54 | void Show(const char *f,...) PRINTF_LIKE(2,3); 55 | void Show(const StringSet &s) { ShowN(s.Set(),s.Count()); } 56 | void Show(const StringSet *s) { Show(*s); } 57 | void WriteLine(const char *f,...) PRINTF_LIKE(2,3); 58 | void Clear(bool title_also=true); 59 | bool CanShowNow() { return update_timer.Stopped(); } 60 | 61 | int getfd() const { return fd; } 62 | 63 | StatusLine(int new_fd); 64 | ~StatusLine(); 65 | 66 | int Do(); 67 | }; 68 | 69 | #endif // STATUSLINE_H 70 | -------------------------------------------------------------------------------- /trio/trionan.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * $Id: trionan.h,v 1.7 2002/05/04 14:26:44 breese Exp $ 4 | * 5 | * Copyright (C) 2001 Bjorn Reese 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 12 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 13 | * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND 14 | * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. 15 | * 16 | ************************************************************************/ 17 | 18 | #ifndef TRIO_NAN_H 19 | #define TRIO_NAN_H 20 | 21 | #include "triodef.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | enum { 28 | TRIO_FP_INFINITE, 29 | TRIO_FP_NAN, 30 | TRIO_FP_NORMAL, 31 | TRIO_FP_SUBNORMAL, 32 | TRIO_FP_ZERO 33 | }; 34 | 35 | /* 36 | * Return NaN (Not-a-Number). 37 | */ 38 | TRIO_PUBLIC double trio_nan TRIO_PROTO((void)); 39 | 40 | /* 41 | * Return positive infinity. 42 | */ 43 | TRIO_PUBLIC double trio_pinf TRIO_PROTO((void)); 44 | 45 | /* 46 | * Return negative infinity. 47 | */ 48 | TRIO_PUBLIC double trio_ninf TRIO_PROTO((void)); 49 | 50 | /* 51 | * Return negative zero. 52 | */ 53 | TRIO_PUBLIC double trio_nzero TRIO_PROTO((TRIO_NOARGS)); 54 | 55 | /* 56 | * If number is a NaN return non-zero, otherwise return zero. 57 | */ 58 | TRIO_PUBLIC int trio_isnan TRIO_PROTO((double number)); 59 | 60 | /* 61 | * If number is positive infinity return 1, if number is negative 62 | * infinity return -1, otherwise return 0. 63 | */ 64 | TRIO_PUBLIC int trio_isinf TRIO_PROTO((double number)); 65 | 66 | /* 67 | * If number is finite return non-zero, otherwise return zero. 68 | */ 69 | TRIO_PUBLIC int trio_isfinite TRIO_PROTO((double number)); 70 | 71 | TRIO_PUBLIC int trio_signbit TRIO_PROTO((double number)); 72 | 73 | TRIO_PUBLIC int trio_fpclassify TRIO_PROTO((double number)); 74 | 75 | TRIO_PUBLIC int trio_fpclassify_and_signbit TRIO_PROTO((double number, int *is_negative)); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* TRIO_NAN_H */ 82 | -------------------------------------------------------------------------------- /src/rmJob.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include "rmJob.h" 24 | #include "plural.h" 25 | #include "url.h" 26 | #include "misc.h" 27 | 28 | rmJob::rmJob(FileAccess *s,ArgV *a) : TreatFileJob(s,a) 29 | { 30 | mode=FA::REMOVE; 31 | recurse=false; 32 | depth_first=true; 33 | } 34 | 35 | void rmJob::Recurse() 36 | { 37 | set_maxdepth(-1); 38 | Need(FileInfo::TYPE); 39 | recurse=true; 40 | } 41 | 42 | void rmJob::SayFinal() 43 | { 44 | if(failed==file_count) 45 | return; 46 | if(file_count==1) 47 | printf(_("%s ok, `%s' removed\n"),op,first->name.get()); 48 | else if(failed) 49 | { 50 | if(mode==FA::REMOVE_DIR) 51 | printf(plural("%s failed for %d of %d director$y|ies$\n",file_count), 52 | op,failed,file_count); 53 | else 54 | printf(plural("%s failed for %d of %d file$|s$\n",file_count), 55 | op,failed,file_count); 56 | } 57 | else 58 | { 59 | if(mode==FA::REMOVE_DIR) 60 | printf(plural("%s ok, %d director$y|ies$ removed\n",file_count), 61 | op,file_count); 62 | else 63 | printf(plural("%s ok, %d file$|s$ removed\n",file_count), 64 | op,file_count); 65 | } 66 | } 67 | 68 | void rmJob::TreatCurrent(const char *d, const FileInfo *fi) 69 | { 70 | /* If we're recursing and this is a directory, rmdir it. (If we're 71 | * not recursing, just send an rm and let it fail.) */ 72 | if(recurse && (fi->defined&fi->TYPE) && (fi->filetype==fi->DIRECTORY)) 73 | session->Open(fi->name,FA::REMOVE_DIR); 74 | else 75 | session->Open(fi->name,mode); 76 | } 77 | -------------------------------------------------------------------------------- /src/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef LOG_H 21 | #define LOG_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "SMTask.h" 27 | 28 | class Log : public SMTask 29 | { 30 | int output; 31 | bool need_close_output; 32 | bool tty; 33 | bool show_pid; 34 | bool show_time; 35 | bool show_context; 36 | bool at_line_start; 37 | typedef void (*tty_cb_t)(); 38 | tty_cb_t tty_cb; 39 | 40 | void CloseOutput() 41 | { 42 | if(need_close_output) 43 | close(output); 44 | output=-1; 45 | need_close_output=false; 46 | } 47 | 48 | bool enabled; 49 | int level; 50 | 51 | public: 52 | static SMTaskRef global; 53 | 54 | bool WillOutput(int l); 55 | void DoWrite(const char *str); 56 | void Write(int l,const char *str); 57 | void Format(int l,const char *fmt,...) PRINTF_LIKE(3,4); 58 | void vFormat(int l,const char *fmt,va_list v); 59 | 60 | void SetLevel(int l) { level=l; } 61 | void Enable() { enabled=true; } 62 | void Disable() { enabled=false; } 63 | 64 | void SetOutput(int o,bool need_close); 65 | 66 | void SetCB(tty_cb_t cb) { tty_cb=cb; } 67 | 68 | bool IsTTY() { return tty; } 69 | 70 | void Init(); 71 | Log() { Init(); } 72 | ~Log(); 73 | 74 | int Do(); 75 | 76 | void ShowPID(bool yes=true) { show_pid=yes; } 77 | void ShowTime(bool yes=true) { show_time=yes; } 78 | void ShowContext(bool yes=true) { show_context=yes; } 79 | void ShowNothing() { show_pid=show_time=show_context=false; } 80 | 81 | static void Cleanup(); 82 | }; 83 | 84 | #endif // LOG_H 85 | -------------------------------------------------------------------------------- /src/Ref.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef REF_H 21 | #define REF_H 22 | 23 | template class Ref 24 | { 25 | Ref(const Ref&); // disable cloning 26 | void operator=(const Ref&); // and assignment 27 | 28 | protected: 29 | T *ptr; 30 | 31 | public: 32 | Ref() { ptr=0; } 33 | Ref(T *p) { ptr=p; } 34 | ~Ref() { delete ptr; } 35 | void operator=(T *p) { delete ptr; ptr=p; } 36 | operator const T*() const { return ptr; } 37 | T *operator->() const { return ptr; } 38 | T *borrow() { return replace_value(ptr,(T*)0); } 39 | const T *get() const { return ptr; } 40 | T *get_non_const() const { return ptr; } 41 | 42 | template const Ref& Cast() const 43 | { void(static_cast(ptr)); return *(const Ref*)this; } 44 | 45 | static const Ref null; 46 | 47 | void _set(T *p) { ptr=p; } 48 | void _clear() { ptr=0; } 49 | void unset() { *this=0; } 50 | }; 51 | 52 | template const Ref Ref::null; 53 | 54 | template class RefToArray : public Ref 55 | { 56 | RefToArray(const RefToArray&); // disable cloning 57 | void operator=(const RefToArray&); // and assignment 58 | 59 | public: 60 | RefToArray() {} 61 | RefToArray(T *p) : Ref(p) {} 62 | ~RefToArray() { delete[] Ref::ptr; Ref::ptr=0; } 63 | void operator=(T *p) { delete[] Ref::ptr; Ref::ptr=p; } 64 | T& operator[](unsigned i) const { return Ref::ptr[i]; } 65 | 66 | static const RefToArray null; 67 | }; 68 | 69 | template const RefToArray RefToArray::null; 70 | 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/fg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef FG_H 21 | #define FG_H 22 | 23 | #include 24 | 25 | 26 | #if 0 27 | /* Assume Posix termio if we have the header and function */ 28 | #if HAVE_TERMIOS_H && HAVE_TCGETATTR 29 | #ifndef TERMIOS 30 | #define TERMIOS 1 31 | #endif 32 | #include 33 | #define TTY struct termios 34 | 35 | #else /* !HAVE_TERMIOS_H */ 36 | 37 | #if HAVE_TERMIO_H 38 | #ifndef TERMIOS 39 | #define TERMIOS 1 40 | #endif 41 | #include 42 | #define TTY struct termio 43 | #define TCSANOW TCSETA 44 | #define TCSADRAIN TCSETAW 45 | #define TCSAFLUSH TCSETAF 46 | #define tcsetattr(fd, cmd, arg) ioctl(fd, cmd, arg) 47 | #define tcgetattr(fd, arg) ioctl(fd, TCGETA, arg) 48 | #define cfgetospeed(t) ((t)->c_cflag & CBAUD) 49 | #define TCIFLUSH 0 50 | #define TCOFLUSH 1 51 | #define TCIOFLUSH 2 52 | #define tcflush(fd, arg) ioctl(fd, TCFLSH, arg) 53 | 54 | #else /* !HAVE_TERMIO_H */ 55 | 56 | #undef TERMIOS 57 | #include 58 | #include 59 | #define TTY struct sgttyb 60 | 61 | #endif /* HAVE_TERMIO_H */ 62 | 63 | #endif /* HAVE_TERMIOS_H */ 64 | 65 | #ifdef TERMIOS 66 | #define GET_TTY(fd, buf) tcgetattr(fd, buf) 67 | #define SET_TTY(fd, buf) tcsetattr(fd, TCSADRAIN, buf) 68 | #else 69 | #define GET_TTY(fd, buf) gtty(fd, buf) 70 | #define SET_TTY(fd, buf) stty(fd, buf) 71 | #endif 72 | 73 | #endif // 0 74 | 75 | class FgData 76 | { 77 | pid_t pg; 78 | pid_t old_pgrp; 79 | #if 0 // not done yet 80 | TTY tc; 81 | TTY old_tc; 82 | #endif 83 | public: 84 | FgData(pid_t npg,bool fg); 85 | ~FgData(); 86 | void Fg(),Bg(); 87 | void cont(); 88 | }; 89 | 90 | #endif//FG_H 91 | -------------------------------------------------------------------------------- /src/StringSet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef STRINGSET_H 21 | #define STRINGSET_H 22 | 23 | #include "xarray.h" 24 | 25 | class StringSet 26 | { 27 | xarray_m set; 28 | 29 | const StringSet &operator=(const StringSet &); // disable assignment 30 | 31 | public: 32 | StringSet(); 33 | StringSet(const char *const *s,int n); 34 | StringSet(const StringSet &o); 35 | StringSet(const char *s); 36 | 37 | void Empty() { set.truncate(); } 38 | void Assign(const char *const *s,int n); 39 | void Assign(const char *s) { Assign(&s,1); } 40 | bool IsEqual(const char *const *s,int n) const; 41 | bool IsEqual(const StringSet &o) const { return IsEqual(o.Set(),o.Count()); } 42 | void Append(const char *); 43 | void AppendFormat(const char *,...) PRINTF_LIKE(2,3); 44 | void InsertBefore(int,const char *); 45 | void Replace(int,const char *); 46 | char *Pop(int i=0); 47 | void Remove(int i) { xfree(Pop(i)); } 48 | 49 | const char *const *Set() const { return set.get(); } 50 | char **SetNonConst() { return set.get_non_const(); } 51 | int Count() const { return set.count(); } 52 | const char *String(int i) const { return i>=0 && i::cmp_t cmp) { set.qsort(cmp); } 61 | static int default_cmp(const char **a,const char **b) { return strcmp(*a,*b); } 62 | void qsort() { qsort(default_cmp); } 63 | }; 64 | 65 | #endif // STRINGSET_H 66 | -------------------------------------------------------------------------------- /src/PollVec.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "trio.h" 22 | #include "PollVec.h" 23 | 24 | static inline bool operator<(const timeval& a,const timeval& b) 25 | { 26 | if(a.tv_sec!=b.tv_sec) 27 | return a.tv_sec. 18 | */ 19 | 20 | /* $Id: DummyProto.cc,v 1.12 2009/03/20 12:28:04 lav Exp $ */ 21 | 22 | #include 23 | 24 | #include "DummyProto.h" 25 | #include 26 | 27 | DummyProto::DummyProto() {} 28 | DummyProto::~DummyProto() {} 29 | int DummyProto::Do() { return STALL; } 30 | int DummyProto::Done() { return NO_HOST; } 31 | const char *DummyProto::GetProto() const { return ""; } 32 | FileAccess *DummyProto::Clone() const { return new DummyProto; } 33 | int DummyProto::Read(Buffer *buf,int size) { return NO_HOST; }; 34 | int DummyProto::Write(const void *buf,int size) { return NO_HOST; }; 35 | int DummyProto::StoreStatus() { return NO_HOST; } 36 | 37 | class DummyDirList : public DirList 38 | { 39 | public: 40 | DummyDirList(FA *p1,ArgV *a) : DirList(p1,a) {} 41 | int Do() { SetError(session->StrError(FA::NO_HOST)); return STALL; } 42 | const char *Status() { return ""; } 43 | }; 44 | class DummyListInfo : public ListInfo 45 | { 46 | public: 47 | DummyListInfo(FA *p1) : ListInfo(p1,0) {} 48 | int Do() { SetError(session->StrError(FA::NO_HOST)); return STALL; } 49 | const char *Status() { return ""; } 50 | }; 51 | DirList *DummyProto::MakeDirList(ArgV *a) 52 | { 53 | return new DummyDirList(this,a); 54 | } 55 | ListInfo *DummyProto::MakeListInfo(const char *path) 56 | { 57 | return new DummyListInfo(this); 58 | } 59 | 60 | const char *DummyNoProto::GetProto() const { return proto; } 61 | FileAccess *DummyNoProto::Clone() const { return new DummyNoProto(proto); } 62 | const char *DummyNoProto::StrError(int) 63 | { 64 | static xstring str; 65 | str.vset(proto.get(),_(" - not supported protocol"),NULL); 66 | return str; 67 | } 68 | -------------------------------------------------------------------------------- /src/GetPass.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "GetPass.h" 28 | #include "CharReader.h" 29 | #include "SignalHook.h" 30 | 31 | const char *GetPass(const char *prompt) 32 | { 33 | static xstring_c oldpass; 34 | static int tty_fd=-2; 35 | 36 | if(tty_fd==-2) 37 | { 38 | if(isatty(0)) 39 | tty_fd=0; 40 | else 41 | { 42 | tty_fd=open("/dev/tty",O_RDONLY); 43 | if(tty_fd!=-1) 44 | fcntl(tty_fd,F_SETFD,FD_CLOEXEC); 45 | } 46 | } 47 | if(tty_fd==-1) 48 | return 0; 49 | 50 | write(tty_fd,prompt,strlen(prompt)); 51 | 52 | struct termios tc; 53 | tcgetattr(tty_fd,&tc); 54 | tcflag_t old_lflag=tc.c_lflag; 55 | tc.c_lflag&=~ECHO; 56 | tcsetattr(tty_fd,TCSANOW,&tc); 57 | 58 | oldpass.set_allocated(readline_from_file(tty_fd)); 59 | 60 | tc.c_lflag=old_lflag; 61 | tcsetattr(tty_fd,TCSANOW,&tc); 62 | 63 | write(tty_fd,"\r\n",2); 64 | 65 | return oldpass; 66 | } 67 | 68 | char *readline_from_file(int fd) 69 | { 70 | xstring line(""); 71 | for(;;) 72 | { 73 | SMTaskRef rr(new CharReader(fd)); 74 | CharReader& r=*rr.get_non_const(); 75 | int c; 76 | for(;;) 77 | { 78 | SMTask::Schedule(); 79 | c=r.GetChar(); 80 | if(c!=r.NOCHAR) 81 | break; 82 | SMTask::Block(); 83 | if(SignalHook::GetCount(SIGINT)>0) 84 | return(xstrdup("")); 85 | } 86 | if(c==r.EOFCHAR && line.length()==0) 87 | return(NULL); 88 | if(c==r.EOFCHAR || c=='\n') 89 | return(line.borrow()); 90 | line.append(c); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/LocalDir.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "LocalDir.h" 29 | #include "misc.h" 30 | 31 | #ifndef O_DIRECTORY 32 | # define O_DIRECTORY 0 33 | #endif 34 | 35 | void LocalDirectory::SetFromCWD() 36 | { 37 | Unset(); 38 | fd=open(".",O_RDONLY|O_DIRECTORY); 39 | fcntl(fd,F_SETFD,FD_CLOEXEC); 40 | name.set_allocated(xgetcwd()); 41 | } 42 | 43 | const char *LocalDirectory::Chdir() 44 | { 45 | #ifdef HAVE_FCHDIR 46 | if(fd!=-1) 47 | { 48 | int res=fchdir(fd); 49 | if(res==-1) 50 | return strerror(errno); 51 | return 0; 52 | } 53 | #endif 54 | if(name) 55 | { 56 | int res=chdir(name); 57 | if(res==-1) 58 | return strerror(errno); 59 | return 0; 60 | } 61 | return "Directory location is undefined"; 62 | } 63 | 64 | const char *LocalDirectory::GetName() 65 | { 66 | return name; 67 | } 68 | 69 | void LocalDirectory::Unset() 70 | { 71 | if(fd!=-1) 72 | close(fd); 73 | fd=-1; 74 | name.set(0); 75 | } 76 | 77 | LocalDirectory::LocalDirectory() 78 | { 79 | fd=-1; 80 | } 81 | 82 | LocalDirectory::LocalDirectory(const LocalDirectory *o) 83 | { 84 | fd=-1; 85 | if(o->fd!=-1) { 86 | fd=dup(o->fd); 87 | fcntl(fd,F_SETFD,FD_CLOEXEC); 88 | } 89 | name.set(o->name); 90 | } 91 | 92 | LocalDirectory *LocalDirectory::Clone() const 93 | { 94 | return new LocalDirectory(this); 95 | } 96 | 97 | LocalDirectory::~LocalDirectory() 98 | { 99 | Unset(); 100 | } 101 | -------------------------------------------------------------------------------- /src/lftp_tinfo.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | extern "C" { 23 | #if defined(HAVE_CURSES_H) 24 | # include 25 | # if defined(HAVE_TERM_H) 26 | # include 27 | # elif defined(HAVE_NCURSES_TERM_H) 28 | # include 29 | # endif 30 | #elif defined(HAVE_NCURSES_CURSES_H) 31 | # include 32 | # if defined(HAVE_NCURSES_TERM_H) 33 | # include 34 | # elif defined(HAVE_TERM_H) 35 | # include 36 | # endif 37 | #elif defined(HAVE_TERMCAP_H) 38 | # include 39 | #endif 40 | } 41 | #include 42 | #include "lftp_tinfo.h" 43 | 44 | static bool terminfo_ok = true; 45 | static void init_terminfo() 46 | { 47 | static bool initted = false; 48 | if(initted) return; 49 | initted = true; 50 | 51 | #if defined(HAVE_TIGETSTR) 52 | int errret=0; 53 | if(setupterm(NULL, 1, &errret) == ERR) 54 | terminfo_ok = false; 55 | #elif defined(HAVE_TGETSTR) 56 | static char buf[2048]; 57 | const char *term=getenv("TERM"); 58 | if(!term || tgetent(buf,term) == -1) 59 | terminfo_ok = false; 60 | #endif 61 | } 62 | 63 | const char *get_string_term_cap(const char *terminfo_cap, const char *tcap_cap) 64 | { 65 | init_terminfo(); 66 | if(!terminfo_ok) 67 | return 0; 68 | 69 | #if defined(HAVE_TIGETSTR) 70 | /* Cast to work around missing const def in some ncurses installations: */ 71 | const char *ret = tigetstr(const_cast(terminfo_cap)); 72 | if(ret && ret != (char *)-1) return ret; 73 | #elif defined(HAVE_TGETSTR) 74 | const char *ret = tgetstr(const_cast(tcap_cap), 0); 75 | if(ret && ret != (const char *)-1) 76 | return ret; 77 | #endif 78 | 79 | return NULL; 80 | } 81 | -------------------------------------------------------------------------------- /src/Bencode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef BENCODE_H 21 | #define BENCODE_H 22 | 23 | #include "xmap.h" 24 | #include "buffer.h" 25 | 26 | class BeNode 27 | { 28 | void PackDict(xstring &buf); 29 | public: 30 | enum be_type_t { 31 | BE_STR, 32 | BE_INT, 33 | BE_LIST, 34 | BE_DICT 35 | } type; 36 | 37 | xstring str; 38 | xstring str_lc; 39 | xarray_p list; 40 | xmap_p dict; 41 | long long num; 42 | 43 | static BeNode *Parse(const char *s,int len,int *rest); 44 | 45 | BeNode(const xstring& s); 46 | BeNode(const char *s,int l); 47 | BeNode(const char *s); 48 | BeNode(xarray_p *l); 49 | BeNode(xmap_p *d); 50 | BeNode(long long); 51 | ~BeNode(); 52 | 53 | BeNode *lookup(const char *key) { 54 | return dict.lookup(key); 55 | } 56 | BeNode *lookup(const char *key,be_type_t t) { 57 | BeNode *n=dict.lookup(key); 58 | if(n && n->type!=t) 59 | n=0; 60 | return n; 61 | } 62 | const xstring& lookup_str(const char *key) const { 63 | BeNode *n=dict.lookup(key); 64 | if(!n || n->type!=BE_STR) 65 | return xstring::null; 66 | return n->str; 67 | } 68 | long long lookup_int(const char *key) const { 69 | BeNode *n=dict.lookup(key); 70 | if(!n || n->type!=BE_INT) 71 | return 0; 72 | return n->num; 73 | } 74 | 75 | int ComputeLength(); 76 | const xstring& Pack(); 77 | void Pack(xstring &buf); 78 | void Pack(const SMTaskRef &buf); 79 | 80 | void Format(xstring &buf,int level); 81 | const char *Format(); 82 | void Format1(xstring &buf); 83 | const char *Format1(); 84 | 85 | static const char *TypeName(be_type_t t); 86 | }; 87 | 88 | #endif//BENCODE_H 89 | -------------------------------------------------------------------------------- /po/Makevars: -------------------------------------------------------------------------------- 1 | # Makefile variables for PO directory in any package using GNU gettext. 2 | 3 | # Usually the message domain is the same as the package name. 4 | DOMAIN = $(PACKAGE) 5 | 6 | # These two variables depend on the location of this directory. 7 | subdir = po 8 | top_builddir = .. 9 | 10 | # These options get passed to xgettext. 11 | XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ \ 12 | \ 13 | --flag=_:1:pass-c-format\ 14 | --flag=N_:1:pass-c-format\ 15 | --flag=error:3:c-format --flag=error_at_line:5:c-format\ 16 | --c++\ 17 | --keyword=plural --flag=plural:1:pass-c-format\ 18 | --from-code=UTF-8\ 19 | --flag=asprintf:2:c-format --flag=vasprintf:2:c-format\ 20 | --flag=asnprintf:3:c-format --flag=vasnprintf:3:c-format\ 21 | --flag=wrapf:1:c-format\ 22 | --flag=format:1:c-format --flag=vformat:1:c-format\ 23 | --flag=appendf:1:c-format --flag=setf:1:c-format\ 24 | --flag=LogNote:2:c-format --flag=LogError:2:c-format\ 25 | $${end_of_xgettext_options+} 26 | 27 | # This is the copyright holder that gets inserted into the header of the 28 | # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding 29 | # package. (Note that the msgstr strings, extracted from the package's 30 | # sources, belong to the copyright holder of the package.) Translators are 31 | # expected to transfer the copyright for their translations to this person 32 | # or entity, or to disclaim their copyright. The empty string stands for 33 | # the public domain; in this case the translators are expected to disclaim 34 | # their copyright. 35 | COPYRIGHT_HOLDER = Alexander V. Lukyanov 36 | 37 | # This is the email address or URL to which the translators shall report 38 | # bugs in the untranslated strings: 39 | # - Strings which are not entire sentences, see the maintainer guidelines 40 | # in the GNU gettext documentation, section 'Preparing Strings'. 41 | # - Strings which use unclear terms or require additional context to be 42 | # understood. 43 | # - Strings which make invalid assumptions about notation of date, time or 44 | # money. 45 | # - Pluralisation problems. 46 | # - Incorrect English spelling. 47 | # - Incorrect formatting. 48 | # It can be your email address, or a mailing list address where translators 49 | # can write to without being subscribed, or the URL of a web page through 50 | # which the translators can contact you. 51 | MSGID_BUGS_ADDRESS = lftp-bugs@lftp.yar.ru 52 | 53 | # This is the list of locale categories, beyond LC_MESSAGES, for which the 54 | # message catalogs shall be used. It is usually empty. 55 | EXTRA_LOCALE_CATEGORIES = 56 | -------------------------------------------------------------------------------- /src/FindJobDu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef FINDJOBDU_H 20 | #define FINDJOBDU_H 21 | 22 | #include "FindJob.h" 23 | 24 | class FinderJob_Du : public FinderJob 25 | { 26 | SMTaskRef buf; 27 | 28 | /* We keep traversing deeper than this, but we never print a total 29 | * past this. */ 30 | int max_print_depth; 31 | bool print_totals; 32 | int output_block_size; 33 | int human_opts; 34 | bool all_files; 35 | bool separate_dirs; 36 | bool file_count; 37 | 38 | bool success; 39 | 40 | long long tot_size; 41 | 42 | void Init(const char *d); 43 | 44 | struct stack_entry { 45 | xstring_c dir; 46 | long long size; 47 | stack_entry(const char *dir) : dir(dir), size(0) {} 48 | }; 49 | RefArray size_stack; 50 | 51 | Ref args; 52 | 53 | void print_size (long long n_blocks, const char *string); 54 | off_t BlockCeil(off_t size) const; 55 | 56 | // prepends last directory name 57 | const char *MakeFileName(const char *n); 58 | 59 | void Push (const char *d); 60 | void Pop(); 61 | 62 | public: 63 | FinderJob_Du(FileAccess *s,ArgV *a,FDStream *o); 64 | ~FinderJob_Du(); 65 | int Done(); 66 | 67 | void PrintTotals() { print_totals=true; } 68 | void SetBlockSize(int n,int ho) { output_block_size = n; human_opts = ho; } 69 | void PrintDepth(int n) { max_print_depth = n; } 70 | void AllFiles() { all_files=true; } 71 | void SeparateDirs() { separate_dirs=true; } 72 | void FileCount() { file_count=true; } 73 | 74 | protected: 75 | /* virtuals */ 76 | prf_res ProcessFile(const char *d,const FileInfo *fi); 77 | void ProcessList(FileSet *f); 78 | void Finish(); 79 | void Enter(const char *d); 80 | void Exit(); 81 | }; 82 | 83 | #endif // FINDJOBDU_H 84 | -------------------------------------------------------------------------------- /src/GetFileInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef GETFILEINFO_H 21 | #define GETFILEINFO_H 22 | 23 | #include "trio.h" 24 | 25 | #include "SMTask.h" 26 | #include "FileAccess.h" 27 | 28 | class GetFileInfo : public ListInfo 29 | { 30 | const FileAccessRef& session; 31 | 32 | SMTaskRef li; 33 | 34 | /* file or dir we're listing: */ 35 | xstring_c dir; 36 | 37 | /* directory we've actually listed: */ 38 | xstring_c path_to_prefix; 39 | 40 | /* directory we started in: */ 41 | FileAccess::Path origdir; 42 | 43 | /* In showdir mode, we make sure the path actually exists; this is 44 | * the filename to look for. */ 45 | xstring verify_fn; 46 | 47 | bool showdir; 48 | 49 | enum state_t { INITIAL, CHANGE_DIR, CHANGING_DIR, GETTING_LIST, GETTING_INFO_ARRAY, DONE } state; 50 | /* whether we've tried to cd to the whole dir (treating it as a dir): */ 51 | bool tried_dir; 52 | /* and whether we've tried to cd to the basename (treating it as a file): */ 53 | bool tried_file; 54 | /* and the last-ditch GetInfoArray */ 55 | bool tried_info; 56 | /* whether we found out the file type from cache */ 57 | bool from_cache; 58 | /* whether the given path was a file or directory. */ 59 | bool was_directory; 60 | /* if true, prepend the appropriate relative path to the result */ 61 | bool prepend_path; 62 | 63 | xstring_c saved_error_text; 64 | 65 | FileSet get_info; 66 | 67 | void PrepareToDie(); 68 | 69 | public: 70 | GetFileInfo(const FileAccessRef& a, const char *path, bool showdir); 71 | virtual ~GetFileInfo(); 72 | 73 | int Do(); 74 | const char *Status(); 75 | bool WasDirectory() const { return was_directory; } 76 | void DontPrependPath() { prepend_path=false; } 77 | }; 78 | 79 | #endif /* GETFILEINFO_H */ 80 | -------------------------------------------------------------------------------- /src/StringSet.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "StringSet.h" 22 | #include "misc.h" 23 | 24 | #define set_size set.count() 25 | 26 | StringSet::StringSet() {} 27 | StringSet::StringSet(const char *const *s,int n) { Assign(s,n); } 28 | StringSet::StringSet(const StringSet &o) { Assign(o.set.get(),o.set.count()); } 29 | StringSet::StringSet(const char *s) { Assign(&s,1); } 30 | 31 | bool StringSet::IsEqual(const char *const *set1,int n1) const 32 | { 33 | if(set_size!=n1) 34 | return false; 35 | int i=0; 36 | while(i0) 48 | set.append(xstrdup(*set1++)); 49 | } 50 | void StringSet::Append(const char *s) 51 | { 52 | if(!s) 53 | return; 54 | set.append(xstrdup(s)); 55 | } 56 | void StringSet::Replace(int i,const char *s) 57 | { 58 | if(i==set_size) 59 | Append(s); 60 | else if(i>=0 && i=set_size) 91 | return 0; 92 | char *s=set[i]; 93 | set[i]=0; 94 | set.remove(i); 95 | return s; 96 | } 97 | -------------------------------------------------------------------------------- /src/pgetJob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef PGETJOB_H 21 | #define PGETJOB_H 22 | 23 | #include "CopyJob.h" 24 | 25 | class pgetJob : public CopyJob 26 | { 27 | class ChunkXfer : public CopyJob 28 | { 29 | friend class pgetJob; 30 | 31 | off_t start; 32 | off_t limit; 33 | 34 | ChunkXfer(FileCopy *c,const char *n,off_t start,off_t limit); 35 | }; 36 | 37 | TaskRefArray chunks; 38 | int max_chunks; 39 | off_t chunks_bytes; 40 | void InitChunks(off_t offset,off_t size); 41 | 42 | off_t start0; 43 | off_t limit0; 44 | 45 | off_t total_xferred; 46 | float total_xfer_rate; 47 | 48 | bool no_parallel:1; 49 | bool chunks_done:1; 50 | bool pget_cont:1; 51 | 52 | void free_chunks(); 53 | ChunkXfer *NewChunk(const char *remote,off_t start,off_t limit); 54 | 55 | long total_eta; 56 | 57 | Timer status_timer; 58 | xstring status_file; 59 | void SaveStatus(); 60 | void LoadStatus(); 61 | void LoadStatus0(); 62 | 63 | protected: 64 | void NextFile(); 65 | 66 | public: 67 | int Do(); 68 | void ShowRunStatus(const SMTaskRef&); 69 | xstring& FormatStatus(xstring&,int,const char *); 70 | xstring& FormatJobs(xstring&,int verbose,int indent); 71 | 72 | pgetJob(FileCopy *c1,const char *n,int m=0); 73 | ~pgetJob(); 74 | void PrepareToDie(); 75 | 76 | void SetMaxConn(int n) { max_chunks=n; } 77 | 78 | off_t GetBytesCount() { return total_xferred; } 79 | double GetTransferRate() { return total_xfer_rate; } 80 | }; 81 | 82 | class pCopyJobCreator : public CopyJobCreator 83 | { 84 | public: 85 | int max_chunks; 86 | pCopyJobCreator(int n) : max_chunks(n) {} 87 | CopyJob *New(FileCopy *c,const char *n,const char *o) const { 88 | return new pgetJob(c,n,max_chunks); 89 | } 90 | }; 91 | 92 | #endif//PGETJOB_H 93 | -------------------------------------------------------------------------------- /src/PatternSet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef EXCLUDE_H 21 | #define EXCLUDE_H 22 | 23 | #include 24 | CDECL_BEGIN 25 | #include 26 | CDECL_END 27 | #include "xstring.h" 28 | 29 | class PatternSet 30 | { 31 | public: 32 | enum Type { EXCLUDE,INCLUDE }; 33 | 34 | class Pattern 35 | { 36 | protected: 37 | xstring_c pattern; 38 | public: 39 | virtual bool Match(const char *str)=0; 40 | Pattern(const char *str) : pattern(str) {} 41 | virtual ~Pattern() {} 42 | }; 43 | 44 | private: 45 | class PatternLink 46 | { 47 | friend class PatternSet; 48 | Type type; 49 | Pattern *pattern; 50 | PatternLink *next; 51 | PatternLink(Type t,Pattern *p,PatternLink *n) 52 | { 53 | type=t; 54 | pattern=p; 55 | next=n; 56 | } 57 | ~PatternLink() 58 | { 59 | delete pattern; 60 | } 61 | }; 62 | 63 | PatternLink *chain; 64 | PatternLink *first; 65 | 66 | public: 67 | PatternSet(); 68 | ~PatternSet(); 69 | 70 | void Add(Type,Pattern *); 71 | void AddFirst(Type,Pattern *); 72 | Type GetFirstType() const; 73 | 74 | bool Match(Type t,const char *str) const; 75 | bool MatchExclude(const char *str) const { return Match(EXCLUDE,str); } 76 | bool MatchInclude(const char *str) const { return Match(INCLUDE,str); } 77 | 78 | class Regex : public Pattern 79 | { 80 | regex_t compiled; 81 | xstring error; 82 | public: 83 | Regex(const char *str); 84 | bool Error() { return error!=0; } 85 | const char *ErrorText() { return error; } 86 | bool Match(const char *str); 87 | ~Regex(); 88 | }; 89 | class Glob : public Pattern 90 | { 91 | int slash_count; 92 | public: 93 | Glob(const char *p); 94 | bool Match(const char *str); 95 | }; 96 | }; 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2013 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef TIMER_H 21 | #define TIMER_H 22 | 23 | #include "SMTask.h" 24 | #include "ResMgr.h" 25 | #include "xlist.h" 26 | #include "xheap.h" 27 | 28 | class Timer 29 | { 30 | Time start; 31 | Time stop; 32 | TimeInterval last_setting; 33 | double random_max; 34 | const char *resource; 35 | const char *closure; 36 | 37 | static int infty_count; 38 | static xlist_head all_timers; 39 | xlist all_timers_node; 40 | static xheap running_timers; 41 | xheap::node running_timers_node; 42 | 43 | void re_sort(); 44 | void re_set(); 45 | void add_random(); 46 | void set_last_setting(const TimeInterval &); 47 | void init(); 48 | void reconfig(const char *); 49 | 50 | public: 51 | Timer(); 52 | ~Timer(); 53 | Timer(int s,int ms=0); 54 | Timer(const TimeInterval &); 55 | Timer(const char *,const char *); 56 | bool Stopped() const; 57 | void Stop() { stop=SMTask::now; re_sort(); } 58 | void Set(const TimeInterval&); 59 | void Set(time_t s,int ms=0) { Set(TimeInterval(s,ms)); } 60 | void SetMilliSeconds(int ms) { Set(TimeInterval(0,ms)); } 61 | void SetMicroSeconds(int us) { Set(TimeInterval(0,0,us)); } 62 | void SetResource(const char *,const char *); 63 | void AddRandom(double r); 64 | void Reset(const Time &t); 65 | void Reset() { Reset(SMTask::now); } 66 | void Reset(const Timer &t) { Reset(t.GetStartTime()); } 67 | void ResetDelayed(int s); 68 | void StopDelayed(int s); 69 | const TimeInterval& GetLastSetting() const { return last_setting; } 70 | TimeDiff TimePassed() const { return SMTask::now-start; } 71 | TimeInterval TimeLeft() const; 72 | bool IsInfty() const { return last_setting.IsInfty(); } 73 | const Time &GetStartTime() const { return start; } 74 | static timeval GetTimeoutTV(); 75 | static void ReconfigAll(const char *); 76 | }; 77 | 78 | bool operator<(const Timer& a,const Timer& b); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/ConnectionSlot.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "FileAccess.h" 22 | #include "ConnectionSlot.h" 23 | 24 | ConnectionSlot ConnectionSlot::lftp_slots; 25 | 26 | ConnectionSlot::SlotValue::SlotValue(const char *n,const FileAccess *s) 27 | : KeyValueDB::Pair(n,s->GetConnectURL()) 28 | { 29 | session=s->Clone(); 30 | } 31 | ConnectionSlot::SlotValue::SlotValue(const char *n,const char *v) 32 | : KeyValueDB::Pair(n,v) 33 | { 34 | session=FileAccess::New(v); 35 | } 36 | ConnectionSlot::SlotValue *ConnectionSlot::Find(const char *n) 37 | { 38 | KeyValueDB::Pair **slot=lftp_slots.LookupPair(n); 39 | return slot?static_cast(*slot):0; 40 | } 41 | void ConnectionSlot::Set(const char *n,const FileAccess *fa) 42 | { 43 | const char *url=fa->GetConnectURL(); 44 | if(!url || !*url) 45 | { 46 | lftp_slots.KeyValueDB::Remove(n); 47 | return; 48 | } 49 | ConnectionSlot::SlotValue *s=Find(n); 50 | if(!s) 51 | { 52 | lftp_slots.AddPair(new SlotValue(n,fa)); 53 | return; 54 | } 55 | if(!s->session->SameLocationAs(fa)) 56 | { 57 | s->SetValue(url); 58 | s->session=fa->Clone(); 59 | } 60 | } 61 | void ConnectionSlot::SetCwd(const char *n,const FileAccess::Path &cwd) 62 | { 63 | ConnectionSlot::SlotValue *s=Find(n); 64 | if(!s || !s->session) 65 | return; 66 | s->session->SetCwd(cwd); 67 | s->SetValue(s->session->GetConnectURL()); 68 | } 69 | const FileAccess *ConnectionSlot::FindSession(const char *n) 70 | { 71 | ConnectionSlot::SlotValue *s=Find(n); 72 | if(s) 73 | return s->session; 74 | return 0; 75 | } 76 | char *ConnectionSlot::Format() 77 | { 78 | return lftp_slots.FormatThis(); 79 | } 80 | char *ConnectionSlot::FormatThis() 81 | { 82 | return KeyValueDB::Format(); 83 | } 84 | void ConnectionSlot::Cleanup() 85 | { 86 | lftp_slots.Empty(); 87 | } 88 | ConnectionSlot::ConnectionSlot() : KeyValueDB() {} 89 | ConnectionSlot::~ConnectionSlot() {} 90 | -------------------------------------------------------------------------------- /src/SignalHook.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include "SignalHook.h" 22 | 23 | int *SignalHook::counts=0; 24 | struct sigaction *SignalHook::old_handlers=0; 25 | bool *SignalHook::old_saved=0; 26 | 27 | void SignalHook::cnt_handler(int sig) 28 | { 29 | counts[sig]++; 30 | } 31 | 32 | void SignalHook::set_signal(int sig,signal_handler handler) 33 | { 34 | if(!old_saved[sig]) 35 | { 36 | sigaction(sig,0,&old_handlers[sig]); 37 | if(sig==SIGINT && old_handlers[sig].sa_handler==(signal_handler)SIG_IGN) 38 | return; 39 | old_saved[sig]=true; 40 | } 41 | struct sigaction act; 42 | act.sa_handler=handler; 43 | act.sa_flags=0; 44 | sigemptyset(&act.sa_mask); 45 | sigaction(sig,&act,0); 46 | } 47 | 48 | void SignalHook::Restore(int i) 49 | { 50 | if(old_saved[i]) 51 | sigaction(i,&old_handlers[i],0); 52 | SignalHook::Unblock(i); 53 | } 54 | 55 | void SignalHook::RestoreAll() 56 | { 57 | for(int i=0; i<256; i++) 58 | Restore(i); 59 | } 60 | 61 | void SignalHook::Block(int sig) 62 | { 63 | sigset_t s; 64 | sigemptyset(&s); 65 | sigaddset(&s,sig); 66 | sigprocmask(SIG_BLOCK,&s,0); 67 | } 68 | void SignalHook::Unblock(int sig) 69 | { 70 | sigset_t s; 71 | sigemptyset(&s); 72 | sigaddset(&s,sig); 73 | sigprocmask(SIG_UNBLOCK,&s,0); 74 | } 75 | 76 | void SignalHook::ClassInit() 77 | { 78 | if(counts) 79 | return; 80 | counts=new int[256]; 81 | old_handlers=new struct sigaction[256]; 82 | old_saved=new bool[256]; 83 | for(int i=0; i<256; i++) 84 | { 85 | counts[i]=0; 86 | old_saved[i]=false; 87 | } 88 | Ignore(SIGPIPE); // want to get EPIPE 89 | #ifdef SIGXFSZ 90 | Ignore(SIGXFSZ); // and EFBIG 91 | #endif 92 | } 93 | 94 | void SignalHook::Cleanup() 95 | { 96 | delete [] counts; 97 | delete [] old_handlers; 98 | delete [] old_saved; 99 | } 100 | -------------------------------------------------------------------------------- /src/ArgV.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2015 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef ARGV_H 21 | #define ARGV_H 22 | 23 | #include "trio.h" 24 | #include "StringSet.h" 25 | #include "getopt.h" 26 | 27 | class ArgV : public StringSet 28 | { 29 | int ind; 30 | 31 | public: 32 | ArgV() { ind=0; } 33 | ArgV(const char *a0) : StringSet(&a0,1) { ind=0; } 34 | ArgV(const char *a0, const char *args); 35 | ArgV(const ArgV& a) : StringSet(a) { ind=0; } 36 | ArgV(const ArgV *a) : StringSet(*a) { ind=0; } 37 | ArgV(int new_c,const char * const *new_v) : StringSet(new_v,new_c) { ind=0; } 38 | ~ArgV(); 39 | 40 | void Append(const char *s) { StringSet::Append(s); } 41 | void Append(int a) { char buf[32]; sprintf(buf,"%d",a); Append(buf); } 42 | void Add(const char *a) { Append(a); } // alias 43 | 44 | char *Combine(int start_index=0,int end_index=0) const; 45 | 46 | // for the UNIX shell 47 | char *CombineShellQuoted(int start) const; 48 | // for lftp's CmdExec 49 | char *CombineQuoted(int start_index=0) const; 50 | char *CombineCmd(int i=0) const; 51 | 52 | int getopt_long(const char *opts,const struct option *lopts,int *lind=0); 53 | int getopt(const char *opts) 54 | { 55 | return getopt_long(opts,0,0); 56 | } 57 | const char *getopt_error_message(int e); 58 | 59 | void seek(int n); 60 | void rewind() { seek(0); } 61 | const char *getnext(); 62 | 63 | const char *getarg(int n) const { return String(n); } 64 | const char *getcurr() const { return indn)--ind; Remove(n); } 68 | void insarg(int n,const char *s) { InsertBefore(n,s); } 69 | const char *a0() const { return getarg(0); } 70 | void back(); 71 | int count() const { return Count(); } 72 | const char *const*GetV() const { return Set(); } 73 | char **GetVNonConst() { return SetNonConst(); } 74 | }; 75 | 76 | #endif//ARGV_H 77 | -------------------------------------------------------------------------------- /src/SysCmdJob.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "SysCmdJob.h" 28 | #include "SignalHook.h" 29 | #include "misc.h" 30 | 31 | #define super Job 32 | 33 | SysCmdJob::SysCmdJob(const char *c) 34 | : cmd(c) 35 | { 36 | } 37 | 38 | void SysCmdJob::PrepareToDie() 39 | { 40 | Bg(); 41 | AcceptSig(SIGTERM); 42 | if(w) 43 | w.borrow()->Auto(); 44 | super::PrepareToDie(); 45 | } 46 | SysCmdJob::~SysCmdJob() {} 47 | 48 | int SysCmdJob::Do() 49 | { 50 | int m=STALL; 51 | 52 | if(w) 53 | return m; 54 | 55 | const char *shell=getenv("SHELL"); 56 | if(!shell) 57 | shell="/bin/sh"; 58 | 59 | ProcWait::Signal(false); 60 | 61 | pid_t pid; 62 | fflush(stderr); 63 | switch(pid=fork()) 64 | { 65 | case(0): /* child */ 66 | setpgid(0,0); 67 | kill(getpid(),SIGSTOP); 68 | SignalHook::RestoreAll(); 69 | if(cmd) 70 | execlp(shell,basename_ptr(shell),"-c",cmd.get(),NULL); 71 | else 72 | execlp(shell,basename_ptr(shell),NULL); 73 | fprintf(stderr,_("execlp(%s) failed: %s\n"),shell,strerror(errno)); 74 | fflush(stderr); 75 | _exit(1); 76 | case(-1): /* error */ 77 | TimeoutS(1); // wait a second and retry 78 | goto out; 79 | } 80 | /* parent */ 81 | int info; 82 | waitpid(pid,&info,WUNTRACED); // wait until the process stops 83 | w=new ProcWait(pid); 84 | fg_data=new FgData(pid,fg); 85 | m=MOVED; 86 | out: 87 | ProcWait::Signal(true); 88 | return m; 89 | } 90 | 91 | int SysCmdJob::AcceptSig(int sig) 92 | { 93 | if(!w) 94 | { 95 | if(sig==SIGINT) 96 | return WANTDIE; 97 | return STALL; 98 | } 99 | w->Kill(sig); 100 | if(sig!=SIGCONT) 101 | AcceptSig(SIGCONT); // for the case of stopped process 102 | return MOVED; 103 | } 104 | -------------------------------------------------------------------------------- /src/mvJob.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include "trio.h" 23 | #include "mvJob.h" 24 | #include "misc.h" 25 | 26 | mvJob::mvJob(FileAccess *session,const char *f,const char *t,FA::open_mode m1) 27 | : SessionJob(session), from(f), to(t), m(m1), 28 | remove_target(false), failed(false), done(false) 29 | { 30 | if(to.last_char()=='/') 31 | to.append(basename_ptr(from)); 32 | doOpen(); 33 | } 34 | 35 | void mvJob::doOpen() const 36 | { 37 | if(remove_target) 38 | session->Open(to,FA::REMOVE); 39 | else 40 | session->Open2(from,to,m); 41 | } 42 | 43 | int mvJob::Do() 44 | { 45 | if(Done()) 46 | return STALL; 47 | 48 | int res=session->Done(); 49 | if(res==FA::IN_PROGRESS || res==FA::DO_AGAIN) 50 | return STALL; 51 | if(res!=FA::OK && !remove_target) { 52 | fprintf(stderr,"%s: %s\n",cmd(),session->StrError(res)); 53 | done=failed=true; 54 | } 55 | session->Close(); 56 | if(remove_target) { 57 | remove_target=false; 58 | doOpen(); 59 | } else 60 | done=true; 61 | return MOVED; 62 | } 63 | 64 | xstring& mvJob::FormatStatus(xstring& s,int v,const char *prefix) 65 | { 66 | SessionJob::FormatStatus(s,v,prefix); 67 | if(Done()) 68 | return s; 69 | if(remove_target) 70 | s.appendf("%srm %s [%s]\n",prefix,to.get(),session->CurrentStatus()); 71 | else 72 | s.appendf("%s%s %s=>%s [%s]\n",prefix,cmd(),from.get(),to.get(),session->CurrentStatus()); 73 | return s; 74 | } 75 | 76 | void mvJob::ShowRunStatus(const SMTaskRef& s) 77 | { 78 | if(Done()) 79 | return; 80 | if(remove_target) 81 | s->Show("rm %s [%s]\n",to.get(),session->CurrentStatus()); 82 | else 83 | s->Show("%s %s=>%s [%s]\n",cmd(),from.get(),to.get(),session->CurrentStatus()); 84 | } 85 | 86 | void mvJob::SayFinal() 87 | { 88 | if(failed) 89 | return; 90 | if(m==FA::RENAME) { 91 | // xgettext:c-format 92 | printf(_("rename successful\n")); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = lftp.conf lftp.lsm FAQ MIRRORS BUGS FEATURES\ 2 | README README.debug-levels README.modules README.dnssec\ 3 | lib/hstrerror.c 4 | EXTRA_DIST += $(top_srcdir)/.version 5 | BUILT_SOURCES = $(top_srcdir)/.version 6 | if NEED_TRIO 7 | TRIO = trio 8 | endif 9 | SUBDIRS = m4 doc lib $(TRIO) src po 10 | ACLOCAL_AMFLAGS = -I m4 11 | 12 | install-data-local: 13 | if [ ! -f $(DESTDIR)$(sysconfdir)/lftp.conf ]; then \ 14 | $(mkinstalldirs) $(DESTDIR)$(sysconfdir); \ 15 | $(INSTALL_DATA) $(srcdir)/lftp.conf $(DESTDIR)$(sysconfdir)/lftp.conf; \ 16 | fi 17 | 18 | uninstall-local: 19 | if cmp -s $(DESTDIR)$(sysconfdir)/lftp.conf $(srcdir)/lftp.conf; then \ 20 | echo "$(DESTDIR)$(sysconfdir)/lftp.conf is not changed and will be removed."; \ 21 | rm -f $(DESTDIR)$(sysconfdir)/lftp.conf; \ 22 | fi 23 | 24 | $(top_srcdir)/.version: 25 | echo $(VERSION) > $@-t && mv $@-t $@ 26 | 27 | dist-hook: 28 | echo $(VERSION) > $(distdir)/.tarball-version 29 | @echo $(PACKAGE).spec updating... 30 | @rm -f $(distdir)/$(PACKAGE).spec 31 | @-sed "s/%define version .*/%define version $(VERSION)/" \ 32 | $(srcdir)/$(PACKAGE).spec > $(distdir)/$(PACKAGE).spec && \ 33 | cp $(distdir)/$(PACKAGE).spec $(srcdir)/$(PACKAGE).spec 34 | @echo $(PACKAGE).lsm updating... 35 | @rm -f $(distdir)/$(PACKAGE).lsm 36 | @-SIZE=`$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c | wc -c`; SIZE=`expr \( $$SIZE + 512 \) / 1024`; echo Size: $$SIZE kB; \ 37 | DATE=`date +%Y-%m-%d`; echo Date: $$DATE; \ 38 | sed -e "s/Version: .*/Version: $(VERSION)/" \ 39 | -e "s/[0-9]* kB $(PACKAGE)-.*\.tar\.gz/$$SIZE kB $(PACKAGE)-$(VERSION).tar.gz/" \ 40 | -e "s/Entered-date: .*/Entered-date: $$DATE/" \ 41 | $(srcdir)/$(PACKAGE).lsm > $(distdir)/$(PACKAGE).lsm && \ 42 | cp $(distdir)/$(PACKAGE).lsm $(srcdir)/$(PACKAGE).lsm 43 | 44 | REL_DIR=/home/lav/www-lftp/ftp 45 | 46 | release-check: 47 | for opt in "" "--with-modules" "--without-gnutls" "--without-openssl" \ 48 | "--without-gnutls --without-openssl" \ 49 | "--with-modules --without-gnutls --without-openssl"; \ 50 | do \ 51 | echo "Testing $$opt ..."; \ 52 | make DISTCHECK_CONFIGURE_FLAGS="$$opt" distcheck >/dev/null || exit 1; \ 53 | done 54 | 55 | release: 56 | make release-check 57 | make release-ftp 58 | 59 | release-ftp: 60 | mv $(PACKAGE)-$(VERSION).tar.gz $(REL_DIR)/$(PACKAGE)-$(VERSION).tar.gz 61 | cp -p $(PACKAGE).lsm $(REL_DIR)/$(PACKAGE)-$(VERSION).lsm 62 | cd $(REL_DIR) && \ 63 | (addbz $(PACKAGE)-$(VERSION).tar.gz; \ 64 | gpg -ba $(PACKAGE)-$(VERSION).tar.gz; \ 65 | gpg -ba $(PACKAGE)-$(VERSION).tar.bz2; \ 66 | gpg -ba $(PACKAGE)-$(VERSION).tar.xz; \ 67 | md5sum $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION).tar.bz2 $(PACKAGE)-$(VERSION).tar.xz > $(PACKAGE)-$(VERSION).md5sum) 68 | mutt -s add lsm@execpc.com < $(PACKAGE).lsm 69 | -------------------------------------------------------------------------------- /src/TreatFileJob.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * lftp - file transfer program 3 | * 4 | * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include "TreatFileJob.h" 24 | #include "StatusLine.h" 25 | #include "ArgV.h" 26 | #include "misc.h" 27 | 28 | TreatFileJob::TreatFileJob(FileAccess *s,ArgV *a) 29 | : FinderJob(s), args(a) 30 | { 31 | quiet=false; 32 | failed=file_count=0; 33 | Need(FileInfo::NAME); 34 | 35 | curr=0; 36 | set_maxdepth(0); 37 | 38 | op=args->a0(); 39 | Begin(a->getcurr()); 40 | } 41 | 42 | /* process a new directory */ 43 | void TreatFileJob::Begin(const char *d) 44 | { 45 | NextDir(d); 46 | } 47 | 48 | void TreatFileJob::Finish() 49 | { 50 | /* next? */ 51 | const char *d=args->getnext(); 52 | if(d) { 53 | /* we have another argument */ 54 | Begin(d); 55 | return; 56 | } 57 | } 58 | 59 | TreatFileJob::~TreatFileJob() 60 | { 61 | } 62 | 63 | TreatFileJob::prf_res TreatFileJob::ProcessFile(const char *d,const FileInfo *fi) 64 | { 65 | curr=fi; 66 | if(session->IsClosed()) 67 | { 68 | if(!first) 69 | first=new FileInfo(*fi); 70 | 71 | TreatCurrent(d,fi); 72 | } 73 | int res=session->Done(); 74 | if(res==FA::IN_PROGRESS) 75 | return PRF_LATER; 76 | 77 | curr=0; 78 | file_count++; 79 | 80 | if(res<0) 81 | { 82 | failed++; 83 | if(!quiet) 84 | eprintf("%s: %s\n",op,session->StrError(res)); 85 | } 86 | CurrentFinished(d,fi); 87 | 88 | session->Close(); 89 | return res<0? PRF_ERR:PRF_OK; 90 | } 91 | 92 | xstring& TreatFileJob::FormatStatus(xstring& s,int v,const char *prefix) 93 | { 94 | SessionJob::FormatStatus(s,v,prefix); 95 | if(Done() || !curr) 96 | return s; 97 | return s.appendf("\t`%s' [%s]\n",curr->name.get(),session->CurrentStatus()); 98 | } 99 | 100 | void TreatFileJob::ShowRunStatus(const SMTaskRef& s) 101 | { 102 | if(curr && !Done()) 103 | s->Show("%s `%s' [%s]",op,curr->name.get(),session->CurrentStatus()); 104 | } 105 | --------------------------------------------------------------------------------