hello alexander -
i've been using lftp for years and consider it one of the essential
unix tools - i think i used ncftp back in 1997 or so but once i found
an early version of lftp i never looked back. thanks for this
wonderful program!
i recently found myself working with a client who regularly makes
changes to his files. he also creates a bunch of files on the server
that i'm not interested in, scattered amongst the ones i do want.
when this first started, i deleted all the files i didn't want from my
local copy; but then every time i mirrored the files to get his
changes, of course all those unwanted files and directories would
re-appear. building an exclude list isn't workable; an include-only
list might do it but would be a pain to maintain.
to solve my problem, i quickly hacked in a new option to the mirror
command, --only-existing. it's kind of the reverse of --only-missing;
it skips any file from the source that does not already exist at the
target.
i don't know if you'd like to include this in the standard lftp, but
i'm attaching the patch just in case. i haven't really tested this
thoroughly - it seems to do what i need it to - and my c is rusty so
you'd probably want to check it carefully first if you're going to
incoporate it.
cheers, and thanks again for lftp!
-damon
diff -urN lftp-3.5.9.orig/doc/lftp.1 lftp-3.5.9/doc/lftp.1
--- lftp-3.5.9.orig/doc/lftp.1 2006-08-22 01:16:53.000000000 -0700
+++ lftp-3.5.9/doc/lftp.1 2007-02-19 10:21:05.000000000 -0800
@@ -384,6 +384,7 @@
--ignore-time ignore time when deciding whether to download
--ignore-size ignore size when deciding whether to download
--only-missing download only missing files
+ --only-existing download only files already existing at target
-n, --only-newer download only newer files (-c won't work)
-r, --no-recursion don't go to subdirectories
--no-symlinks don't create symbolic links
diff -urN lftp-3.5.9.orig/src/MirrorJob.cc lftp-3.5.9/src/MirrorJob.cc
--- lftp-3.5.9.orig/src/MirrorJob.cc 2007-01-05 22:39:33.000000000 -0800
+++ lftp-3.5.9/src/MirrorJob.cc 2007-02-19 10:19:12.000000000 -0800
@@ -254,6 +254,12 @@
else
stats.new_files++;
}
+ else if(flags&ONLY_EXISTING)
+ {
+ Report(_("Skipping file `%s' (only-existing)"),
+ dir_file(source_relative_dir,file->name));
+ goto skip;
+ }
else
stats.new_files++;
@@ -332,8 +338,19 @@
bool create_target_dir=true;
FileInfo *old=target_set->FindByName(file->name);
- if(old && old->defined&old->TYPE && old->filetype==old->DIRECTORY)
+ if(!old)
+ {
+ if(flags&ONLY_EXISTING)
+ {
+ Report(_("Skipping directory `%s' (only-existing)"),
+ dir_file(target_relative_dir,file->name));
+ goto skip;
+ }
+ }
+ else if(old->defined&old->TYPE && old->filetype==old->DIRECTORY)
+ {
create_target_dir=false;
+ }
if(target_is_local && !script_only)
{
if(lstat(target_name,&st)!=-1)
@@ -445,6 +462,12 @@
}
else
{
+ if(flags&ONLY_EXISTING)
+ {
+ Report(_("Skipping symlink `%s' (only-existing)"),
+ dir_file(target_relative_dir,file->name));
+ goto skip;
+ }
stats.new_symlinks++;
}
Report(_("Making symbolic link `%s' to `%s'"),
@@ -1278,6 +1301,7 @@
OPT_NO_UMASK,
OPT_OLDER_THAN,
OPT_ONLY_MISSING,
+ OPT_ONLY_EXISTING,
OPT_PERMS,
OPT_REMOVE_SOURCE_FILES,
OPT_SCRIPT,
@@ -1315,6 +1339,7 @@
{"ignore-time",no_argument,0,OPT_IGNORE_TIME},
{"ignore-size",no_argument,0,OPT_IGNORE_SIZE},
{"only-missing",no_argument,0,OPT_ONLY_MISSING},
+ {"only-existing",no_argument,0,OPT_ONLY_EXISTING},
{"log",required_argument,0,OPT_SCRIPT},
{"script", required_argument,0,OPT_SCRIPT_ONLY},
{"just-print",optional_argument,0,OPT_SCRIPT_ONLY},
@@ -1519,6 +1544,9 @@
case(OPT_SKIP_NOACCESS):
skip_noaccess=true;
break;
+ case(OPT_ONLY_EXISTING):
+ flags|=MirrorJob::ONLY_EXISTING;
+ break;
case('?'):
eprintf(_("Try `help %s' for more information.\n"),args->a0());
no_job:
diff -urN lftp-3.5.9.orig/src/MirrorJob.h lftp-3.5.9/src/MirrorJob.h
--- lftp-3.5.9.orig/src/MirrorJob.h 2006-08-29 00:25:27.000000000 -0700
+++ lftp-3.5.9/src/MirrorJob.h 2007-02-19 10:18:28.000000000 -0800
@@ -147,7 +147,8 @@
REMOVE_FIRST=1<<11,
IGNORE_SIZE=1<<12,
NO_SYMLINKS=1<<13,
- LOOP=1<<14
+ LOOP=1<<14,
+ ONLY_EXISTING=1<<15
};
void SetFlags(int f,int v)