1. File transfer, client->server; 2. Problem with popen in CGI script.
decoux@moulon.inra.fr (ts)
Errors-To: listmaster@www0.cern.ch
Date: Sun, 1 May 1994 11:49:51 +0200
Errors-To: listmaster@www0.cern.ch
Message-id: <9405010946.AA03925@moulon.moulon.inra.fr>
Errors-To: listmaster@www0.cern.ch
Reply-To: decoux@moulon.inra.fr
Originator: www-talk@info.cern.ch
Sender: www-talk@www0.cern.ch
Precedence: bulk
From: decoux@moulon.inra.fr (ts)
To: Multiple recipients of list <www-talk@www0.cern.ch>
Subject: 1. File transfer, client->server; 2. Problem with popen in CGI script.
X-Listprocessor-Version: 6.0c -- ListProcessor by Anastasios Kotsikonas
Hello,
I don't run NCSA http, but CERN httpd and I don't know if there is a
difference between this 2 servers.
The following C source actually work well, with CERN httpd 2.18 and Mosaic
2.4, on a Sun OS 4.1.3
------------------------------------------------------------
#include <stdio.h>
char *machinename = "moulon";
char *username = "ftp";
char *password = "decoux@moulon.inra.fr";
char *directory = "/pub/www-acedb";
char *filename = "README";
main()
{
char *ftpcom;
FILE *fp;
printf("Content-type: text/html\r\n\r\n");
printf("<H1>FTP request:</H1>\n");
ftpcom = (char *) malloc(20); /* allocate string for ftp command */
sprintf(ftpcom, "ftp -n %s%c", machinename,10); /* put ftp command in string */
fp = popen(ftpcom, "w"); /* send ftp command */
fprintf(fp, "user %s %s%c", username,password, 10); /* login at remote machine, under ftp */
fprintf(fp, "cd %s%c", directory, 10); /* go to correct directory */
fprintf(fp, "get %s /tmp/%s%c", filename, filename, 10); /* get file */
fprintf(fp, "quit%c", 10); /* quit ftp */
pclose(fp); /* close pipe */
printf("Command: %s was executed<p>\n", ftpcom, 10); /* tell client ftp
done */
free(ftpcom);
}
------------------------------------------------------------
If you want to test it, URL is :
http://moulon.inra.fr/cgi-bin/ftp-example
Guy Decoux