I'm trying to download a file, https://the.earth.li/~sgtatham/putty/latest/w64/putty.exe or https://www.7-zip.org/a/7z1806-x64.exe, without using curl or wget; rather, I want to download the file by using telnet as follows.

(echo 'GET /~sgtatham/putty/latest/w64/putty.exe'; echo ""; sleep 1; ) | telnet the.earth.li 80 > s.exe

This does not work; when I use cat the file contents are as follows.

HTTP/1.1 302 Found
Date: Sun, 17 Feb 2019 18:40:22 GMT
Server: Apache
Location: https://the.earth.li/~sgtatham/putty/0.70/w64/putty.exe
Content-Length: 301
Content-Type: text/html; charset=iso-8859-1

<title>302 Found</title>
<p>The document has moved <a href="https://the.earth.li/~sgtatham/putty/0.70/w64/putty.exe">here</a>.</p>
<address>Apache Server at the.earth.li Port 80</address>
  • 1
    In the reply from the server, you see that the document has moved to a new address. It also tells you what the new address is. – Kusalananda Feb 17 at 18:53
  • after following the new address, you’ll also have to remove the http header from the response – Nephanth Feb 17 at 18:56
  • 2
    You are going to have to be very good at hand-writing TLS handshakes to do that with telnet from an HTTPS URL. I think you're out of luck. – Michael Homer Feb 17 at 18:57
  • forget what I said, the command "(echo 'GET /~sgtatham/putty/0.70/w64/putty.exe'; echo ""; sleep 1; ) | telnet the.earth.li 80 > s.exe " seems to just work without even having to remove headers – Nephanth Feb 17 at 19:02
  • 1
    If you have openssl installed, openssl s_client -host the.earth.li -port 443 -crlf will do the job. Otherwise you may want to put a copy somewhere HTTP-accessible. – Michael Homer Feb 17 at 19:14

From the reply you can see that the "document has moved" to "https://the.earth.li/~sgtatham/putty/0.70/w64/putty.exe", so you should just change the link in your command (change "latest" to "0.70").
Your browser does this automatically. The command should be:
(echo 'GET /~sgtatham/putty/0.70/w64/putty.exe'; echo ""; sleep 1; ) | telnet the.earth.li 80 > s.exe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.