int ftpgetput_main(int argc, char **argv) { /* content-length of the file */ unsigned long opt; char *port = "ftp"; /* socket to ftp server */ FILE *control_stream; struct sockaddr_in s_in; /* continue a prev transfer (-c) */ ftp_host_info_t *server; int (*ftp_action)(ftp_host_info_t *, FILE *, const char *, char *) = NULL; /* Check to see if the command is ftpget or ftput */ #ifdef CONFIG_FTPPUT # ifdef CONFIG_FTPGET if (bb_applet_name[3] == 'p') { ftp_action = ftp_send; } # else ftp_action = ftp_send; # endif #endif #ifdef CONFIG_FTPGET # ifdef CONFIG_FTPPUT if (bb_applet_name[3] == 'g') { ftp_action = ftp_recieve; } # else ftp_action = ftp_recieve; # endif #endif /* Set default values */ server = xmalloc(sizeof(ftp_host_info_t)); server->user = "******"; server->password = "******"; verbose_flag = 0; /* * Decipher the command line */ bb_applet_long_options = ftpgetput_long_options; opt = bb_getopt_ulflags(argc, argv, "cvu:p:P:", &server->user, &server->password, &port); /* Process the non-option command line arguments */ if (argc - optind != 3) { bb_show_usage(); } if (opt & FTPGETPUT_OPT_CONTINUE) { do_continue = 1; } if (opt & FTPGETPUT_OPT_VERBOSE) { verbose_flag = 1; } /* We want to do exactly _one_ DNS lookup, since some * sites (i.e. ftp.us.debian.org) use round-robin DNS * and we want to connect to only one IP... */ server->s_in = &s_in; bb_lookup_host(&s_in, argv[optind]); s_in.sin_port = bb_lookup_port(port, "tcp", 21); if (verbose_flag) { printf("Connecting to %s[%s]:%d\n", argv[optind], inet_ntoa(s_in.sin_addr), ntohs(s_in.sin_port)); } /* Connect/Setup/Configure the FTP session */ control_stream = ftp_login(server); return(ftp_action(server, control_stream, argv[optind + 1], argv[optind + 2])); }
int ftpgetput_main(int argc, char **argv) { /* content-length of the file */ int option_index = -1; int opt; /* socket to ftp server */ FILE *control_stream; /* continue a prev transfer (-c) */ ftp_host_info_t *server; int (*ftp_action)(FILE *, const char *, const char *, char *) = NULL; struct option long_options[] = { {"username", 1, NULL, 'u'}, {"password", 1, NULL, 'p'}, {"port", 1, NULL, 'P'}, {"continue", 1, NULL, 'c'}, {"verbose", 0, NULL, 'v'}, {0, 0, 0, 0} }; #ifdef CONFIG_FTPPUT if (bb_applet_name[3] == 'p') { ftp_action = ftp_send; } #endif #ifdef CONFIG_FTPGET if (bb_applet_name[3] == 'g') { ftp_action = ftp_recieve; } #endif /* Set default values */ server = ftp_init(); verbose_flag = 0; /* * Decipher the command line */ while ((opt = getopt_long(argc, argv, "u:p:P:cv", long_options, &option_index)) != EOF) { switch(opt) { case 'c': do_continue = 1; break; case 'u': server->user = optarg; break; case 'p': server->password = optarg; break; case 'P': server->port = optarg; break; case 'v': verbose_flag = 1; break; default: bb_show_usage(); } } /* * Process the non-option command line arguments */ if (argc - optind != 3) { bb_show_usage(); } /* Connect/Setup/Configure the FTP session */ server->host = argv[optind]; control_stream = ftp_login(server); return(ftp_action(control_stream, argv[optind], argv[optind + 1], argv[optind + 2])); }