Lines Matching +full:data +full:- +full:rate +full:- +full:bps

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2000-2014 Dag-Erling Smørgrav
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55 static int A_flag; /* -A: do not follow 302 redirects */
56 static int a_flag; /* -a: auto retry */
57 static off_t B_size; /* -B: buffer size */
58 static int b_flag; /*! -b: workaround TCP bug */
59 static char *c_dirname; /* -c: remote directory */
60 static int d_flag; /* -d: direct connection */
61 static int F_flag; /* -F: restart without checking mtime */
62 static char *f_filename; /* -f: file to fetch */
63 static char *h_hostname; /* -h: host to fetch from */
64 static int i_flag; /* -i: specify file for mtime comparison */
66 static int l_flag; /* -l: link rather than copy file: URLs */
67 static int m_flag; /* -[Mm]: mirror mode */
68 static char *N_filename; /* -N: netrc file name */
69 static int n_flag; /* -n: do not preserve modification time */
70 static int o_flag; /* -o: specify output file */
74 static int once_flag; /* -1: stop at first successful file */
75 static int p_flag; /* -[Pp]: use passive FTP */
76 static int R_flag; /* -R: don't delete partial files */
77 static int r_flag; /* -r: restart previous transfer */
78 static off_t S_size; /* -S: require size to match */
79 static int s_flag; /* -s: show size, don't fetch */
80 static long T_secs; /* -T: transfer timeout in seconds */
81 static int t_flag; /*! -t: workaround TCP bug */
82 static int U_flag; /* -U: do not use high ports */
83 static int v_level = 1; /* -v: verbosity level */
87 static long w_secs; /* -w: retry delay */
88 static int family = PF_UNSPEC; /* -[46]: address family to use */
120 { "one-file", no_argument, NULL, '1' },
121 { "ipv4-only", no_argument, NULL, '4' },
122 { "ipv6-only", no_argument, NULL, '6' },
123 { "no-redirect", no_argument, NULL, 'A' },
125 { "buffer-size", required_argument, NULL, 'B' },
126 /* -c not mapped, since it's deprecated */
128 { "force-restart", no_argument, NULL, 'F' },
129 /* -f not mapped, since it's deprecated */
130 /* -h not mapped, since it's deprecated */
131 { "if-modified-since", required_argument, NULL, 'i' },
133 /* -M not mapped since it's the same as -m */
136 { "no-mtime", no_argument, NULL, 'n' },
138 /* -P not mapped since it's the same as -p */
141 { "keep-output", no_argument, NULL, 'R' },
143 { "require-size", required_argument, NULL, 'S' },
144 { "print-size", no_argument, NULL, 's' },
146 { "passive-portrange-default", no_argument, NULL, 'T' },
148 { "retry-delay", required_argument, NULL, 'w' },
151 { "bind-address", required_argument, NULL, OPTION_BIND_ADDRESS },
152 { "no-passive", no_argument, NULL, OPTION_NO_FTP_PASSIVE_MODE },
154 { "user-agent", required_argument, NULL, OPTION_HTTP_USER_AGENT },
155 { "no-proxy", required_argument, NULL, OPTION_NO_PROXY },
156 { "ca-cert", required_argument, NULL, OPTION_SSL_CA_CERT_FILE },
157 { "ca-path", required_argument, NULL, OPTION_SSL_CA_CERT_PATH },
161 { "no-sslv3", no_argument, NULL, OPTION_SSL_NO_SSL3 },
162 { "no-tlsv1", no_argument, NULL, OPTION_SSL_NO_TLS1 },
163 { "no-verify-hostname", no_argument, NULL, OPTION_SSL_NO_VERIFY_HOSTNAME },
164 { "no-verify-peer", no_argument, NULL, OPTION_SSL_NO_VERIFY_PEER },
230 elapsed = xs->last.tv_sec - xs->start.tv_sec; in stat_eta()
231 received = xs->rcvd - xs->offset; in stat_eta()
232 expected = xs->size - xs->rcvd; in stat_eta()
257 * Compute and display transfer rate
263 double delta, bps; in stat_bps() local
265 delta = ((double)xs->last.tv_sec + (xs->last.tv_usec / 1.e6)) in stat_bps()
266 - ((double)xs->last2.tv_sec + (xs->last2.tv_usec / 1.e6)); in stat_bps()
269 snprintf(str, strsz, "?? Bps"); in stat_bps()
271 bps = (xs->rcvd - xs->lastrcvd) / delta; in stat_bps()
272 stat_bytes(bytes, sizeof bytes, (off_t)bps); in stat_bps()
283 char bytes[16], bps[16], eta[16]; in stat_display() local
293 if (!force && now.tv_sec <= xs->last.tv_sec) in stat_display()
295 xs->last2 = xs->last; in stat_display()
296 xs->last = now; in stat_display()
298 fprintf(stderr, "\r%-46.46s", xs->name); in stat_display()
299 if (xs->rcvd >= xs->size) { in stat_display()
300 stat_bytes(bytes, sizeof bytes, xs->rcvd); in stat_display()
301 setproctitle("%s [%s]", xs->name, bytes); in stat_display()
304 stat_bytes(bytes, sizeof bytes, xs->size); in stat_display()
305 setproctitle("%s [%d%% of %s]", xs->name, in stat_display()
306 (int)((100.0 * xs->rcvd) / xs->size), in stat_display()
309 (int)((100.0 * xs->rcvd) / xs->size), in stat_display()
313 xs->lastrcvd = xs->offset; in stat_display()
314 xs->last2 = xs->start; in stat_display()
316 stat_bps(bps, sizeof bps, xs); in stat_display()
317 fprintf(stderr, " %s", bps); in stat_display()
318 if ((xs->size > 0 && xs->rcvd > 0 && in stat_display()
319 xs->last.tv_sec >= xs->start.tv_sec + 3) || in stat_display()
324 xs->lastrcvd = xs->rcvd; in stat_display()
335 snprintf(xs->name, sizeof xs->name, "%s", name); in stat_start()
336 gettimeofday(&xs->start, NULL); in stat_start()
337 xs->last2 = xs->last = xs->start; in stat_start()
338 xs->size = size; in stat_start()
339 xs->offset = offset; in stat_start()
340 xs->rcvd = offset; in stat_start()
341 xs->lastrcvd = offset; in stat_start()
345 fprintf(stderr, "%-46s", xs->name); in stat_start()
355 xs->rcvd = rcvd; in stat_update()
366 char bytes[16], bps[16], eta[16]; in stat_end() local
368 gettimeofday(&xs->last, NULL); in stat_end()
373 stat_bytes(bytes, sizeof bytes, xs->rcvd); in stat_end()
374 stat_bps(bps, sizeof bps, xs); in stat_end()
376 fprintf(stderr, " %s %s %s\n", bytes, bps, eta); in stat_end()
391 URL->scheme, URL->host, URL->port); in query_auth()
394 if (fgets(URL->user, sizeof URL->user, stdin) == NULL) in query_auth()
395 return (-1); in query_auth()
396 for (i = strlen(URL->user); i >= 0; --i) in query_auth()
397 if (URL->user[i] == '\r' || URL->user[i] == '\n') in query_auth()
398 URL->user[i] = '\0'; in query_auth()
406 nopwd = (fgets(URL->pwd, sizeof URL->pwd, stdin) == NULL); in query_auth()
410 nopwd = (fgets(URL->pwd, sizeof URL->pwd, stdin) == NULL); in query_auth()
413 return (-1); in query_auth()
414 for (i = strlen(URL->pwd); i >= 0; --i) in query_auth()
415 if (URL->pwd[i] == '\r' || URL->pwd[i] == '\n') in query_auth()
416 URL->pwd[i] = '\0'; in query_auth()
466 if (!*url->scheme) { in fetch()
467 if (!*url->host) in fetch()
468 strcpy(url->scheme, SCHEME_FILE); in fetch()
469 else if (strncasecmp(url->host, "ftp.", 4) == 0) in fetch()
470 strcpy(url->scheme, SCHEME_FTP); in fetch()
471 else if (strncasecmp(url->host, "www.", 4) == 0) in fetch()
472 strcpy(url->scheme, SCHEME_HTTP); in fetch()
476 *is_http = strncmp(url->scheme, "http", 4) == 0; in fetch()
489 if (strcmp(url->scheme, SCHEME_FTP) == 0) { in fetch()
500 if (strcmp(url->scheme, SCHEME_HTTP) == 0 || in fetch()
501 strcmp(url->scheme, SCHEME_HTTPS) == 0) { in fetch()
512 url->ims_time = sb.st_mtime; in fetch()
529 if (r == -1) { in fetch()
533 if (us.size == -1) in fetch()
544 * If the -r flag was specified, we have to compare the local in fetch()
556 sb.st_size = -1; in fetch()
560 url->offset = sb.st_size; in fetch()
561 } else if (r == -1 || !S_ISREG(sb.st_mode)) { in fetch()
567 sb.st_size = -1; in fetch()
569 if (r == -1 && errno != ENOENT) { in fetch()
602 if (us.size == -1) { in fetch()
612 if (l_flag && strcmp(url->scheme, "file") == 0 && !o_stdout) { in fetch()
613 if (symlink(url->doc, path) == -1) { in fetch()
620 if (us.size == -1 && !o_stdout && v_level > 0) in fetch()
623 if (sb.st_size != -1) in fetch()
626 if (us.size != -1) in fetch()
635 } else if (r_flag && sb.st_size != -1) { in fetch()
646 } else if (url->offset > sb.st_size) { in fetch()
652 } else if (us.size != -1) { in fetch()
669 if (fstat(fileno(of), &nsb) == -1) { in fetch()
685 if (of != NULL && fseeko(of, url->offset, SEEK_SET) != 0) { in fetch()
691 } else if (m_flag && sb.st_size != -1) { in fetch()
704 if (url->offset > 0) { in fetch()
707 * some reason gave up - so we have to restart in fetch()
710 url->offset = 0; in fetch()
720 if (sb.st_size != -1 && S_ISREG(sb.st_mode)) { in fetch()
728 (int)(slash - path), path, slash); in fetch()
730 if (mkstemps(tmppath, strlen(slash) + 1) == -1) { in fetch()
746 count = url->offset; in fetch()
753 /* suck in the data */ in fetch()
757 if (us.size != -1 && us.size - count < B_size && in fetch()
758 us.size - count >= 0) in fetch()
759 size = us.size - count; in fetch()
778 for (ptr = buf; readcnt > 0; ptr += wr, readcnt -= wr) in fetch()
796 * set the mtime in case the file is not removed (-r or -R) and in fetch()
802 (stat(path, &sb) != -1) && sb.st_mode & S_IFREG) { in fetch()
836 if (us.size != -1 && count < us.size) { in fetch()
853 if (sigalrm && us.size == -1) { in fetch()
860 if (tmppath != NULL && rename(tmppath, path) == -1) { in fetch()
867 if (stat(path, &sb) != -1 && (sb.st_mode & S_IFREG)) in fetch()
869 if (R_flag && tmppath != NULL && sb.st_size == -1) in fetch()
872 r = -1; in fetch()
890 "usage: fetch [-146AadFlMmnPpqRrsUv] [-B bytes] [--bind-address=host]", in usage()
891 " [--ca-cert=file] [--ca-path=dir] [--cert=file] [--crl=file]", in usage()
892 " [-i file] [--key=file] [-N file] [--no-passive] [--no-proxy=list]", in usage()
893 " [--no-sslv3] [--no-tlsv1] [--no-verify-hostname] [--no-verify-peer]", in usage()
894 " [-o file] [--referer=URL] [-S bytes] [-T seconds]", in usage()
895 " [--user-agent=agent-string] [-w seconds] URL ...", in usage()
896 " fetch [-146AadFlMmnPpqRrsUv] [-B bytes] [--bind-address=host]", in usage()
897 " [--ca-cert=file] [--ca-path=dir] [--cert=file] [--crl=file]", in usage()
898 " [-i file] [--key=file] [-N file] [--no-passive] [--no-proxy=list]", in usage()
899 " [--no-sslv3] [--no-tlsv1] [--no-verify-hostname] [--no-verify-peer]", in usage()
900 " [-o file] [--referer=URL] [-S bytes] [-T seconds]", in usage()
901 " [--user-agent=agent-string] [-w seconds] -h host -f file [-c dir]"); in usage()
920 longopts, NULL)) != -1) in main()
943 warnx("warning: the -b option is deprecated"); in main()
959 warnx("the -H option is now implicit, " in main()
960 "use -U to disable"); in main()
979 errx(1, "the -m and -r flags " in main()
1001 errx(1, "the -m and -r flags " in main()
1020 warnx("warning: the -t option is deprecated"); in main()
1081 argc -= optind; in main()
1093 c_dirname ? c_dirname : "", f_filename) == -1) in main()
1136 if (strcmp(o_filename, "-") == 0) { in main()
1138 } else if (stat(o_filename, &sb) == -1) { in main()
1164 if (setenv("NETRC", N_filename, 1) == -1) in main()
1180 e = fetch(*argv, "-", &is_http); in main()
1223 argc--, argv++; in main()