Investigate why downloads always freeze when I call ftpget. Trace it to
a refactor leaving two REST and zero RETR. Branch wget to xexec ftpget
given an ftp url. Rename the output flag -O like in other wgets. Add
mock wget --no-check-certificate and gzip -n to satisfy pkgsrc. Ifdef
the version output in wget because the nonexistent constant fails single
builds and mkroot.
From 6f47711ada5b1c43d7e518a06dd77516763e163e Mon Sep 17 00:00:00 2001
From: Denys Nykula <[email protected]>
Date: Mon, 23 Sep 2019 05:15:02 +0300
Subject: [PATCH] Fix ftpget download, call from wget, noop gzip -n.

Investigate why downloads always freeze when I call ftpget. Trace it to
a refactor leaving two REST and zero RETR. Branch wget to xexec ftpget
given an ftp url. Rename the output flag -O like in other wgets. Add
mock wget --no-check-certificate and gzip -n to satisfy pkgsrc. Ifdef
the version output in wget because the nonexistent constant fails single
builds and mkroot.
---
 toys/lsb/gzip.c     |  2 +-
 toys/net/ftpget.c   |  2 +-
 toys/pending/wget.c | 27 ++++++++++++++++-----------
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/toys/lsb/gzip.c b/toys/lsb/gzip.c
index 0fa9b7e1..3038495e 100644
--- a/toys/lsb/gzip.c
+++ b/toys/lsb/gzip.c
@@ -8,7 +8,7 @@
  * todo: qtv --rsyncable
 
 // gzip.net version allows all options for all commands.
-USE_GZIP(NEWTOY(gzip,     "cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
+USE_GZIP(NEWTOY(gzip,    "ncdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
 USE_GUNZIP(NEWTOY(gunzip, "cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
 USE_ZCAT(NEWTOY(zcat,     "cdfk123456789[-123456789]", TOYFLAG_USR|TOYFLAG_BIN))
 
diff --git a/toys/net/ftpget.c b/toys/net/ftpget.c
index 05c53509..27ea6db6 100644
--- a/toys/net/ftpget.c
+++ b/toys/net/ftpget.c
@@ -166,7 +166,7 @@ void ftpget_main(void)
       lenl = fdlength(ii);
     }
     if (get) {
-      cmd = "REST";
+      cmd = "RETR";
       if (toys.optflags&FLAG_l) cmd = "LIST";
       if (toys.optflags&FLAG_L) cmd = "NLST";
       if (cnt) {
diff --git a/toys/pending/wget.c b/toys/pending/wget.c
index ced51d9c..eb496da2 100644
--- a/toys/pending/wget.c
+++ b/toys/pending/wget.c
@@ -3,19 +3,19 @@
  * Copyright 2016 Lipi C.H. Lee <[email protected]>
  *
 
-USE_WGET(NEWTOY(wget, "f:", TOYFLAG_USR|TOYFLAG_BIN))
+USE_WGET(NEWTOY(wget, "(no-check-certificate)O:", TOYFLAG_USR|TOYFLAG_BIN))
 
 config WGET
   bool "wget"
   default n
   help
-    usage: wget -f filename URL
-    -f filename: specify the filename to be saved
-    URL: HTTP uniform resource location and only HTTP, not HTTPS
+    usage: wget -O filename URL
+    -O filename: specify output filename
+    URL: uniform resource location, FTP/HTTP only, not HTTPS
 
     examples:
-      wget -f index.html http://www.example.com
-      wget -f sample.jpg http://www.example.com:8080/sample.jpg
+      wget -O index.html http://www.example.com
+      wget -O sample.jpg ftp://ftp.example.com:21/sample.jpg
 */
 
 #define FOR_wget
@@ -55,8 +55,10 @@ static unsigned get_port(const char *url, char *port, unsigned url_i) {
 // get http infos in URL
 static void get_info(const char *url, char* hostname, char *port, char *path) {
   unsigned i = 7, len;
+  char ftp = !strncmp(url, "ftp://";, 6);
 
-  if (strncmp(url, "http://";, i)) error_exit("only HTTP support");
+  if (ftp) i--;
+  else if (strncmp(url, "http://";, i)) error_exit("only FTP/HTTP support");
   len = get_hn(url+i, hostname);
   i += len;
 
@@ -72,6 +74,8 @@ static void get_info(const char *url, char* hostname, char *port, char *path) {
     if (strlen(url+i) < 1024) strcpy(path, url+i);
     else error_exit("too long path in URL");
   } else error_exit("wrong URL");
+
+  if (ftp) xexec((char *[]){"ftpget", hostname, TT.filename, path, 0});
 }
 
 // connect to any IPv4 or IPv6 server
@@ -131,10 +135,10 @@ void wget_main(void)
   FILE *fp;
   ssize_t len, body_len;
   char *body, *result, *rc, *r_str;
-  char ua[18] = "toybox wget/", ver[6], hostname[1024], port[6], path[1024];
+  char ua[18] = "toybox wget", ver[6], hostname[1024], port[6], path[1024];
 
   // TODO extract filename to be saved from URL
-  if (!(toys.optflags & FLAG_f)) help_exit("no filename");
+  if (!(toys.optflags & FLAG_O)) help_exit("no filename");
   if (fopen(TT.filename, "r")) error_exit("'%s' already exists", TT.filename);
 
   if(!toys.optargs[0]) help_exit("no URL");
@@ -145,8 +149,9 @@ void wget_main(void)
   // compose HTTP request
   sprintf(toybuf, "GET %s HTTP/1.1\r\n", path);
   mk_fld("Host", hostname);
-  strncpy(ver, TOYBOX_VERSION, 5);
-  strcat(ua, ver);
+#ifdef TOYBOX_VERSION
+  strcat(ua, "/"), strncpy(ver, TOYBOX_VERSION, 5), strcat(ua, ver);
+#endif
   mk_fld("User-Agent", ua); 
   mk_fld("Connection", "close");
   strcat(toybuf, "\r\n");
-- 
2.23.0

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to