SkillPilotAI

curl (2/3)

Part 2 of curl goes below HTTP: TLS and certificates, connection timeouts and retries, curl's own DNS (servers, DoH), HTTP/HTTPS/SOCKS proxies, and the non-HTTP protocols curl speaks (FTP/FTPS, SFTP/SCP, SMTP/POP3, Telnet, TFTP, DICT, IPFS). These are the options that fix "works in browser, fails in script" problems.

164.1 Why is it used?

  • Verify a server certificate with the right CA, test TLS versions/ciphers, mTLS and key pinning.
  • Stop scripts from hanging with connect/total timeouts, speed limits and retries.
  • Point curl at a specific DNS server or DoH without touching the system resolver.
  • Reach sites through an HTTP, HTTPS or SOCKS5 proxy, with proxy authentication.
  • Use one tool for FTP uploads, SFTP file operations, sending test mail or a TFTP boot file.
  • TLS backend depends on the build: Windows curl.exe = Schannel, Linux = OpenSSL/GnuTLS, macOS = LibreSSL/Secure Transport.

164.2 How it works

  • Lab: client 192.168.184.20 (netshoot curl 8.7.1, OpenSSL 3.3, c-ares), server 192.168.184.10 for shop.lab with HTTPS on 443 (lab CA), 8441 (self-signed), 8443 (mTLS), 8444 (TLS <= 1.2).
  • HTTPS order: resolve name -> TCP to 443 -> TLS ClientHello -> server certificate -> verify against trusted CA -> HTTP.
  • If the certificate is not trusted, the HTTP request is never sent (exit 60).
  • Through an HTTP proxy, HTTPS uses a CONNECT tunnel: the proxy sees only host:port.
curl HTTPS: DNS, TCP, TLS, then HTTP
  1. 1.curl resolves shop.lab (or --resolve maps it to 192.168.184.10)

  2. 2.TCP connect to 192.168.184.10:443

  3. 3.TLS ClientHello with SNI shop.lab

  4. 4.Server sends its certificate (CN=shop.lab, issuer N164 Lab Root CA)

  5. 5.curl verifies it against --cacert / the trust store

  6. 6.Only if verify ok: GET / is sent inside TLS

No trust = exit 60, the HTTP request never leaves the client

164.3 TLS and certificates

  • No DNS record: exit 6. --resolve host:port:IP skips DNS.
  • Lab CA not trusted: exit 60 "unable to get local issuer certificate"; self-signed cert: exit 60 "self-signed certificate".
  • --cacert FILE trusts that CA; -k skips verification (lab only).
  • Default negotiates TLSv1.3; --tls-max 1.2 caps it; --tlsv1.3 sets the minimum; --ciphers picks TLS 1.2 ciphers.
  • An RSA cipher (AES256-SHA) with an EC certificate: exit 35 handshake failure; TLS1.3 to a 1.2-only port: exit 35 protocol version.
Terminal
S=192.168.184.10R="--resolve shop.lab:443:$S"curl -sS https://shop.lab/curl -sS $R https://shop.lab/curl -sS $R --cacert /lab/ca.crt https://shop.lab/curl -sS -k --resolve shop.lab:8441:$S https://shop.lab:8441/
Output
$ curl -sS https://shop.lab/curl: (6) Could not resolve host: shop.lab$ curl -sS $R https://shop.lab/curl: (60) SSL certificate problem: unable to getlocal issuer certificate$ curl -sS $R --cacert /lab/ca.crt https://shop.lab/hello from shop.lab port 443, you are 192.168.184.20$ curl -sS -k --resolve shop.lab:8441:$S https://shop.lab:8441/hello from shop.lab port 8441, you are 192.168.184.20
Terminal
CA="--cacert /lab/ca.crt"curl -sS $R $CA -v https://shop.lab/ -o /dev/nullcurl -sS $R $CA --tls-max 1.2 -v https://shop.lab/ -o /dev/nullcurl -sS $R $CA --tls-max 1.2 --ciphers AES256-SHA https://shop.lab/curl -sS --resolve shop.lab:8444:$S $CA --tlsv1.3 https://shop.lab:8444/
Output
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384  / x25519 / id-ecPublicKey*  subject: CN=shop.lab*  issuer: O=N164 Lab; CN=N164 Lab Root CA*  SSL certificate verify ok.$ curl -sS $R $CA --tls-max 1.2 -v ...* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES256-GCM-SHA384$ curl -sS $R $CA --tls-max 1.2 --ciphers AES256-SHA ...curl: (35) OpenSSL/3.3.0: error:0A000410:SSL routines::ssl/tls alert handshake failure$ curl ... --tlsv1.3 https://shop.lab:8444/curl: (35) OpenSSL/3.3.0: error:0A00042E:SSL routines::tlsv1 alert protocol version

164.4 mTLS, pinned public key and OCSP

  • Port 8443 needs a client certificate: without one the server resets (exit 55).
  • --cert client.crt --key client.key presents the client cert (key generated on the client, only the CSR signed).
  • --pinnedpubkey sha256//HASH: wrong hash = exit 90, correct hash passes.
  • --cert-status asks for a stapled OCSP response; the lab server sends none (exit 91).
  • Other TLS options: --capath, --ca-native, --cert-type P12, --tls13-ciphers, --curves, --crlfile, --ssl-no-revoke / --ssl-revoke-best-effort (Schannel), --false-start (macOS).
Terminal
curl -sS --resolve shop.lab:8443:$S $CA https://shop.lab:8443/whoamicurl -sS --resolve shop.lab:8443:$S $CA --cert /lab/client.crt --key /lab/client.key https://shop.lab:8443/whoamicurl -sS $R $CA --pinnedpubkey 'sha256//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=' https://shop.lab/curl -sS $R $CA --cert-status https://shop.lab/
Output
curl: (55) Send failure: Connection reset by peer$ curl ... --cert /lab/client.crt --key /lab/client.key ...hello asha-laptop (mTLS port 8443)$ curl ... --pinnedpubkey 'sha256//AAAA...' ...curl: (90) SSL: public key does not match pinned public key$ curl -sS $R $CA --cert-status https://shop.lab/curl: (91) No OCSP response received

164.5 Connection, timeouts, speed and retries

  • --connect-timeout 2 limits only the connect phase (exit 28 after 2001 ms); -m 2 limits the whole transfer.
  • --retry N retries transient errors (HTTP 503, timeouts), not a refused connection; --retry-all-errors retries everything; --retry-connrefused adds refused.
  • --limit-rate 256K throttles; -Y 50000 -y 2 aborts if slower than 50000 B/s for 2 s (exit 28).
  • --interface eth0 / IP binds the source (unknown IP = exit 45); --keepalive-time sets TCP keepalive.
  • --connect-to shop.lab:443:IP:8444 sends the connection elsewhere while Host and SNI stay shop.lab.
Terminal
time curl -sS --connect-timeout 2 http://192.168.184.99/time curl -sS -m 2 http://$S/slowcurl --no-progress-meter -f --retry 2 --retry-delay 1 http://$S/busytime curl -sS --limit-rate 20K -Y 50000 -y 2 -o /dev/null http://$S/big.bincurl -sS --interface 192.168.184.99 http://$S/curl -sS $CA --connect-to shop.lab:443:$S:8444 -v https://shop.lab/
Output
$ time curl -sS --connect-timeout 2 http://192.168.184.99/curl: (28) Failed to connect to 192.168.184.99 port 80after 2001 ms: Timeout was reachedreal 0m 2.01s$ time curl -sS -m 2 http://$S/slowcurl: (28) Operation timed out after 2003 millisecondswith 0 bytes received$ curl --no-progress-meter -f --retry 2 --retry-delay 1 .../busycurl: (22) The requested URL returned error: 503Warning: Problem : HTTP error. Will retry in 1 seconds. 2 retries left.Warning: Problem : HTTP error. Will retry in 1 seconds. 1 retries left.$ time curl -sS --limit-rate 20K -Y 50000 -y 2 ...curl: (28) Operation too slow. Less than 50000 bytes/sectransferred the last 2 seconds$ curl -sS --interface 192.168.184.99 http://$S/curl: (45) bind failed with errno 99: Address not available$ curl -sS $CA --connect-to shop.lab:443:$S:8444 -v ...* Connected to 192.168.184.10 (192.168.184.10) port 8444* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES256-GCM-SHA384> Host: shop.labhello from shop.lab port 8444, you are 192.168.184.20
OptionLimits / doesExit on failure
--connect-timeout 2Only the TCP/TLS connect phase28
-m / --max-time 2The whole operation28
-Y 50000 -y 2Abort if below speed for N seconds28
--max-filesize NRefuse files bigger than N63
--retry 2Retry transient errors (503, timeouts)last error
--retry-all-errorsRetry every error, even refusedlast error
--interface IPBind source address45

164.6 DNS options

  • Needs a c-ares build: --dns-servers IP uses that resolver; --dns-interface eth0 sends queries out of that interface.
  • --doh-url wraps the query in HTTPS; the DoH server's certificate is verified too (exit 6 until --cacert).
  • --doh-insecure skips that check; the server log showed both A and AAAA queries.
  • Others: --dns-ipv4-addr, --dns-ipv6-addr, --doh-cert-status.
Terminal
curl -sS --dns-servers $S http://shop.lab/curl -sS --doh-url https://$S/dns-query http://shop.lab/curl -sS --doh-insecure --doh-url https://$S/dns-query -v http://files.lab/
Output
$ curl -sS --dns-servers $S http://shop.lab/hello from shop.lab port 80, you are 192.168.184.20$ curl -sS --doh-url https://$S/dns-query http://shop.lab/curl: (6) Couldn't resolve host name$ curl -sS --doh-insecure --doh-url ... -v http://files.lab/* Connected to files.lab (192.168.184.10) port 80[srv]$ grep dns /tmp/labsrv.log[dns] A files.lab -> 192.168.184.10[dns] AAAA files.lab -> no data

164.7 HTTP, HTTPS and SOCKS proxies

  • -x http://host:8888 sends the full request to the proxy; the proxy resolves the name and the server sees the proxy IP.
  • No proxy credentials: 407; -U user:pass fixes it; the Via header shows tinyproxy.
  • HTTPS through a proxy uses CONNECT automatically; -p forces CONNECT for plain HTTP too.
  • --noproxy 192.168.184.0/24 goes direct for those hosts.
  • --socks5 resolves the name locally (exit 97 here); --socks5-hostname (socks5h://) resolves at the proxy.
  • HTTPS proxy (-x https://...) has its own TLS: --proxy-cacert / --proxy-insecure apply to the proxy only.
Proxy: curl, tinyproxy and server
  1. 1.curl -x http://192.168.184.10:8888 -U proxyuser:... http://shop.lab/

  2. 2.Full request GET http://shop.lab/ + Proxy-Authorization goes to tinyproxy

  3. 3.tinyproxy checks credentials (407 without -U)

  4. 4.tinyproxy resolves shop.lab and forwards the request

  5. 5.Server replies "you are 192.168.184.10" (the proxy IP)

  6. 6.For https:// curl sends CONNECT shop.lab:443 and TLS runs inside the tunnel

Terminal
PX="-x http://192.168.184.10:8888"PU="-U proxyuser:ProxyPass164"curl -sS $PX -o /dev/null -w 'HTTP %{http_code}\n' http://shop.lab/curl -sS -i $PX $PU http://shop.lab/curl -sS $PX $PU -p -v http://shop.lab/curl -sS --socks5 $S:1080 http://shop.lab/curl -sS --socks5-hostname $S:1080 http://shop.lab/curl -sS -x https://$S:8889 --proxy-cacert /lab/ca.crt $PU http://shop.lab/
Output
HTTP 407$ curl -sS -i $PX $PU http://shop.lab/HTTP/1.1 200 OKVia: 1.1 n164-proxy (tinyproxy/1.11.1)Server: BaseHTTP/0.6 Python/3.11.2 hello from shop.lab port 80, you are 192.168.184.10$ curl -sS $PX $PU -p -v http://shop.lab/> CONNECT shop.lab:80 HTTP/1.1< HTTP/1.0 200 Connection established$ curl -sS --socks5 $S:1080 http://shop.lab/curl: (97) Could not resolve host: shop.lab$ curl -sS --socks5-hostname $S:1080 http://shop.lab/hello from shop.lab port 80, you are 192.168.184.10$ curl ... --proxy-cacert /lab/ca.crt $PU http://shop.lab/hello from shop.lab port 80, you are 192.168.184.10
Proxy typeOptionWho resolves the name
HTTP proxy-x http://h:8888Proxy
HTTPS proxy-x https://h:8889 (+ --proxy-cacert)Proxy
SOCKS4 / SOCKS5--socks4 / --socks5, socks5://Client
SOCKS4a / SOCKS5h--socks4a / --socks5-hostname, socks5h://Proxy

164.8 FTP and FTPS

  • URL ending in / lists the directory; -l lists names only; -T uploads.
  • Default passive mode: curl sends EPSV and connects to the data port the server announces (30006).
  • -P - is active mode: the client sends EPRT with its IP/port and the server connects back.
  • --ssl-reqd makes TLS mandatory (AUTH SSL, then PROT P encrypts data); --ssl alone falls back to plain text.
  • --ftp-create-dirs makes missing folders; -Q 'CMD' runs before, -Q '-CMD' after the transfer; a failed command = exit 21.
Terminal
U="-u asha:LabPass164"curl -sS $U -l ftp://$S/files/curl -sS $U --ftp-pasv -v ftp://$S/files/curl -sS $U -P - -v ftp://$S/files/curl -sS $U --ssl-reqd $CA -v ftp://$S/files/curl -sS $U -Q 'DELE files/draft.txt' -T /lab/up.txt -Q '-RNFR up.txt' -Q '-RNTO sales.txt' ftp://$S/files/curl -sS $U -Q 'DELE nothere.txt' ftp://$S/files/
Output
$ curl -sS $U -l ftp://$S/files/draft.txtreport.txt$ curl -sS $U --ftp-pasv -v ftp://$S/files/> EPSV< 229 Entering Extended Passive Mode (|||30006|)* Connecting to 192.168.184.10 (192.168.184.10) port 30006> LIST$ curl -sS $U -P - -v ftp://$S/files/> EPRT |1|192.168.184.20|33459|< 200 EPRT command successful. Consider using EPSV.$ curl -sS $U --ssl-reqd $CA -v ftp://$S/files/> AUTH SSL< 234 Proceed with negotiation.* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384> PROT P< 200 PROT now Private.$ curl -sS $U -l ftp://$S/files/2026report.txtsales.txt$ curl -sS $U -Q 'DELE nothere.txt' ftp://$S/files/curl: (21) QUOT command failed with 550

164.9 SFTP and SCP

  • netshoot curl has no libssh2: "Protocol sftp not supported" (exit 1); this part used Debian curl 7.88.1 + libssh2.
  • --hostpubsha256 pins the SSH host key; a mismatch shows the real fingerprint and denies the session (exit 60).
  • --key logs in with a private key (-u asha:); a bad key path = exit 67 Authentication failure.
  • scp:// downloads a file directly.
  • SFTP -Q commands are interpreted by curl: rename, mkdir, chmod, pwd, rm, chown, symlink...; rm on a missing file = exit 21.
Terminal
D=sftp://$S/home/asha/files/curl -sS --hostpubsha256 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA $U $Dcurl -sS -u asha: --key /root/.ssh/lab_ed25519 -l $DF=/home/asha/filescurl -sS $U -Q "rename $F/sales.txt $F/sales-q3.txt" -Q "mkdir $F/archive" -Q "chmod 600 $F/report.txt" $D
Output
curl: (60) Denied establishing ssh session: mismatch sha256fingerprint. Remote WZwObtU66o6tp4wfc78OqK8udZ7TzXu6275ZmntI0LA=is not equal to AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA[srv]$ curl -sS -u asha: --key /root/.ssh/lab_ed25519 -l $Dsales.txt2026report.txt[srv]$ curl -sS $U -Q "rename ..." -Q "mkdir ..." -Q "chmod ..." $Ddrwxr-xr-x  3 asha  asha  4096 Nov  9 08:13 2026drwxr-xr-x  2 asha  asha  4096 Nov  9 08:13 archive-rw-------  1 asha  asha    13 Nov  9 08:11 report.txt-rw-r--r--  1 asha  asha     9 Nov  9 08:13 sales-q3.txt

164.10 Mail, Telnet, TFTP, DICT and IPFS

  • SMTP: --mail-from and --mail-rcpt build the envelope, -T mail.txt is sent in DATA; -X VRFY sends a custom command.
  • pop3://host/ lists messages, pop3://host/1 downloads message 1; IMAP not running here = exit 7.
  • telnet:// opens a raw TCP session (-t TTYPE=vt100); tftp:// downloads over UDP (--tftp-blksize 1024); missing file = exit 68.
  • dict://host/d:word fetches a definition; file:// reads a local file.
  • ipfs:// needs --ipfs-gateway, otherwise "automatic gateway detection failed".
Terminal
curl -sS --mail-from asha@shop.lab --mail-rcpt ops@shop.lab -T /lab/mail.txt -v smtp://$S/client.labcurl -sS -u ops:LabMail164 pop3://$S/1curl -sS tftp://$S/boot.cfgcurl -sS --ipfs-gateway http://$S:8080 ipfs://bafylabcid/report.txt
Output
< 220 mail.shop.lab ESMTP N164 lab sink> EHLO client.lab> MAIL FROM:<asha@shop.lab>< 250 2.1.0 Ok> RCPT TO:<ops@shop.lab>> DATA< 354 End data with <CR><LF>.<CR><LF>< 250 2.0.0 Ok: queued as N164-1$ curl -sS -u ops:LabMail164 pop3://$S/1From: asha@shop.labTo: ops@shop.labSubject: N164 lab test Backup done at 02:00.$ curl -sS tftp://$S/boot.cfgkernel vmlinuz-labip=192.168.184.50$ curl -sS --ipfs-gateway http://$S:8080 ipfs://bafylabcid/report.txtN164 lab IPFS gateway stub: /ipfs/bafylabcid/report.txt

164.11 Common mistakes

  • Fixing a certificate error with -k: it turns verification off and accepts fake servers; use --cacert (and --pinnedpubkey if needed).
  • Using --ssl for FTPS: it silently falls back to plain text; use --ssl-reqd.
  • Using --socks5 when only the proxy can resolve the name: use --socks5-hostname.
  • Expecting --retry to retry a refused connection: add --retry-connrefused or --retry-all-errors.
  • Confusing --cacert (destination) with --proxy-cacert (HTTPS proxy).

164.12 Interview tips

  • --resolve maps host:port to an IP (port unchanged); --connect-to sends host:port to another host:port. In both, URL, Host header and SNI stay the same, so the cert check still works.
  • HTTPS through an HTTP proxy: the proxy sees only CONNECT shop.lab:443; path and headers stay encrypted.
  • --connect-timeout vs -m: connect phase only vs the whole transfer; both exit 28.
  • Exit codes to remember: 6 resolve, 7 connect, 28 timeout, 35 handshake, 60 cert verify, 67 login, 97 SOCKS.