{"id":257,"date":"2013-02-07T21:46:54","date_gmt":"2013-02-08T05:46:54","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=257"},"modified":"2013-02-07T22:03:00","modified_gmt":"2013-02-08T06:03:00","slug":"curl-command-line-downloads","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/curl-command-line-downloads\/","title":{"rendered":"Curl command line downloads"},"content":{"rendered":"

If you need a command line download on Linux there are several options.\u00a0 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.<\/p>\n

Plus if you need to go further and integrate something with python or php the curl libraries are awesome.<\/p>\n

Simple download:<\/strong><\/span><\/p>\n

$ curl -o myfile.iso "http:\/\/server.com\/file.iso"<\/pre>\n

With login:<\/strong><\/span><\/p>\n

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

** 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.\u00a0 Or in some cases actually initiate the download with the browser and then copy the link from the browser download window.<\/p>\n

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

Login and save a cookie:<\/strong><\/span><\/p>\n

$ curl -c cookie.txt -u user:password https:\/\/secDownload.mybank.com\/<\/pre>\n

List files:<\/strong><\/span><\/p>\n

$ curl -b cookie.txt -u user:password https:\/\/secDownload.mybank.com\/<\/pre>\n

Upload a file:<\/strong><\/span><\/p>\n

$ curl -b cookie.txt --upload-file test.rrosso https:\/\/secDownload.mybank.com\/<\/pre>\n

 <\/p>\n

If you are behind corporate firewalls you might still be able to use curl.
\nBehind socks5 proxy:<\/strong><\/span><\/p>\n

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

Behind squid proxy:<\/span><\/strong><\/p>\n

\r\n$ 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\r\n\r\n$ curl -x proxy.domain.com:3128 -U rrosso:pwd -c cookie2.txt -u site-user:pwd https:\/\/secDownload.mybank.com\r\nVirtual user site-user logged in.\r\n\r\n$ curl -x proxy.domain.com:3128 -U rrosso:pwd -b cookie2.txt -u site-user:pwd https:\/\/secDownload.mybank.com\r\ntotal 38\r\n...\r\n\r\n$ curl -x proxy.domain.com:3128 -U rrosso:pwd -b cookie2.txt -u site-user:pwd --upload-file rrosso-test https:\/\/secDownload.mybank.com\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

If you need a command line download on Linux there are several options.\u00a0 Wget for a simple download is a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,9],"tags":[],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-curl","category-linux"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}