home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE2.TAR / ftp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-12  |  2.0 KB  |  65 lines

  1. /*
  2.  * ftp.c : Fetches a file by anonymous ftp.
  3.  *
  4.  * George Ferguson, ferguson@cs.rochester.edu, 12 Nov 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.
  11.  *
  12.  * The Settings panel now allows the transfer type and local directory
  13.  * to be set for ftp transfers. We're getting there...
  14.  *
  15.  * Note that error messages form ftp go to stderr, and the return status
  16.  * signalled by pclose() is really inadequate. It is almost always 0,
  17.  * and so "file not found" errors go unnoticed but for the stderr message.
  18.  *
  19.  * This code contains definite Unix-isms. If if won't compile for you,
  20.  * you'll have to do without the ftp capability or hack the code
  21.  * yourself.
  22.  *
  23.  */
  24. #include <stdio.h>
  25. #include <pwd.h>
  26. #include <X11/Intrinsic.h>
  27. #include "appres.h"
  28. extern char *getenv();
  29.  
  30. #define FTP_CMD "/usr/ucb/ftp -n"
  31.  
  32. void
  33. ftp(host,loc,file)
  34. char *host,*loc,*file;
  35. {
  36.     FILE *fp;
  37.     struct passwd *pwe;
  38.     char *username,hostname[64];
  39.     int status;
  40.  
  41.     if ((pwe=getpwuid(getuid())) != NULL)
  42.     username = pwe->pw_name;
  43.     else if ((username=getenv("USER")) == NULL)
  44.     username = "xarchie_user";
  45.     if (gethostname(hostname,sizeof(hostname)) < 0)
  46.     strcpy(hostname,"unknown_host");
  47.     if ((fp=popen(FTP_CMD,"w")) == NULL) {
  48.     alert0("Popen failed for ftp process");
  49.     return;
  50.     }
  51.     status2("Retrieving \"%.100s\" from %.100s",file,host);
  52.     fprintf(fp,"open %s\n",host);
  53.     fprintf(fp,"user anonymous %s@%s\n",username,hostname);
  54.     if (*(appResources.ftpType))
  55.     fprintf(fp,"type %s\n",appResources.ftpType);
  56.     if (*(appResources.ftpDir))
  57.     fprintf(fp,"lcd %s\n",appResources.ftpDir);
  58.     fprintf(fp,"cd %s\n",loc);
  59.     fprintf(fp,"get %s\n",file);
  60.     status = pclose(fp) >> 8;
  61.     if (status)
  62.     alert1("Ftp returned error code %d",status);
  63.     status0("Ready");
  64. }
  65.