I am trying to check whether a file is available at a particular location or not, if file doesn't exists then it must send an email to an email list. The problem is that, the file needs to be downloaded from a URL (sharepoint) before checking if it exists or not.

If there is no file at the URL, the cURL command is downloading the file with "404 NOT FOUND" content in it. If there is no file at the source, I don't want the cURL command to download any file. How can i achieve this?

cd $file_path    
curl -k --ntlm -u $USER_GROUP:$PASS -O http://sharepoint.com/sites/dummy/file_list.txt

This is the command to download that i am using. Any help would be appreciated. Thanks.

1 Answer 1


Adding the -f switch should achieve what you want.

From curl manual:

-f/--fail (HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts. In normal cases when a HTTP server fails to deliver a document, it returns an HTML document stating so (which often also describes why and more). This flag will prevent curl from outputting that and return error 22.

This method is not fail-safe and there are occasions where non-successful response codes will slip through, especially when authentication is involved (response codes 401 and 407).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .