home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE0.TAR / ftp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-21  |  1.8 KB  |  59 lines

  1. /*
  2.  * ftp.c : Fetches a file by anonymous ftp.
  3.  *
  4.  * George Ferguson, ferguson@cs.rochester.edu, 21 Aug 1991.
  5.  *
  6.  * This is just an initial cut at providing the real kind of ftp
  7.  * services that we want. In particular, we will eventually be using
  8.  * Prospero for the transfers, rather than feeding commands to ftp.
  9.  * Also, it would be nice to be able to log in from xarchie as well
  10.  * as fetching files immediately. Also, we currently only fetch in
  11.  * binary (image) mode. Eventually there will be a panel for setting
  12.  * ftp options.
  13.  *
  14.  * Note that error messages form ftp go to stderr, and the return status
  15.  * signalled by pclose() is really inadequate. It is almost always 0,
  16.  * and so "file not found" errors go unnoticed but for the stderr message.
  17.  *
  18.  * This code contains definite Unix-isms. If if won't compile for you,
  19.  * you'll have to do without the ftp capability or hack the code
  20.  * yourself.
  21.  *
  22.  */
  23. #include <stdio.h>
  24. #include <pwd.h>
  25. extern char *getenv();
  26.  
  27. #define FTP_CMD "/usr/ucb/ftp -n"
  28.  
  29. void
  30. ftp(host,loc,file)
  31. char *host,*loc,*file;
  32. {
  33.     FILE *fp;
  34.     struct passwd *pwe;
  35.     char *username,hostname[64];
  36.     int status;
  37.  
  38.     if ((pwe=getpwuid(getuid())) != NULL)
  39.     username = pwe->pw_name;
  40.     else if ((username=getenv("USER")) == NULL)
  41.     username = "xarchie_user";
  42.     if (gethostname(hostname,sizeof(hostname)) < 0)
  43.     strcpy(hostname,"unknown_host");
  44.     if ((fp=popen(FTP_CMD,"w")) == NULL) {
  45.     alert0("Popen failed for ftp process");
  46.     return;
  47.     }
  48.     status2("Retrieving \"%.100s\" from %.100s",file,host);
  49.     fprintf(fp,"open %s\n",host);
  50.     fprintf(fp,"user anonymous %s@%s\n",username,hostname);
  51.     fprintf(fp,"binary\n");
  52.     fprintf(fp,"cd %s\n",loc);
  53.     fprintf(fp,"get %s\n",file);
  54.     status = pclose(fp) >> 8;
  55.     if (status)
  56.     alert0("Ftp returned error code %d",status);
  57.     status0("Ready");
  58. }
  59.