Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Nov 2001 22:25:26 +0100
From:      Jerry Eriksson <eip@coredump.cx>
To:        freebsd-net@freebsd.org
Subject:   ftp(1) patch
Message-ID:  <20011111222526.A895@coredump.cx>

next in thread | raw e-mail | index | archive | help

--PNTmBPCT7hxwcZjr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Here's a quick patch for ftp(1) to show
the transfer rate while downloading files.

/ Jerry


--PNTmBPCT7hxwcZjr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ftp.diff"

--- /usr/src/usr.bin/ftp/util.c	Fri Apr  6 13:34:03 2001
+++ ftp/util.c	Fri Nov  9 18:07:49 2001
@@ -602,9 +602,9 @@ progressmeter(flag)
 	static struct timeval lastupdate;
 	static off_t lastsize;
 	struct timeval now, td, wait;
-	off_t cursize, abbrevsize;
+	off_t cursize, abbrevsize, bs;
 	double elapsed;
-	int ratio, barlength, i, len;
+	int ratio, barlength, i, len, meg;
 	off_t remaining;
 	char buf[256];
 
@@ -625,7 +625,7 @@ progressmeter(flag)
 	ratio = MIN(ratio, 100);
 	len += snprintf(buf + len, sizeof(buf) - len, "\r%3d%% ", ratio);
 
-	barlength = ttywidth - 30;
+	barlength = ttywidth - 43;
 	if (barlength > 0) {
 		i = barlength * ratio / 100;
 		len += snprintf(buf + len, sizeof(buf) - len,
@@ -668,6 +668,12 @@ progressmeter(flag)
 	} else {
 		remaining = 
 		    ((filesize - restart_point) / (bytes / elapsed) - elapsed);
+		bs = bytes / (elapsed == 0.0 ? 1 : elapsed);
+		meg = 0;
+		if (bs > (1024 * 1024))
+			    meg = 1;
+		len += snprintf(buf + len, sizeof(buf) - len,
+				" (%.2f %sB/s)",  bs / (1024.0 * (meg ? 1024.0 : 1.0)), meg ? "M" : "K");
 		if (remaining >= 100 * SECSPERHOUR)
 			len += snprintf(buf + len, sizeof(buf) - len,
 			    "   --:-- ETA");

--PNTmBPCT7hxwcZjr--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011111222526.A895>