1. File transfer, client->server; 2. Problem with popen in CGI script.

ts ([email protected])
Sun, 1 May 94 11:46:21 +0200


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 = "[email protected]";
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