Implement the -c option

This commit is contained in:
Dag-Erling Smørgrav 2000-06-29 10:32:56 +00:00
parent f685a909b5
commit a8369cd91b

View File

@ -50,6 +50,7 @@ int A_flag; /* -A: do not follow 302 redirects */
int a_flag; /* -a: auto retry */
size_t B_size; /* -B: buffer size */
int b_flag; /*! -b: workaround TCP bug */
char *c_dirname; /* -c: remote directory */
int d_flag; /* -d: direct connection */
int F_flag; /* -F: restart without checking mtime */
char *f_filename; /* -f: file to fetch */
@ -434,7 +435,7 @@ main(int argc, char *argv[])
int c, e, r;
while ((c = getopt(argc, argv,
"146AaB:bdFf:h:lHMmnPpo:qRrS:sT:tvw:")) != EOF)
"146AaB:bc:dFf:h:lHMmnPpo:qRrS:sT:tvw:")) != EOF)
switch (c) {
case '1':
once_flag = 1;
@ -459,6 +460,9 @@ main(int argc, char *argv[])
warnx("warning: the -b option is deprecated");
b_flag = 1;
break;
case 'c':
c_dirname = optarg;
break;
case 'd':
d_flag = 1;
break;
@ -532,7 +536,7 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
if (h_hostname || f_filename) {
if (h_hostname || f_filename || c_dirname) {
if (!h_hostname || !f_filename || argc) {
usage();
exit(EX_USAGE);
@ -540,7 +544,8 @@ main(int argc, char *argv[])
/* XXX this is a hack. */
if (strcspn(h_hostname, "@:/") != strlen(h_hostname))
errx(1, "invalid hostname");
if (asprintf(argv, "ftp://%s/%s", h_hostname, f_filename) == -1)
if (asprintf(argv, "ftp://%s/%s/%s", h_hostname,
c_dirname ? c_dirname : "", f_filename) == -1)
errx(1, strerror(ENOMEM));
argc++;
}