Skip to content

Curl command line downloads

wordpress meta

title: 'Curl command line downloads'
date: '2013-02-07T21:46:54-06:00'
status: publish
permalink: /curl-command-line-downloads
author: admin
excerpt: ''
type: post
id: 257
category:
    - Curl
    - Linux
tag: []
post_format: []

If you need a command line download on Linux there are several options. Wget for a simple download is a very good option but I prefer curl as I have had more success when dealing with logins, cookies and uploads than with wget.

Plus if you need to go further and integrate something with python or php the curl libraries are awesome.

Simple download:

$ curl -o myfile.iso "http://server.com/file.iso"

With login:

$ curl -o myfile.iso -u user:password "https://content.server.com/isos/file-x86_64-dvd.iso"
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
 Dload  Upload   Total   Spent    Left  Speed
 100 3509M  100 3509M    0     0  6204k      0  0:09:39  0:09:39 --:--:-- 7106k

** Note sometimes to get the correct download string you will need to login into the site with your browser and copy the download location of the link. Or in some cases actually initiate the download with the browser and then copy the link from the browser download window.

If you are after a more permanent web or scripted solution you can use curl to login and save the cookie. Then subsequently download the file using the generated cookie. This requires more experimentation with your particular site.

Login and save a cookie:

$ curl -c cookie.txt -u user:password https://secDownload.mybank.com/

List files:

$ curl -b cookie.txt -u user:password https://secDownload.mybank.com/

Upload a file:

$ curl -b cookie.txt --upload-file test.rrosso https://secDownload.mybank.com/

If you are behind corporate firewalls you might still be able to use curl.
Behind socks5 proxy:

$ curl --socks5 proxy.domain.com -U rrosso:pwd -c cookie2.txt -u site-user:pwd https://secDownload.mybank.com/ (login and save a cookie)
$ curl --socks5 proxy.domain.com -U rrosso:pwd -b cookie2.txt -u site-user:pwd
https://secDownload.mybank.com/ (list files using saved cookie)
$ curl --socks5 proxy.domain.com -U rrosso:pwd -b cookie2.txt --upload-file test.rrosso https://secDownload.mybank.com

Behind squid proxy:

$ curl -x proxy.domain.com:3128 -U rrosso:pwd -o ARP08110610926072.txt_171317.RECVD -u site-user:pwd https://secDownload.mybank.com/ARP08110610926072.txt_171317.RECVD

$ curl -x proxy.domain.com:3128 -U rrosso:pwd -c cookie2.txt -u site-user:pwd https://secDownload.mybank.com
Virtual user site-user logged in.

$ curl -x proxy.domain.com:3128 -U rrosso:pwd -b cookie2.txt -u site-user:pwd https://secDownload.mybank.com
total 38
...

$ curl -x proxy.domain.com:3128 -U rrosso:pwd -b cookie2.txt -u site-user:pwd --upload-file rrosso-test https://secDownload.mybank.com