Subject: [436] how to modify ftp commands

From: JARLE MARTINSEN +41 22 730 5949 <[email-masked]>
Date: Tue, 13 Sep 1994 07:52:03 +0100 (CET)

Hi,

I'm looking for a way to modify the ls and dir commands
in wu-ftpd.  I would prefer not to show hidden files,
i.e. preceded with a dot (.something).

Any pointers on how to do so would be appriciated.

Thanks.

Regards,
/jarle

Jarle Martinsen
International Telecomunnication Union (ITU)
Place des nations
CH-1211 Geneva 20
Switzerland

Internet: [email-masked]
X.400:    S=martinsen; P=itu; A=arcom; C=ch
Voice:    +41 22 730 5949
Fax:      +41 22 730 5337

---

From: jher <[email-masked]>
Date: Tue, 13 Sep 1994 02:16:56 -0500 (CDT)

I remember someone posting a perl script (?) program for wu-ftpd stats.  
Anyone have a copy they can mail me? Thanks.

Only death awaits outside the Eden Matrix.
	[email-masked]						Fnord
		SysAdmin eden.com

---

From: [email-masked] (Leigh Hume)
Date: Tue, 13 Sep 1994 22:25:30 +1000 (EST)

>From your last message :

> Anyone have a copy they can mail me? Thanks.

I think we might have something which might be useful. It was/is part of
the wuarchive. I know nothing about it.

-- 

Leigh HUME

Voice +61 2 850 9588	    Fax +61 2 850 9551	     Email [email-masked]
Post Mail: Dr Leigh Hume, School of MPCE, Macquarie University 2109, AUSTRALIA

#! /usr/local/bin/perl
# Usage:
#   xferstats [filename|-] [filename...]
# If filename is not specified, use /usr/adm/xferlog for input
# If filename is "-", use stdin
# If filename is specified, use filename for input
# Multiple filenames may be specified, they will be read sequentially

$mydom1 = "wustl";
$mydom2 = "edu";

if ($#ARGV == -1) { $ARGV[0] = "/usr/adm/xferlog"; }

line: while (<>) {

   @line = split;
   if ($#line != 16) {
      print "NF: skip $_\n";
      next;
   }

   $daytime = substr($_, 0, 10) . substr($_, 19, 5);
   @path = split(/\//, $line[8]);

   while (length($path[1]) <= 1) {
      shift @path;
      next line if ($#path == -1);
   }

   if ($#path == 1)
      { $pathkey = "Index/Informational Files"; }
   elsif ($#path == 2)
      { $pathkey = $path[1]; }
   else
      { $pathkey = $path[1] . "/" . $path[2]; }

   $line[6] =~ tr/A-Z/a-z/;

   $xferfiles++;                                # total files sent
   $xferfiles{$daytime}++;                      # files per day
   $groupfiles{$pathkey}++;                     # per-group accesses
   $systemfiles{$line[6]}++;                    # files per host
#  $accesscnt{$line[8]}++;                      # per-file accesses

   $xfersecs{$daytime}    += $line[5];          # xmit seconds per day
   $xferbytes{$daytime}   += $line[7];          # bytes per day
   $systemsecs{$line[6]}  += $line[5];          # xmit seconds per host
   $systembytes{$line[6]} += $line[7];          # bytes per host
   $xferbytes             += $line[7];          # total bytes sent
   $groupbytes{$pathkey}  += $line[7];          # per-group bytes sent

}

@syslist = keys(systemfiles);
@dates = sort datecompare keys(xferbytes);

print "TOTALS FOR SUMMARY PERIOD ", $dates[0], " TO ", $dates[$#dates], "\n\n";
printf ("Files Transmitted During Summary Period  %12.0f\n", $xferfiles);
printf ("Bytes Transmitted During Summary Period  %12.0f\n", $xferbytes); 
printf ("Systems Using Archives                   %12.0f\n\n", $#syslist+1);

printf ("Average Files Transmitted Daily          %12.0f\n", $xferfiles / ($#dates + 1));
printf ("Average Bytes Transmitted Daily          %12.0f\n", $xferbytes / ($#dates + 1));

format top1 =

Daily Transmission Statistics

                 Number Of    Number of    Average    Percent Of  Percent Of
     Date        Files Sent  Bytes  Sent  Xmit  Rate  Files Sent  Bytes Sent
---------------  ----------  -----------  ----------  ----------  ----------
.

format line1 =
@<<<<<<<<<<<<<<  @>>>>>>>>>  @>>>>>>>>>>  @>>>>>>>>>  @>>>>>>>    @>>>>>>>  
$date,           $nfiles,    $nbytes,     $avgrate,   $pctfiles,  $pctbytes
.

$^ = top1;
$~ = line1;

foreach $date ( sort datecompare keys(xferbytes) ) {

   $nfiles   = $xferfiles{$date};
   $nbytes   = $xferbytes{$date};
   $avgrate  = sprintf("%5.1f KB/s", $xferbytes{$date}/$xfersecs{$date}/1000);
   $pctfiles = sprintf("%8.2f", 100*$xferfiles{$date} / $xferfiles);
   $pctbytes = sprintf("%8.2f", 100*$xferbytes{$date} / $xferbytes);
   write;
}

format top2 =

Total Transfers from each Archive Section

                                                 ---- Percent  Of ---- Interest
     Archive Section      Files Sent Bytes Sent  Files Sent Bytes Sent  Factor
------------------------- ---------- ----------- ---------- ---------- --------
.

format line2 =
@<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>> @>>>>>>>   @>>>>>>>   @>>>>>>>
$section,                 $files,    $bytes,     $pctfiles, $pctbytes, $fac
.

$| = 1;
$- = 0;
$^ = top2;
$~ = line2;

dbmopen(USAGE, "/usr/adm/usage_info", 0644);
foreach $section ( sort keys(groupfiles) ) {

   $files = $groupfiles{$section};
   $bytes = $groupbytes{$section};
   $pctbytes = sprintf("%8.2f", 100 * $groupbytes{$section} / $xferbytes);
   $pctfiles = sprintf("%8.2f", 100 * $groupfiles{$section} / $xferfiles);
   $key = "/" . $section . "\0";
   if ($USAGE{$key} == 0) {
      $fac = "n/a";
   } else {
      $fac = sprintf("%8.2f", $groupbytes{$section} / $USAGE{$key});
   }
   $fac{$section} = $fac;
   write;

}

foreach $sys ( keys(systemfiles) ) {

   @address = split(/\./, $sys);

#   if (int($address[$#address]) > 0) {
#      $domain = $address[0] . "." . $address[1];
#   } else {
#      $domain = $address[$#address-1] . "." . $address[$#address];
#   }

   $domain = $address[$#address];
   if ($address[$#address-1] eq $mydom1 && $address[$#address] eq $mydom2)
      { $domain = "wustl.edu"; }
   if ( int($address[0]) > 0 || $#address < 2 )
      { $domain = "unresolved"; }

   $domainfiles{$domain} += $systemfiles{$sys};
   $domainbytes{$domain} += $systembytes{$sys};
   $domainsecs{$domain}  += $systemsecs{$sys};

}

if ( $xferfiles < 1 ) { $xferfiles = 1; }
if ( $xferbytes < 1 ) { $xferbytes = 1; }

format top3 =

Total Transfer Amount By Domain

             Number Of    Number of     Average    Percent Of  Percent Of
Domain Name  Files Sent   Bytes Sent   Xmit  Rate  Files Sent  Bytes Sent
-----------  ----------  ------------  ----------  ----------  ----------
.

format line3 =
@<<<<<<<<<<  @>>>>>>>>>  @>>>>>>>>>>>  @>>>>>>>>>  @>>>>>>>    @>>>>>>>  
$domain,     $files,     $bytes,       $avgrate,   $pctfiles,  $pctbytes
.

$- = 0;
$^ = top3;
$~ = line3;

foreach $domain ( sort domnamcompare keys(domainfiles) ) {

   if ( $domainsecs{$domain} < 1 ) { $domainsecs{$domain} = 1; }

   $files = $domainfiles{$domain};
   $bytes = $domainbytes{$domain};
   $avgrate  = sprintf("%5.1f KB/s",
                  $domainbytes{$domain}/$domainsecs{$domain}/1000);
   $pctfiles = sprintf("%8.2f", 100 * $domainfiles{$domain} / $xferfiles);
   $pctbytes = sprintf("%8.2f", 100 * $domainbytes{$domain} / $xferbytes);
   write;

}

print "\n";
print "These figures only reflect ANONYMOUS FTP transfers.  There are many\n";
print "sites which mount the archives via NFS, and those transfers are not\n";
print "logged and reported by this program.\n\n\n";

format top4 =

Top 15 Most Popular Archive Sections By Bytes Transferred

                                                 ---- Percent  of ---- Interest
     Archive Section      Files Sent Bytes  Sent Files Sent Bytes Sent  Factor
------------------------- ---------- ----------- ---------- ---------- --------
.

format line4 =
@<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>> @>>>>>>>   @>>>>>>>   @>>>>>>>
$section,                 $files,    $bytes,     $pctfiles, $pctbytes, $fac
.

$- = 0;
$^ = top4;
$~ = line4;

@topgroups = sort bytecompare keys(groupfiles);

foreach $section ( @topgroups[0..14] ) {

   $files = $groupfiles{$section};
   $bytes = $groupbytes{$section};
   $pctfiles = sprintf("%8.2f", 100 * $groupfiles{$section} / $xferfiles);
   $pctbytes = sprintf("%8.2f", 100 * $groupbytes{$section} / $xferbytes);
   $fac = $fac{$section};
   write;
}

print "

Top 15 Most Popular Archive Sections By Interest Factor

                                                 ---- Percent  of ---- Interest
     Archive Section      Files Sent Bytes  Sent Files Sent Bytes Sent  Factor
------------------------- ---------- ----------- ---------- ---------- --------
";

format line5 =
@<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>> @>>>>>>>>>> @>>>>>>>   @>>>>>>>   @>>>>>>>
$section,                 $files,    $bytes,     $pctfiles, $pctbytes, $fac
.

$^ = top5;
$~ = line5;

@topgroups = sort faccompare keys(groupfiles);

foreach $section ( @topgroups[0..14] ) {

   $files = $groupfiles{$section};
   $bytes = $groupbytes{$section};
   $pctfiles = sprintf("%8.2f", 100 * $groupfiles{$section} / $xferfiles);
   $pctbytes = sprintf("%8.2f", 100 * $groupbytes{$section} / $xferbytes);
   $fac = $fac{$section};
   write;
}

print "

Bottom 15 Least Popular Archive Sections By Interest Factor

                                                 ---- Percent  of ---- Interest
     Archive Section      Files Sent Bytes  Sent Files Sent Bytes Sent  Factor
------------------------- ---------- ----------- ---------- ---------- --------
";

foreach $section ( @topgroups[$#topgroups-14..$#topgroups] ) {

   $files = $groupfiles{$section};
   $bytes = $groupbytes{$section};
   $pctfiles = sprintf("%8.2f", 100 * $groupfiles{$section} / $xferfiles);
   $pctbytes = sprintf("%8.2f", 100 * $groupbytes{$section} / $xferbytes);
   $fac = $fac{$section};
   write;
}

dbmclose(USAGE);

# print "Total Transfer Amount By System\n\n";
# print "                                  Number Of   Number of   Average\n";
# print "     System Name or Address       Files Sent  Bytes Sent  Xmit Rate\n";
# print "--------------------------------  ----------  ----------  ---------\n";
# 
# $lines = 58;
# 
# foreach $sys ( sort sysaddrcompare keys(systemfiles) ) {
# 
#  if ($systemsecs{$sys} == 0) { $systemsecs{$sys} = 1; }
# 
#  printf("%-32s  %10d  %10.0f  %5d cps\n", $sys, $systemfiles{$sys},
#         $systembytes{$sys}, $systembytes{$sys} / $systemsecs{$sys});
# 
#  if ($lines-- == 0) {
#     $lines = 58;
#     print "\n";
# 
#     print "Total Transfer Amount By System\n\n";
#     print "                                  Number Of   Number of   Average\n";
#     print "     System Name or Address       Files Sent  Bytes Sent  Xmit Rate\n";
#     print "--------------------------------  ----------  ----------  ---------\n";
# 
#  }
# }

exit(0);

sub datecompare {

   $date1  = substr($a, 11, 4) * 4800;
   $date2  = substr($b, 11, 4) * 4800;
   $date1 += index("JanFebMarAprMayJunJulAugSepOctNovDec",substr($a, 4, 3))*400;
   $date2 += index("JanFebMarAprMayJunJulAugSepOctNovDec",substr($b, 4, 3))*400;
   $date1 += substr($a, 8, 2);
   $date2 += substr($b, 8, 2);
   $date1 - $date2;

}

sub domnamcompare {

   $sdiff = length($a) - length($b);
   ($sdiff < 0) ? -1 : ($sdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;

}

sub bytecompare {

   $bdiff = $groupbytes{$b} - $groupbytes{$a};
   ($bdiff < 0) ? -1 : ($bdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;

}

sub faccompare {

   $fdiff = $fac{$b} - $fac{$a};
   ($fdiff < 0) ? -1 : ($fdiff > 0) ? 1 : ($a lt $b) ? -1 : ($a gt $b) ? 1 : 0;

}

---

From: [email-masked] (Bill Campbell)
Date: Tue, 13 Sep 1994 07:41:07 -0700 (PDT)

> Anyone have a copy they can mail me? Thanks.
Here's a quickie that I put together.

Bill
--
INTERNET:  [email-masked]   Bill Campbell; Celestial Software
UUCP:              camco!bill   8545 SE 68th Street
FAX:           (206) 232-9186   Mercer Island, WA 98040; (206) 947-5591

"The strongest reason for the people to retain the right to keep and
 bear arms is, as a last resort, to protect themselves against tyranny
 in government." --1 Thomas Jefferson Papers, 334 (C.J.Boyd, Ed.,1950)

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  ftpstats.pl
# Wrapped by bill@camco1 on Tue Sep 13 07:40:53 1994
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'ftpstats.pl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ftpstats.pl'\"
else
echo shar: Extracting \"'ftpstats.pl'\" \(3939 characters\)
sed "s/^X//" >'ftpstats.pl' <<'END_OF_FILE'
X:
X#!/usr/local/bin/perl
Xeval ' exec /usr/local/bin/perl $0 "$@" '
X	if $running_under_some_shell;
X	shift if(join("", @ARGV) eq ""); # Xenix Kludge
X
X# $Header: /u/usr/cvs/lbin/getopt.perl,v 1.6 92/10/26 18:05:37 bill Exp $
X# $Date: 92/10/26 18:05:37 $
X# @(#) $Id: getopt.perl,v 1.6 92/10/26 18:05:37 bill Exp $
X# $Log:	getopt.perl,v $
X
X( $progname = $0 ) =~ s!.*/!!; # save this very early
X
Xdo "/usr/bin/csspath.perl" unless $ENV{'USR_BIN_CSSPATH'};
X
X$USAGE = "
X#
X#   Usage: $progname [-v] [-e var=value]
X#
X# Options   Argument    Description
X#   -s                  Print only totals.
X#   -v                  Verbose
X#
X";
X
Xsub usage {
X	die join("\n",@_) .
X	"\n$USAGE\n";
X}
X
Xdo "getopts.pl";
X
X&usage("Invalid Option") unless do Getopts("e:sv");
X
Xforeach (@opt_e) {
X	($var, $value) = split('=', $_);
X	$ENV{$var} = $value;
X}
X$verbose = '-v' if $opt_v;
X$suffix = $$ unless $opt_v;
X
Xsub un_taint {
X	local($PATH) = $ENV{'PATH'};
X	$ENV{'PATH'} = $PATH;
X	$< = $>;	# make it ignore taintedness
X	$( = $);	# gids
X}
X# &un_taint();	# make it ignore taintedness
X
X$\ = "\n";	# use newlines as separators.
Xrequire 'getdate.pl';
Xrequire 'd2s.pl';
Xpush(@ARGV, "/usr/adm/xferlog") unless @ARGV;
Xshift if $ARGV[0] eq '-';
X
Xwhile(<>) {
X	(
X		$dow, $mon, $day, $time, $year,
X		$filler,
X		$site,
X		$bytes,
X		$file,
X		$type,
X		$filler,
X		$filler,
X		$filler,
X		$login,
X		$ftp,
X		$filler,
X		$filler
X	) = split(' ');
X	# $ctime = &getdate("$dow $mon $day $time $year");
X	print STDERR "$ctime $site, $bytes, $file" if $verbose;
X	$count{$file}++;
X	$size{$file} += $bytes;
X	$size += $bytes;
X	$count++;
X	$site_bytes{$site} += $bytes;
X	$site_files{$site}++;
X	$login_bytes{$login} += $bytes;
X	$login_files{$login}++;
X}
X$sort_opts = '+1rn +0';
Xselect(STDOUT); $| = 1;
Xif ($opt_s) {
X	print join("\t", $count, &i2s($size));
X}
Xelse {
X		printf "%-61s%5s%12s\n", 'file', 'times', 'size';
X		open (OUTPUT, "| sort $sort_opts");
X		select(OUTPUT);
X		for (keys %count) {
X			printf OUTPUT ("%-61s%5d %12s\n", $_, $count{$_}, &i2s($size{$_}));
X		}
X		close(OUTPUT);
X		select(STDOUT); $| = 1;
X	printf ("%-61s%5d %12s\n\n", 'TOTALS', $count, &i2s($size));
X	printf "%-61s%5s%12s\n", 'site', 'files', 'size';
X	open (OUTPUT, "| sort -fd");
X	select(OUTPUT);
X	for (keys %site_files) {
X		printf OUTPUT ("%-61s%5d %12s\n",
X			$_, $site_files{$_}, &i2s($site_bytes{$_}));
X	}
X	close(OUTPUT);
X	select(STDOUT);
X	printf ("%-61s%5d %12s\n\n", 'TOTALS', $count, &i2s($size));
X	select(STDOUT); $| = 1;
X	printf "%-61s%5s%12s\n", 'login', 'files', 'size';
X	open (OUTPUT, "| sort -fd");
X	select(OUTPUT);
X	for (keys %login_files) {
X		printf OUTPUT ("%-61s%5d %12s\n",
X			$_, $login_files{$_}, &i2s($login_bytes{$_}));
X	}
X	close(OUTPUT);
X	select(STDOUT);
X	printf ("%-61s%5d %12s\n\n", 'TOTALS', $count, &i2s($size));
X}
X__END__
XFri Nov 19 20:58:30 1993 76 netcom3.netcom.com 447226 /pub/sco-ports/xnx/gzip124.tar.Z b _ o a [email-masked] ftp 0 *
XFri Nov 19 21:01:54 1993 28 netcom3.netcom.com 157887 /pub/sco-ports/xnx/smail2.5.tar.gz b _ o a [email-masked] ftp 0 *
XFri Nov 19 23:41:14 1993 227 netcom2.netcom.com 1356511 /pub/sco-ports/xnx/cnews-pe.tar.gz b _ o a [email-masked] ftp 0 *
XFri Nov 19 23:42:39 1993 83 netcom2.netcom.com 508818 /pub/sco-ports/xnx/gtar-1.11.2.tar.gz b _ o a [email-masked] ftp 0 *
XFri Nov 19 23:43:27 1993 47 netcom2.netcom.com 289812 /pub/sco-ports/xnx/utree-3.03b-um.tar.gz b _ o a [email-masked] ftp 0 *
XFri Nov 19 23:49:41 1993 318 netcom2.netcom.com 1955456 /pub/sco-ports/xnx/perl4.0.36.tar.gz b _ o a [email-masked] ftp 0 *
XFri Nov 19 23:50:38 1993 56 netcom2.netcom.com 342633 /pub/sco-ports/xnx/uniperl-1.0.tar.gz b _ o a [email-masked] ftp 0 *
XSat Nov 20 04:14:27 1993 1 solair1.inter.NL.net 954 /README a _ o a [email-masked] ftp 0 *
XSat Nov 20 04:15:15 1993 1 solair1.inter.NL.net 416 /pub/README a _ o a [email-masked] ftp 0 *
XSat Nov 20 05:14:21 1993 401 access.digex.net 2481729 /pub/gnu/sco-ports/unix/libg++-2.4.tar.gz b _ o a arctic@ ftp 0 *
END_OF_FILE
if test 3939 -ne `wc -c <'ftpstats.pl'`; then
    echo shar: \"'ftpstats.pl'\" unpacked with wrong size!
fi
chmod +x 'ftpstats.pl'
# end of 'ftpstats.pl'
fi
echo shar: End of shell archive.
exit 0

---

From: Mike Trest <[email-masked]>
Date: Tue, 13 Sep 1994 07:16:35 -0700 (PDT)

> i.e. preceded with a dot (.something).

There are two ways:  (a) Modify the flags passed to "ls"
by wu-ftp or (b) modify the ls command.

Modification of ls was easiest for me.  
I simply commented out the "a" flag logic.

====================================================
Mike Trest                      [email-masked]
Senior Engineer                 Voice: 619 457 2111
VisiCom Laboratories            Fax:   619 457 0888
10052 Mesa Ridge Court          San Diego, CA 92121
====================================================

---

From: "Michael J. Corrigan" <[email-masked]>
Date: Tue, 13 Sep 1994 08:04:57 -0700

I received your mail.
I am on vacation until Monday, Sep 19.
I will respond then.
Send mail to [email-masked] if you need immediate help.
-- 

-mike

---

From: JARLE MARTINSEN +41 22 730 5949 <[email-masked]>
Date: Wed, 14 Sep 1994 14:59:51 +0100 (CET)

Still having problems with ls and dir within 
the wu-ftpd - actually the more I look the more
confused I get....:-)

Here goes....

Machine: DEC Alpha running OSF/1 v2.0

Me: 	Moderate to low UNIX experiance, and no c programming
	knowledge at all...

Generell:	wu-ftpd works, i.e. I can log on as a user, put, get,
	ls and dir works.... 
	wu-ftpd is started from a shell (ref. in inetd.conf)
		chroot /u /usr/sbin/ftpd 
	All files/directories to run ftp is setup under /u (new
	root). 

Want: 	to avoid listing of all UNIX hidden files, i.e. .filename

For ls:	I removed the ls executable....but still the ls works from
	wu-ftpd, indicating that the ls is an internal function to
	wu-ftpd.  
	What/where to change to suppress the ls -A listing??
	(I really want to hide those .file files)

For dir:	I modified all references of "ls -lA" in  ftpd.c, to "ls -lF"
	(then build osf, then copy executable to proper location)
	 But no....no change.  What am I missing....

For dir(2)	Then I made a shell (called ls) to call instead of the ls 
	executable....

		#!/bin/sh
		echo "$1"
		/bin/ls.org "$1"

	(chmod +x)
	(/bin/sh is actuallu /u/bin/sh)
	But this script is not even executed.  I.e. dir from wu-ftp
	gives no listing at all.  Looks like the wu-ftpd will not run
	a shell script....or I'm missing something (again).

Any help, pointers, guidense is appricated.

Best Regards,
/jarle

Jarle Martinsen