How can you download a file/zip from the commandline using putty?

qodeninja picture qodeninja · Oct 23, 2009 · Viewed 50.9k times · Source

I'm trying to write a batch script (CMD @ Windows XP Pro) that will automatically download and unzip packages with the help of 7zip and putty/psftp

If I have a URL to a package to download http://somesite.org/packages/package.zip how do I download it on command line using putty?

Also if you have a better way to do this that would be helpful too.

Answer

fvu picture fvu · Oct 23, 2009

wget is of course an obvious solution, but I also suggest to have a look at cURL. From their website:

curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks.

Of course free and open source, and despite its huge list of supported protocols it's as simple to use as wget, so to use your example

curl -O http://somesite.org/packages/package.zip 

downloads package.zip to a local file with the same name

curl -o myname.zip http://somesite.org/packages/package.zip 

downloads package.zip as myname.zip

curl http://somesite.org/packages/package.zip > package.zip 

redirects curl's stdout to package.zip

EDIT - example corrected, with thanks to @PrabhakarKasi