C
Cat
Add many lines to a file
cat > file.txt << EOF
Line 1
Line 2
EOFCurl
Options
-X: Method GET, POST, etc
-F or –form: Form data
-v: verbose
-u: username:password
-k, –insecure: allow insecure connection
-d, --data:
@, the rest should be a file name to read the data from: e.g. -d @filename
-: data is from stdin
When -d, --data is told to read from a file, carriage returns and newlines will be stripped out. => @ character has a special interpretation use --data-raw instead
o filename: save output to filename
O: save output with its original filename
Upload file using Post
curl -X POST -F "file=@./file.txt" -F "key=" https://website.com/uploader
curl -d @data.txt -X POST http://example.com/upload
curl -X POST -F "content=Here is a text file upload" -F "[email protected]" https://discord.com/api/webhooks/1781574/wMt6zP
Send form data
curl -d "username=user1&password=pass123" -X POST http://example.com/login: submit login form with credential
Send Json data
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://example.com/api
Send URL-encoded data
curl -d "field1=value1&field2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://example.com/form
Download file
curl -O http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso
curl -C - -O http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso: Resume dropped connection
curl --limit-rate 1m -O http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso: limit speed to 1 mb, other suffix is k for kilobytes, g for gigabytes
curl -# -O http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso: display download status progress bar
Upload file via FTP
curl -T newfile.tar.gz -u FTP_USERNAME:FTP_PASSWORD ftp://ftp.example.com/
-T: remote file name is the original filename
curl -T newfile.tar.gz -u FTP_USERNAME:FTP_PASSWORD -k sftp://ftp.example.com/: using sftp
Delete file from FTP Server
curl ftp://ftp.example.com/ -X 'DELE file.txt' -u FTP_USERNAME:FTP_PASSWORD
Post data to influxdb via api
curl -i -XPOST 'http://localhost:8086/write?db=telegraf' --data-binary 'cpu_load_short,host=server01 value=0.64'
-i, --include: Include protocol response headers in the output
Delete file from ftp server
Basic Authentication
curl -u "username:password" url
Using a proxy
curl --proxy socks5://127.0.0.1:8080 checkip.dyndns.org
curl -x socks5://127.0.0.1:8080 checkip.dyndns.org
curl --proxy-ntlm --proxy "http://$user:[email protected]:8080 checkip.dyndns.org: NTLM Auth with Proxy
Timing with Curl
curl -w "dnslookup: %{time_namelookup} | connect: %{time_connect} | appconnect: %{time_appconnect} | pretransfer: %{time_pretransfer} | starttransfer: %{time_starttransfer} | total: %{time_total} | size: %{size_download}\n" -so /dev/null https://site.com
Getting Definition of a word using DICT Protocol
curl dict://dict.org/d:computer
curl dict://dict.org/show:db: list available dictionaries
Reference
https://davidwalsh.name/curl-post-file
https://medium.com/@petehouston/upload-files-with-curl-93064dcccc76
https://kb.fortinet.com/kb/documentLink.do?externalID=FD37759
https://blog.cloudflare.com/a-question-of-timing/
Last updated