Arun Arun - 1 year ago 130
JSON Question

cURL download files issue

When i give the URL (
) in browser, It automatically downloads the file as

Now using i'm trying to download the file using
but i get the following error.

$ curl -O
curl: Remote file name has no length!
curl: try 'curl --help' or 'curl --manual' for more information

When using the '
' switch , I get the JSON content displayed but the file is not saved.

$curl -L




How to download the exact file "
" using cURL / wget ?

I don't want the contents to be redirected (
) manually to a file (

Any suggestions please ?

Answer Source

The -O flag of curl tries to use the remote name of the file, but because your URL schema does not end with a filename, it can not do this. The -o flag (lower-case o) can be used to specify a file name manually without redirecting STDOUT like so:

curl <address> -o filename.json

You can manually construct the filename format you want using awk. For example:

file_number=$(echo $URL | awk -F/ '{print $(NF-2)}')
curl -L "$URL" -o "$file_name"

Hope this is more helpful.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download