FreeKB - Curl -o --output (download file)
Curl - -o --output (download file)

The curl command no options or flags can be used to display the contents of a file on a remote system. In this example, the contents of the index.html file on the www.example.com web server is displayed.

~]# curl http://www.example.com/index.html
<html>
  <body>
    Hello World
  </body>
</html>

 

In this example, the contents of the foo.json file on the www.example.com web server is displayed.

~]# curl http://www.example.com/foo.json
[
 {
  "foo":"bar"
 }
]

 

By default, curl uses the GET method, thus there is no need to use the -X or --request option when using the GET method. The following commands will both return the content of the index.html page. The -X or --request option must be used when using any other method (POST, PUT, DELETE). 

curl http://www.example.com/index.html
curl -X GET http://www.example.com/index.html

 

The -o or --output option can be used to redirect the content of the remote file to a file on your local system. In this example, the contents of the index.html file on the www.example.com web server is redirected to a file named index.html on your local system.

curl --output index.html http://www.example.com/index.html

 

Or, redirection can be used as well.

curl http://www.example.com/index.html > index.html

 

If the remote system requires basic authentication, the -u or --user option can be used to include the username and password in the request.

curl --user "username:password" --output "/tmp/index.html" "http://www.example.com/index.html"

 

It is often a good idea to also used the -w or --write-out option to determine if you are able to GET the file from the remote system.

curl --write-out "%{http_code}" --output "/tmp/index.html" "http://www.example.com/index.html"

 

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 53585 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |