diff -r 3e2d7841482d src/init.c
--- a/src/init.c	Wed Sep 10 08:42:42 2008 -0700
+++ b/src/init.c	Wed Oct 01 06:14:59 2008 -0400
@@ -183,6 +183,7 @@ static const struct {
 #endif
   { "input",            &opt.input_filename,    cmd_file },
   { "keepsessioncookies", &opt.keep_session_cookies, cmd_boolean },
+  { "limitfile",        &opt.limit_file,        cmd_number_inf },
   { "limitrate",        &opt.limit_rate,        cmd_bytes },
   { "loadcookies",      &opt.cookies_input,     cmd_file },
   { "logfile",          &opt.lfilename,         cmd_file },
diff -r 3e2d7841482d src/main.c
--- a/src/main.c	Wed Sep 10 08:42:42 2008 -0700
+++ b/src/main.c	Wed Oct 01 06:14:59 2008 -0400
@@ -201,6 +201,7 @@ static struct cmdline_option option_data
     { "input-file", 'i', OPT_VALUE, "input", -1 },
     { "keep-session-cookies", 0, OPT_BOOLEAN, "keepsessioncookies", -1 },
     { "level", 'l', OPT_VALUE, "reclevel", -1 },
+    { "limit-file", 0, OPT_VALUE, "limitfile", -1 },
     { "limit-rate", 0, OPT_VALUE, "limitrate", -1 },
     { "load-cookies", 0, OPT_VALUE, "loadcookies", -1 },
     { "max-redirect", 0, OPT_VALUE, "maxredirect", -1 },
diff -r 3e2d7841482d src/options.h
--- a/src/options.h	Wed Sep 10 08:42:42 2008 -0700
+++ b/src/options.h	Wed Oct 01 06:14:59 2008 -0400
@@ -119,6 +119,8 @@ struct options
   double waitretry;		/* The wait period between retries. - HEH */
   bool use_robots;		/* Do we heed robots.txt? */
 
+  wgint limit_file;		/* Limit the number of files to be
+				   downloaded and stored. */
   wgint limit_rate;		/* Limit the download rate to this
 				   many bps. */
   SUM_SIZE_INT quota;		/* Maximum file size to download and
diff -r 3e2d7841482d src/recur.c
--- a/src/recur.c	Wed Sep 10 08:42:42 2008 -0700
+++ b/src/recur.c	Wed Oct 01 06:14:59 2008 -0400
@@ -219,6 +219,8 @@ retrieve_tree (const char *start_url)
       bool is_css = false;
       bool dash_p_leaf_HTML = false;
 
+      if (opt.limit_file && opt.numurls >= opt.limit_file)
+        break;
       if (opt.quota && total_downloaded_bytes > opt.quota)
         break;
       if (status == FWRITEERR)
@@ -443,6 +445,8 @@ retrieve_tree (const char *start_url)
     url_free (start_url_parsed);
   string_set_free (blacklist);
 
+  if (opt.limit_file && opt.numurls >= opt.limit_file)
+    return QUOTEXC;
   if (opt.quota && total_downloaded_bytes > opt.quota)
     return QUOTEXC;
   else if (status == FWRITEERR)
diff -r 3e2d7841482d src/retr.c
--- a/src/retr.c	Wed Sep 10 08:42:42 2008 -0700
+++ b/src/retr.c	Wed Oct 01 06:14:59 2008 -0400
@@ -55,6 +55,9 @@ as that of the covered work.  */
 
 /* Total size of downloaded files.  Used to enforce quota.  */
 SUM_SIZE_INT total_downloaded_bytes;
+
+/* Total number of downloaded files.  Used to enforce file limit. */
+wgint total_downloaded_file;
 
 /* Total download time in seconds. */
 double total_download_time;
@@ -863,6 +866,11 @@ retrieve_from_file (const char *file, bo
       if (cur_url->ignore_when_downloading)
         continue;
 
+      if (opt.limit_file && opt.numurls >= opt.limit_file)
+        {
+          status = QUOTEXC;
+          break;
+        }
       if (opt.quota && total_downloaded_bytes > opt.quota)
         {
           status = QUOTEXC;
