cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Two newbie questions

From: Scott Haneda <talklists_at_newgeo.com>
Date: Fri, 5 Mar 2010 13:07:14 -0800

On Mar 5, 2010, at 8:28 AM, Jeremy Solomon wrote:

> I'm new at using curl, and was hoping you would be able to help me with two questions that I can't find the answer to:
>
> 1. When performing an http download, how do I specify the local path where I want the file to be saved?
> 2. How do I prevent the http download of non-existant (404) pages?

My first answer to a question, so take it as being also new…
You use -O to specify the saved location.

Locate a 404 page for testing:
     $curl --head http://www.google.com/support/webmasters/bin/
    HTTP/1.1 404 Not Found
    Content-Type: text/html; charset=UTF-8
    Date: Fri, 05 Mar 2010 20:59:52 GMT
    Expires: Fri, 05 Mar 2010 20:59:52 GMT
    Cache-Control: private, max-age=0
    X-Content-Type-Options: nosniff
    Server: GSE
    X-XSS-Protection: 0
    Transfer-Encoding: chunked
    
Test it out:
    $curl http://www.google.com/support/webmasters/bin/ -fo ~/Desktop/file.txt

    $ls -la ~/Desktop/file.txt
    ls: /Users/me/Desktop/file.txt: No such file or directory

Find a working file…
    $curl --head
    http://www.abm-enterprises.net/fractal-art/green-curl-wallpaper.jpg
    HTTP/1.1 200 OK
    Date: Fri, 05 Mar 2010 21:02:00 GMT
    Server: Apache/1.3.39 (Unix) PHP/4.4.8 mod_auth_passthrough/1.8
    mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635 DAV/1.0.3
    mod_ssl/2.8.30 OpenSSL/0.9.7a
    Last-Modified: Fri, 01 Feb 2008 22:33:14 GMT
    ETag: "1d6827f2-3c81f-47a39e2a"
    Accept-Ranges: bytes
    Content-Length: 247839
    Content-Type: image/jpeg
    
Putting it all together:
$curl http://www.abm-enterprises.net/fractal-art/green-curl-wallpaper.jpg -fo ~/Desktop/image.jpg
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 242k 100 242k 0 0 640k 0 --:--:-- --:--:-- --:--:-- 809k

    $file ~/Desktop/image.jpg
    /Users/me/Desktop/image.jpg: JPEG image data, JFIF standard 1.02

You can use --silent for silent and not get any of the output messages as well:
$curl --silent http://www.abm-enterprises.net/fractal-art/green-curl-wallpaper.jpg -fo ~/Desktop/image.jpg

-- 
Scott * If you contact me off list replace talklists@ with scott@ * 
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-03-05