[PATCH] smbclient download status bar

Nick Hay nickjhay at gmail.com
Sun Nov 20 02:39:33 GMT 2005


This quick hack prints a status bar when you download files via smbclient:

4515840 of 263783900 bytes read (1.7% done)

-- Nick Hay

--- source/client/client.c.orig 2005-11-20 14:14:09.000000000 +1300
+++ source/client/client.c      2005-11-20 15:26:14.000000000 +1300
@@ -790,6 +790,9 @@
                return 1;
        }

+       char statustext[256];
+       statustext[0] = 0;
+
        while (1) {
                int n = cli_read(targetcli, fnum, data, nread + start,
read_size);

@@ -803,7 +806,26 @@
                }

                nread += n;
+
+               // erase previous status text and print new
+               char *p = statustext;
+               while (*p != 0) {
+                       *p = '\b';
+                       p++;
+               }
+               x_fprintf(dbf, statustext);
+
+               snprintf(statustext, 256, "%i of %i bytes read (%2.1f%% done)",
+                                                       (int)nread,
(int)size, (double)nread*100/(int)size);
+               x_fprintf(dbf, "%s", statustext);
+               x_fflush(dbf);
+       }
+       char *p = statustext;
+       while (*p != 0) {
+               *p = '\b';
+               p++;
        }
+       x_fprintf(dbf, statustext);

        if (nread + start < size) {
                DEBUG (0, ("Short read when getting file %s. Only got
%ld bytes.\n",


More information about the samba-technical mailing list