From owner-freebsd-hackers Sat Dec 9 10:20:28 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id KAA05530 for hackers-outgoing; Sat, 9 Dec 1995 10:20:28 -0800 (PST) Received: from brasil.moneng.mei.com (brasil.moneng.mei.com [151.186.20.4]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id KAA05525 for ; Sat, 9 Dec 1995 10:20:24 -0800 (PST) Received: (from jgreco@localhost) by brasil.moneng.mei.com (8.7.Beta.1/8.7.Beta.1) id MAA22305; Sat, 9 Dec 1995 12:19:08 -0600 From: Joe Greco Message-Id: <199512091819.MAA22305@brasil.moneng.mei.com> Subject: Re: Does anybody knows a way to get file via HTTP To: ache@astral.msk.su (=?KOI8-R?Q?=E1=CE=C4=D2=C5=CA_=FE=C5=D2=CE=CF=D7?=) Date: Sat, 9 Dec 1995 12:19:08 -0600 (CST) Cc: hackers@freebsd.org In-Reply-To: from "=?KOI8-R?Q?=E1=CE=C4=D2=C5=CA_=FE=C5=D2=CE=CF=D7?=" at Dec 9, 95 04:13:44 pm X-Mailer: ELM [version 2.4 PL24] Content-Type: text Sender: owner-hackers@freebsd.org Precedence: bulk > It is actual, because more and more sites places archives available by > HTTP only. > All browsers I know can't work in background... :-( I assume you can write a small C program to do it, but I really don't know for sure. Typically I test http servers by doing telnet www.server.name. 80 GET /path/file for "http://www.server.name/path/file" (remember http does not specify the "http://www.server.name" in the GET command). I would suspect you can simply catch the response from the server and save it. Since I do these little sorts of programs all the time, I can probably take something I already have and throw something new together in 45 seconds... Ok, here is a sample "webget": % webget www.sol.net. 80 /demon43_ps1.bkgd.gif /tmp/test.gif % xv /tmp/test.gif source code below. ... Joe ------------------------------------------------------------------------------- Joe Greco - Systems Administrator jgreco@ns.sol.net Solaria Public Access UNIX - Milwaukee, WI 414/342-4847 #include #include #include #include #include #include #include #define bcopy(a, b, c) memcpy((b), (a), (c)) int main(argc, argv) int argc; char *argv[]; { int s; int fd; struct sockaddr_in sin; int addrlen; struct hostent *host; char buffer[65536]; int ofd, rval; if (argc < 4 || argc > 5) { fprintf(stderr, "usage: webget []\n"); exit(1); } if (argc == 5) { if ((ofd = open(argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) { perror(argv[4]); exit(1); } } else { ofd = fileno(stdout); } sin.sin_port = 0; sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(1); } if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("bind"); exit(1); } sin.sin_port = htons(atoi(argv[2])); sin.sin_family = AF_INET; if (isdigit(*argv[1])) { sin.sin_addr.s_addr = inet_addr(argv[1]); } else { if (! (host = gethostbyname(argv[1]))) { perror(argv[1]); exit(1); } bcopy(host->h_addr_list[0], (char *)&sin.sin_addr.s_addr, sizeof(sin.sin_addr.s_addr)); } if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("connect"); exit(1); } sprintf(buffer, "GET %s\r\n", argv[3]); write(s, buffer, strlen(buffer)); while (rval = read(s, buffer, sizeof(buffer))) { if (rval > 0) { if (write(ofd, buffer, rval) < 0) { perror("write"); exit(1); } } else { perror("read"); exit(1); } } close(s); close(ofd); exit(0); }