curl

Updated: February 11, 2024

Curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.


Table of Contents

tldr

# make multiple requests
curl www.example.com --next -d postthis www.another.com

# transfer files to URL
curl -T "{file1,file2}" http://www.example.com

# get local weather report and colorize the result
curl wttr.in/ | lolcat

ARGUMENTS

curl http://somelame.site           # pulls the html of a website and prints to terminal.
      -o, --output                  # download file; write output to file instead of stdout
      -O, --remote-name             # match local file name to file we get
      -T, --upload-file             # transfer local file to remote URL
      -f, --fail                    # fail silently on server errors
      -s, --silent                  # don't show progress meter  or  error  messages.
      -S, --show-error              # When used with -s, --silent, it makes curl show an error message if it fails.
      -L, --location                # follow redirects
      -i, --include                 # gets server, content-type info etc.
      -:, --next                    # send several URL request each repleat with their own options
      -#, --progress-bar            # make curl display transfer progress as  a  simple  progress  bar.
      -m, --max-time <time>         # maximum time in seconds that you allow the  whole  operation  to take.
      -v, --verbose                 # output more information on progress
      -V, --version                 # get current version
      -I, --head                    # fetch headers only for an FTP|HTTP file
      -#  --progress-bar            # simple progress bar using #####
      -u, --user <user:pw>          # to be used for server authentication
      -d, --data <data>             # send data to HTTP server as POST request
      -F, --form <name=content>     # connect content to type
      -e, --referer <URL>           # sends referrer page information to the server
      -k, --insecure                # let transfer proceed as insecure
            --create-dirs           # create necessary directories
      --create-file-mode            # choose permission at time of creation (0644 default)
      -Z, --parallel                # make curl transfer in parallel instead of serial manner
      -M, --manual                  # display huge help text

GITLAB API

curl -o filename "https://gitlab.com/api/v4/projects/:id/repository/files/:base64path/raw?ref=branch"       # pull exact copy of a file
curl -o .vimrc "https://gitlab.com/api/v4/projects/12002459/repository/files/vim%2F.vimrc/raw?ref=master"   # for public repos

GET /projects/:id/repository/files/:file_path

curl --request GET --header 'PRIVATE-TOKEN: ibo6YuQqQgDmP9soX9w3' 'https://gitlab.com/api/v4/projects/11995278/repository/files/:/blob/master/megamenu.sh'

curl --request GET --header 'PRIVATE-TOKEN: ibo6YuQqQgDmP9soX9w3' 'https://gitlab.com/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb/raw?ref=master'
git archive --remote=ssh:git@gitlab.com:megacron/megamenu.git HEAD megamenu.sh | tar -x

user = ibo6YuQqQgDmP9soX9w3
API = McByzDhszcKZnVjzVT2m

MANIPULATING CONTENT

curl http://somelame.site/methods         # get request must be done with method.
      -d, --data                          # post request
curl -d "first=mega&last=cron" http://somelame.site/methods    # ex send in data
curl -X PUT -d "first=mega&last=tron" http://somelame.site/methods
      # put updates existing data. (we changed cron to tron)
curl -X DELETE http://somelame.site/methods    # eletes data

AUTHENTICATION

curl http://somelame.site/secret   # site that requires a login in order to use curl
    -u, --user <user:password>    # specify the user name and password to use for server authentication.

DOWNLOAD

curl http://somelame.site/download   # to be done from download route
    -o, --output    # download specified item
curl -o noice.jpg https://somelame.site/download    # change the name of the file from download to noice
curl -o somename.json https://somelame.site/download

curl -O https://somelame.site/download    # uses file name of the file being downloaded

FTP GOPHER SMB HTTPS

curl -u user:password -o <url>    # download from ftp
curl -u user:password -T <filename(s)> <url>

GETTING INFORMATION ABOUT A WEBSITE

curl -IL https://www.cnn.com