Exit code
A lot of effort has gone into the project to make curl return a usable exitcode when something goes wrong and it always returns 0 (zero) when theoperation went as planned.
If you write a shell script or batch file that invokes curl, you can alwayscheck the return code to detect problems in the invoked command. Below, youfind a list of return codes as of the time of this writing. Over time we tendto slowly add new ones so if you get a code back not listed here, please referto more updated curl documentation for aid.
A basic Unix shell script could look like something like this:
#!/bin/shcurl http://example.comres=$?if test "$res" != "0"; then echo "the curl command failed with: $res"fi
Available exit codes
Unsupported protocol. This build of curl has no support for thisprotocol. Usually this happens because the URL was misspelled to use ascheme part that either has a space in front of it or spells
http
likehtpt
or similar. Another common mistake is that you use a libcurlinstallation that was built with one or more protocols disabled and younow ask libcurl to use one of those protocols that were disabled in thebuild.Failed to initialize. This is mostly an internal error or a problem withthe libcurl installation or system libcurl runs in.
URL malformed. The syntax was not correct. This happens when you mistype aURL so that it ends up wrong, or in rare situations you are using a URLthat is accepted by another tool that curl does not support only becausethere is no universal URL standard that everyone adheres to.
A feature or option that was needed to perform the desired request wasnot enabled or was explicitly disabled at build-time. To make curl ableto do this, you probably need another build of libcurl.
Could not resolve proxy. The address of the given proxy host could not beresolved. Either the given proxy name is just wrong, or the DNS server ismisbehaving and does not know about this name when it should or perhaps eventhe system you run curl on is misconfigured so that it does not find/use thecorrect DNS server.
Could not resolve host. The given remote host's address was not resolved.The address of the given server could not be resolved. Either the givenhostname is just wrong, or the DNS server is misbehaving and does not knowabout this name when it should or perhaps even the system you run curl on ismisconfigured so that it does not find/use the correct DNS server.
Failed to connect to host. curl managed to get an IP address to themachine and it tried to set up a TCP connection to the host butfailed. This can be because you have specified the wrong port number,entered the wrong hostname, the wrong protocol or perhaps because thereis a firewall or other network equipment in between that blocks thetraffic from getting through.
Unknown FTP server response. The server sent data curl could notparse. This is either because of a bug in curl, a bug in the server orbecause the server is using an FTP protocol extension that curl does notsupport. The only real work-around for this is to tweak curl options to tryto get it to use other FTP commands that perhaps do not get this unknownserver response back.
FTP access denied. The server denied login or denied access to theparticular resource or directory you wanted to reach. Most often you triedto change to a directory that does not exist on the server. The directoryof course is what you specify in the URL.
FTP accept failed. While waiting for the server to connect back when anactive FTP session is used, an error code was sent over the controlconnection or similar.
FTP weird PASS reply. Curl could not parse the reply sent to the PASSrequest. PASS in the command curl sends the password to the server with,and even anonymous connections to FTP server actually sends a password - afixed anonymous string. Getting a response back from this command thatcurl does not understand is a strong indication that this is not an FTPserver at all or that the server is badly broken.
During an active FTP session (PORT is used) while waiting for the serverto connect, the timeout expired. It took too long for the server to getback. This is usually a sign that something is preventing the server fromreaching curl successfully, such as a firewall or other networkarrangements.
Unknown response to FTP PASV command. Curl could not parse the reply sentto the PASV request. This is a strange server. PASV is used to set up thesecond data transfer connection in passive mode, see theFTP uses two connections section for more onthat. You might be able to work-around this problem by using PORT instead,with the
--ftp-port
option.Unknown FTP 227 format. Curl could not parse the 227-line the server sent.This is most certainly a broken server. A 227 is the FTP server's responsewhen sending back information on how curl should connect back to it inpassive mode. You might be able to work-around this problem by using PORTinstead, with the
--ftp-port
option.FTP cannot get host. Could not use the host IP address we got in the227-line. This is most likely an internal error.
HTTP/2 error. A problem was detected in the HTTP2 framing layer. This issomewhat generic and can be one out of several problems, see the errormessage for details.
FTP could not set binary. Could not change transfer method to binary.This server is broken. curl needs to set the transfer to the correct modebefore it is started as otherwise the transfer cannot work.
Partial file. Only a part of the file was transferred. When the transferis considered complete, curl verifies that it actually received the sameamount of data that it was told before-hand that it was going to get. If thetwo numbers do not match, this is the error code. It could mean that curlgot fewer bytes than advertised or that it got more. curl itself cannot knowwhich number is wrong or which is correct, if any.
FTP could not download/access the given file. The RETR (or similar)command failed. curl got an error from the server when trying to downloadthe file.
Not used
Quote error. A quote command returned an error from the server. curlallows several different ways to send custom commands to an IMAP, POP3,SMTP or FTP server and features a generic check that the commandswork. When any of the individually issued commands fails, this is the exitstatus returned. The advice is generally to watch the headers in theFTP communication to better understand exactly what failed and how.
HTTP page not retrieved. The requested URL was not found or returnedanother error with the HTTP error code being 400 or above. This returncode only appears if
-f, --fail
is used.Write error. Curl could not write data to a local filesystem orsimilar. curl receives data chunk by chunk from the network and it storesit like at (or writes it to stdout), one piece at a time. If that writeaction gets an error, this is the exit status.
Not used
Upload failed. The server refused to accept or store the file that curltried to send to it. This is usually due to wrong access rights on theserver but can also happen due to out of disk space or other resourceconstraints. This error can happen for many protocols.
Read error. Various reading problems. The inverse to exit status 23. Whencurl sends data to a server, it reads data chunk by chunk from a local fileor stdin or similar, and if that reading fails in some way this is the exitstatus curl returns.
Out of memory. A memory allocation request failed. curl needed toallocate more memory than what the system was willing to give it and curlhad to exit. Try using smaller files or make sure that curl gets morememory to work with.
Operation timeout. The specified time-out period was reached according tothe conditions. curl offers severaltimeouts,and this exit code tells one of those timeout limits were reached. Extendthe timeout or try changing something else that allows curl to finish itsoperation faster. Often, this happens due to network and remote serversituations that you cannot affect locally.
Not used
FTP PORT failed. The PORT command failed. Not all FTP servers support thePORT command; try doing a transfer using PASV instead. The PORT command isused to ask the server to create the data connection byconnecting backto curl. See also theFTP uses two connectionssection.
FTP could not use REST. The REST command failed. This command is used forresumed FTP transfers. curl needs to issue the REST command to do range orresumed transfers. The server is broken, try the same operation withoutrange/resume as a crude work-around.
Not used
HTTP range error. The range request did not work. Resumed HTTP requestsare not necessarily acknowledged or supported, so this exit code signals thatfor this resource on this server, there can be no range or resumedtransfers.
HTTP post error. Internal post-request generation error. If you get thiserror, please report the exact circumstances to the curl project.
A TLS/SSL connect error. The SSL handshake failed. The SSL handshake canfail due to numerous different reasons so the error message may offer someadditional clues. Maybe the parties could not agree to a SSL/TLSversion, an agreeable cipher suite or similar.
Bad download resume. Could not continue an earlier aborted download. Whenasking to resume a transfer that then ends up not possible to do, thiserror can get returned. For FILE, FTP or SFTP.
Could not read the given file when using the FILE:// scheme. Failed toopen the file. The file could be non-existing or is it a permission problemperhaps?
LDAP cannot bind. LDAP "bind" operation failed, which is a necessary stepin the LDAP operation and thus this means the LDAP query could not beperformed. This might happen because of a wrong username or password, or forother reasons.
LDAP search failed. The given search terms caused the LDAP search toreturn an error.
Not used
Not used
Aborted by callback. An application told libcurl to abort theoperation. This error code is not generally made visible to users and notto users of the curl tool.
Bad function argument. A function was called with a bad parameter - thisreturn code is present to help application authors to understand whylibcurl cannot perform certain actions and should never be returned by thecurl tool. Please file a bug report to the curl project if this happens toyou.
Not used
Interface error. A specified outgoing network interface could not beused. curl typically decides outgoing network and IP addresses by itself butwhen explicitly asked to use a specific one that curl cannot use, this errorcan occur.
Not used
Too many redirects. When following HTTP redirects, libcurl hit themaximum number set by the application. The maximum number of redirects isunlimited by libcurl but is set to 50 by default by the curl tool. Thelimit is present to stop endless redirect loops. Change the limit with
--max-redirs
.Unknown option specified to libcurl. This could happen if you use a curlversion that is out of sync with the underlying libcurl version. Perhapsyour newer curl tries to use an option in the older libcurl that was notintroduced until after the libcurl version you are using but is known toyour curl tool code as that is newer. To decrease the risk of this andmake sure it does not happen: use curl and libcurl of the same versionnumber.
Malformed telnet option. The telnet option you provided to curl did notuse the correct syntax.
Not used
The server's SSL/TLS certificate or SSH fingerprint failed verification.curl can then not be sure of the server being who it claims to be. See theusing TLS with curl andusing SCP and SFTP withcurl sections for more details.
The server did not reply anything, which in this context is considered anerror. When an HTTP(S) server responds to an HTTP(S) request, it alwaysreturnssomething as long as it is alive and sound. All valid HTTPresponses have a status line and responses header. Not getting anything atall back is an indication the server is faulty or perhaps that somethingprevented curl from reaching the right server or that you are trying toconnect to the wrong port number etc.
SSL crypto engine not found.
Cannot set SSL crypto engine as default.
Failed sending network data. Sending data over the network is a crucialpart of most curl operations and when curl gets an error from the lowestnetworking layers that the sending failed, this exit status getsreturned. To pinpoint why this happens, some serious digging is usuallyrequired. Start with enabling verbose mode, do tracing and if possible checkthe network traffic with a tool like Wireshark or similar.
Failure in receiving network data. Receiving data over the network is acrucial part of most curl operations and when curl gets an error from thelowest networking layers that the receiving of data failed, this exitstatus gets returned. To pinpoint why this happens, some serious diggingis usually required. Start with enabling verbose mode, do tracing and ifpossible check the network traffic with a tool like Wireshark or similar.
Not used
Problem with the local certificate. The client certificate had a problemso it could not be used. Permissions? The wrong passphrase?
Could not use the specified SSL cipher. The cipher names need to bespecified exactly and they are also unfortunately specific to the particularTLS backend curl has been built to use. For the current list of supportciphers and how to write them, see the online docs athttps://curl.se/docs/ssl-ciphers.html.
Peer certificate cannot be authenticated with known CA certificates. Thisusually means that the certificate is either self-signed or signed by aCA (Certificate Authority) that is not present in the CA store curl uses.
Unrecognized transfer encoding. Content received from the server couldnot be parsed by curl.
Not used
Maximum file size exceeded. When curl has been told to restrict downloadsto not do it if the file is too big, this is the exit code for thatcondition.
Requested SSL (TLS) level failed. In most cases this means that curlfailed to upgrade the connection to TLS when asked to.
Sending the data requires a rewind that failed. In some situations curlneeds to rewind in order to send the data again and if this cannot be done,the operation fails.
Failed to initialize the OpenSSL SSL Engine. This can only happen whenOpenSSL is used and would signify a serious internal problem.
The username, password, or similar was not accepted and curl failed tolog in. Verify that the credentials are provided correctly and that they areencoded the right way.
File not found on TFTP server.
Permission problem on TFTP server.
Out of disk space on TFTP server.
Illegal TFTP operation.
Unknown TFTP transfer ID.
File already exists (TFTP).
No such user (TFTP).
Not used
Not used
Problem with reading the SSL CA cert. The default or specified CA certbundle could not be read/used to verify the server certificate.
The resource (file) referenced in the URL does not exist.
An unspecified error occurred during the SSH session. This sometimesindicates an incompatibility problem between the SSH libcurl curl uses andthe SSH version used by the server curl speaks to.
Failed to shut down the SSL connection.
Not used
Could not load CRL file, missing or wrong format
TLS certificate issuer check failed. The most common reason for this isthat the server did not send the proper intermediate certificate in the TLShandshake.
The FTP
PRET
command failed. This is a non-standard command and farfrom all servers support it.RTSP: mismatch of CSeq numbers
RTSP: mismatch of Session Identifiers
Unable to parse FTP file list. The FTP directory listing format used bythe server could not be parsed by curl. FTP wildcards can not be used onthis server.
FTP chunk callback reported error
No connection available, the session is queued
SSL public key does not match pinned public key. Either you provideda bad public key, or the server has changed.
Invalid SSL certificate status. The server did not provide a propervalid certificate in the TLS handshake.
Stream error in HTTP/2 framing layer. This is usually an unrecoverableerror, but trying to force curl to speak HTTP/1 instead might circumvent it.
An API function was called from inside a callback. If the curl toolreturns this, something has gone wrong internally
Authentication error.
HTTP/3 layer error. This is somewhat generic and can be one out ofseveral problems, see the error message for details.
QUIC connection error. This error may be caused by an TLS libraryerror. QUIC is the transport protocol used for HTTP/3.
Proxy handshake error. Usually that means that a SOCKS proxy did not playalong.
A TLS client certificate is required but was not provided.
An internal call to poll() or select() returned error that is notrecoverable.
Error message
When curl exits with a non-zero code, it also outputs an error message (unless--silent
is used). That error message may add some additional information orcircumstances to the exit status number itself so the same error number canget different error messages.
Users can also craft their own error messages with--write-out. The pseudo variable%{onerror}
allows you to set a message that only gets displayed on errors,and it offers%{errormsg}
and%{exitcode}
among all the variables.
For example:
curl --write-out "%{onerror}curl says: (%{exitcode}) %{errormsg}" \ https://curl.se/
"Not used"
The list of exit codes above contains a number of values marked as 'notused'. Those are exit status codes that are not used in modern versions of curlbut that have been used or were intended to be used in the past. They may beused in a future version of curl.
Additionally, the highest used error status in this list is 99, but futurecurl versions might have added more exit codes after that number.