Skip to content

Instantly share code, notes, and snippets.

@atomize
Created February 26, 2019 22:03
Show Gist options
  • Save atomize/74357b8e5e0b772b1398968eb069bc6c to your computer and use it in GitHub Desktop.
Save atomize/74357b8e5e0b772b1398968eb069bc6c to your computer and use it in GitHub Desktop.
bash function to download file from web without cURL/wget
# Add this to your .bashrc
# Use it like: you@console_>$ _get https://website.org/file.txt
_get ()
{
IFS=/ read proto z host query <<< "$1"
exec 3< /dev/tcp/$host/80
{
echo GET /$query HTTP/1.1
echo connection: close
echo host: $host
echo
} >&3
sed '1,/^$/d' <&3 > $(basename $1)
}
@gaborcsardi
Copy link

Very neat trick, although https of course does not work, only http, and of course redirects do not work, either.

@DocterDum
Copy link

A unix stack exchange page containing multiple alternative scripts, discussing advantages:
https://unix.stackexchange.com/questions/83926/how-to-download-a-file-using-just-bash-and-nothing-else-no-curl-wget-perl-et

Or superuser article page with a couple alternative protocols (Notably using openssl for HTTPS):
https://superuser.com/questions/447873/download-a-file-without-wget-or-curl

@elExplode
Copy link

@atomize
Copy link
Author

atomize commented May 3, 2023

I love that folks are commenting on this gist 4 years later :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment