Thursday, May 16, 2013

Bash - download using bash


Bash can be used to download files from command line.
Here is an example.

TEST_HOSTNAME='downloadmirror01.org'
exec {HTTP_FD}<>/dev/tcp/${TEST_HOSTNAME}/80
echo -ne 'GET /tmp/file.tar.gz HTTP/1.1\r\nHost: '\
${TEST_HOSTNAME}'\r\nUser-Agent: '\
'bash/'${BASH_VERSION}'\r\n\r\n' >&${HTTP_FD}
sed -e '1,/^.$/d' <&${HTTP_FD} >file.tar.gz


Explanation 
We use exec to connect and assign the connection to file descriptor.
Echo transfers the command(http request) to the download server using file descriptor.
sed skips the http headers sent by the sever, and output the resuilt into file.tar.gz.


No comments :

Post a Comment