computing
  • 6

CURL Not Returning Error Code

  • 6

I am using cURL in a script to grab files at set intervals. My script currently includes the following:

“C:\cURL\curl.exe” -u username:password -R –remote-name-all -K “C:\curl\filelist.txt”
if not ERRORLEVEL 0 goto end

After this line I call an asp page that deletes the files that I just downloaded. Normally this works without issue but occasionally the server will return a 500 internal server error. When this happens, cURL still responds with an ERRORLEVEL of 0 instead of something else identifying a problem. So I am sometimes deleting files before I download them. The file names are dynamic so its not an option to check to see if a certain file exists. Any other thoughts?

This specific script runs on various versions of Windows workstation and server all with the same results.

Share

1 Answer

  1. You might want to try the -f flag of curl:

           -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  pre-
                  vent 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).
    

    However, I think that this may not work when you are trying to get files from a list. What if your list contains 100 URLs, and you get a server error in one of them but the other 99 are ok? If you use a loop (using FOR /F, try typing FOR /? for help) to read the file list, you can then check for an error each time.

    • 1