From owner-freebsd-net Sun Nov 11 13:23:47 2001 Delivered-To: freebsd-net@freebsd.org Received: from procyon.mine.nu (h119n2fls33o883.telia.com [217.208.62.119]) by hub.freebsd.org (Postfix) with ESMTP id 13F7937B418 for ; Sun, 11 Nov 2001 13:23:44 -0800 (PST) Received: (from eip@localhost) by procyon.mine.nu (8.11.3/8.11.3) id fABLPR600960 for freebsd-net@freebsd.org; Sun, 11 Nov 2001 22:25:27 +0100 (CET) (envelope-from eip) Date: Sun, 11 Nov 2001 22:25:26 +0100 From: Jerry Eriksson To: freebsd-net@freebsd.org Subject: ftp(1) patch Message-ID: <20011111222526.A895@coredump.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="PNTmBPCT7hxwcZjr" Content-Disposition: inline User-Agent: Mutt/1.3.22.1i Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org --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