Date: Sat, 9 Dec 1995 12:19:08 -0600 (CST) From: Joe Greco <jgreco@brasil.moneng.mei.com> To: ache@astral.msk.su (=?KOI8-R?Q?=E1=CE=C4=D2=C5=CA_=FE=C5=D2=CE=CF=D7?=) Cc: hackers@freebsd.org Subject: Re: Does anybody knows a way to get file via HTTP Message-ID: <199512091819.MAA22305@brasil.moneng.mei.com> In-Reply-To: <KH8kOomCL1@deep-thought.demos.su> from "=?KOI8-R?Q?=E1=CE=C4=D2=C5=CA_=FE=C5=D2=CE=CF=D7?=" at Dec 9, 95 04:13:44 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> 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 <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include <netdb.h> #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 <host> <port> <relative-path> [<local-filename>]\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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199512091819.MAA22305>