+ if (ftpcmd(NULL, NULL, sfp) != 226)
+ bb_error_msg_and_die("ftp error: %s", sanitize_string(G.wget_buf + 4));
+ /* ftpcmd("QUIT", NULL, sfp); - why bother? */
+ }
+ fclose(sfp);
+
+ free(server.allocated);
+ free(target.allocated);
+ free(fname_out_alloc);
+ free(redirected_path);
+}
+
+int wget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int wget_main(int argc UNUSED_PARAM, char **argv)
+{
+#if ENABLE_FEATURE_WGET_LONG_OPTIONS
+ static const char wget_longopts[] ALIGN1 =
+ /* name, has_arg, val */
+ "continue\0" No_argument "c"
+//FIXME: -s isn't --spider, it's --save-headers!
+ "spider\0" No_argument "s"
+ "quiet\0" No_argument "q"
+ "output-document\0" Required_argument "O"
+ "directory-prefix\0" Required_argument "P"
+ "proxy\0" Required_argument "Y"
+ "user-agent\0" Required_argument "U"
+#if ENABLE_FEATURE_WGET_TIMEOUT
+ "timeout\0" Required_argument "T"
+#endif
+ /* Ignored: */
+ // "tries\0" Required_argument "t"
+ /* Ignored (we always use PASV): */
+ "passive-ftp\0" No_argument "\xff"
+ "header\0" Required_argument "\xfe"
+ "post-data\0" Required_argument "\xfd"
+ /* Ignored (we don't do ssl) */
+ "no-check-certificate\0" No_argument "\xfc"
+ /* Ignored (we don't support caching) */
+ "no-cache\0" No_argument "\xfb"
+ ;
+#endif
+
+#if ENABLE_FEATURE_WGET_LONG_OPTIONS
+ llist_t *headers_llist = NULL;
+#endif
+
+ INIT_G();
+
+ IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;)
+ G.proxy_flag = "on"; /* use proxies if env vars are set */
+ G.user_agent = "Wget"; /* "User-Agent" header field */
+
+#if ENABLE_FEATURE_WGET_LONG_OPTIONS
+ applet_long_options = wget_longopts;
+#endif
+ opt_complementary = "-1" IF_FEATURE_WGET_TIMEOUT(":T+") IF_FEATURE_WGET_LONG_OPTIONS(":\xfe::");
+ getopt32(argv, "csqO:P:Y:U:T:" /*ignored:*/ "t:",
+ &G.fname_out, &G.dir_prefix,
+ &G.proxy_flag, &G.user_agent,
+ IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL),
+ NULL /* -t RETRIES */
+ IF_FEATURE_WGET_LONG_OPTIONS(, &headers_llist)
+ IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_data)
+ );
+ argv += optind;
+
+#if ENABLE_FEATURE_WGET_LONG_OPTIONS
+ if (headers_llist) {
+ int size = 1;
+ char *cp;
+ llist_t *ll = headers_llist;
+ while (ll) {
+ size += strlen(ll->data) + 2;
+ ll = ll->link;
+ }
+ G.extra_headers = cp = xmalloc(size);
+ while (headers_llist) {
+ cp += sprintf(cp, "%s\r\n", (char*)llist_pop(&headers_llist));
+ }