[Ilugc] download from the terminal(curl,wget,lftp,lynx)

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Tue, 15 Nov 2011 10:21:54 +0530

This is not just a simple tip. This is a tip cluster so to speak.

Here we are going to see how many different ways exist to download a
file using the web(http) or ftp.

There is also a way to download from Windows share using a Samba tool
but I have no need to use it at the moment.

So let us stick with the web and ftp protocols. In fact sftp can also
be used to download but it is not very prevalent.

In the UNIX command line world where memory power is the key factor in
getting your job done, be it vi(m) key strokes or mutt keystrokes or
even one of those popular commands like grep you ought to remember the
appropriate switch.

Moreover just like every language has its own idiom, in Tamil you
always address elders by neenga and in Telugu you always use "ri" or
"di" and in Hindi you say "ji", in English you don't have any such
term.

Similarly in C programming you have to use pointers to do anything at
all which is more than basic programming.

Likewise in the UNIX world even if you are using a kid Linux like
Ubuntu or Redhat, you still have to use the command line.

I think many people shy away from the command line due to their
distrust of their own memory.

And funnily enough Tiruvalluvar has very clearly said that a person
without memory can never succeed in life.

So most of the tips I send need to be memorized. However much you
dislike mugup (as they say), you cannot get away
 from it.

And that is indeed the UNIX idiom and that is why it is most powerful
and comprehensive.

So using a browser or a GUI to do what can be done with the command
line is not style. It is frowned upon.

Now let us see how many ways exist to download something.

Let me adopt this URL for our purpose. It is a live working URL, so
you don't have to change anything while running.

Just copy paste and it will run(remove the dollar sign).

http://ftp.openssl.org/source/openssl-0.9.6.tar.gz

Now the "ftp.openssl.org" is a host name which will be replaced by IP
address internally. It does not mean that it
 uses FTP commands.

As you well know if you paste this URL in a browser you will obtain
the zip file using HTTP.

Now there are multiple ways in which to obtain this from the UNIX command line.

$ lynx --dump http://ftp.openssl.org/source/openssl-0.9.6.tar.gz ;>
openssl-0.9.6.tar.gz

$ curl -s http://ftp.openssl.org/source/openssl-0.9.6.tar.gz ;>
openssl-0.9.6.tar.gz

$ wget http://ftp.openssl.org/source/openssl-0.9.6.tar.gz

$ lftpget http://ftp.openssl.org/source/openssl-0.9.6.tar.gz

All these do the same thing.

$ ncftpget http://ftp.openssl.org/source/openssl-0.9.6.tar.gz

Now you can also use FTP URL instead.

Interestingly the same URL can be converted to FTP by(yes you know)

ftp://ftp.openssl.org/source/openssl-0.9.6.tar.gz

Now you can use FTP commands underneath to fetch the file for you.

OSes like FreeBSD, NetBSD and OpenBSD use makefiles to build its ports
subsystem.

In that process one of the first steps is to fetch the zip files and
also the patches(in most cases patches
 ship with the OS) , so the fetch is done using a command line like
this and then
 this is made into a Makefile rule.

I will be talking about makefiles in a subsequent tip.

-Girish
-- 
G3 Tech
Networking appliance company
web: http://g3tech.in ?mail: girish at g3tech.in

Other related posts: