+/*
+ * Get multiple files.
+ */
+mget(argc, argv)
+ char *argv[];
+{
+ char temp[16], *dst, dstpath[MAXPATHLEN], buf[MAXPATHLEN];
+ FILE *ftemp;
+ int madedir = 0, oldverbose;
+ struct stat stb;
+
+ if (!connected) {
+ printf("Not connected.\n");
+ return;
+ }
+ if (argc == 2)
+ argc++, argv[2] = argv[1];
+ if (argc < 2) {
+ strcat(line, " ");
+ printf("(remote-directory) ");
+ gets(&line[strlen(line)]);
+ makeargv();
+ argc = margc;
+ argv = margv;
+ }
+ if (argc < 2) {
+usage:
+ printf("%s remote-directory [ local-directory ], or\n",
+ argv[0]);
+ printf("%s remote-files local-directory\n", argv[0]);
+ return;
+ }
+ if (argc < 3) {
+ strcat(line, " ");
+ printf("(local-directory) ");
+ gets(&line[strlen(line)]);
+ makeargv();
+ argc = margc;
+ argv = margv;
+ }
+ if (argc < 3)
+ goto usage;
+ dst = argv[argc - 1];
+ if (!globulize(&dst))
+ return;
+ /*
+ * If destination doesn't exist,
+ * try and create it.
+ */
+ if (stat(dst, &stb) < 0) {
+ if (mkdir(dst, 0777) < 0) {
+ perror(dst);
+ return;
+ }
+ madedir++;
+ } else {
+ if ((stb.st_mode & S_IFMT) != S_IFDIR) {
+ printf("%s: not a directory\n", dst);
+ return;
+ }
+ }
+ /*
+ * Multiple files, just get each one without an nlst.
+ */
+ if (argc > 3) {
+ int i;
+
+ for (i = 1; i < argc - 1; i++)
+ recvrequest("RETR",
+ sprintf(dstpath, "%s/%s", dst, argv[i]), argv[i]);
+ return;
+ }
+ /*
+ * Get a directory full of files. Perform an
+ * nlst to find the file names, then retrieve
+ * each individually. If prompting is on, ask
+ * before grabbing each file.
+ */
+ strcpy(temp, "/tmp/ftpXXXXXX");
+ mktemp(temp);
+ oldverbose = verbose, verbose = 0;
+ recvrequest("NLST", temp, argv[1]);
+ verbose = oldverbose;
+ ftemp = fopen(temp, "r");
+ unlink(temp);
+ if (ftemp == NULL) {
+ printf("can't find list of remote files, oops\n");
+ if (madedir)
+ (void) rmdir(dst);
+ return;
+ }
+ while (fgets(buf, sizeof (buf), ftemp) != NULL) {
+ char *cp = index(buf, '\n');
+
+ if (cp)
+ *cp = '\0';
+ if (skip(argv[0], buf))
+ continue;
+ recvrequest("RETR", sprintf(dstpath, "%s/%s", dst, buf), buf);
+ }
+ fclose(ftemp);
+}
+