5 Basic CURL Command Examples - RoseHosting

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

5/29/2017 5basiccURLcommandexamplesRoseHosting.

comBlog

5basiccURLcommandexamples
OCTOBER21,2016 1 TIPSANDTRICKS

Facebook 0 Twitter 8 Google+ 2 Linkedin 2

cURLisveryusefulcommandlinetooltotransferdatafromortoaserver.cURLsupportsvariousprotocols

likeFILE,HTTP,HTTPS,IMAP,IMAPS,LDAP,DICT,LDAPS,TELNET,FTP,FTPS,GOPHER,RTMP,

RTSP,SCP,SFTP,POP3,POP3S,SMB,SMBS,SMTP,SMTPS,andTFTP.

cURLcanbeusedinmanydifferentandinterestingways.Withthistoolyoucandownload,uploadandmanage

files,checkyouremailaddress,orevenupdateyourstatusonsomeofthesocialmediawebsitesorcheckthe

weatheroutside.InthisarticlewillcoverfiveofthemostusefulandbasicusesofthecURLtoolonanyLinux

VPS.

1.CheckURL
OneofthemostcommonandsimplestusesofcURListypingthecommanditself,followedbytheURLyou

wanttocheck

https://www.rosehosting.com/blog/curlcommandexamples/ 1/4
5/29/2017 5basiccURLcommandexamplesRoseHosting.comBlog

curlhttps://domain.com

ThiscommandwilldisplaythecontentoftheURLonyourterminal

2.SavetheoutputoftheURLtoafile
TheoutputofthecURLcommandcanbeeasilysavedtoafilebyaddingtheooptiontothecommand,as

shownbelow

curlowebsitehttps://domain.com

%Total%Received%XferdAverageSpeedTimeTimeTimeCurrent
DloadUploadTotalSpentLeftSpeed
1004179304179300275k0::::::2.9M

Inthisexample,outputwillbesavetoafilenamedwebsiteinthecurrentworkingdirectory.

3.DownloadfileswithcURL
YoucandownlaodfileswithcURLbyaddingtheOoptiontothecommand.Itisusedforsavingfilesonthe

localserverwiththesamenamesasontheremoteserver

curlOhttps://domain.com/file.zip

Inthisexample,thefile.zipziparchivewillbedownloadedtothecurrentworkingdirectory.

YoucanalsodownloadthefilewithadifferentnamebyaddingtheooptiontocURL.

curloarchive.ziphttps://domain.com/file.zip

Thiswaythefile.ziparchivewillbedownloadedandsavedasarchive.zip.
https://www.rosehosting.com/blog/curlcommandexamples/ 2/4
5/29/2017 5basiccURLcommandexamplesRoseHosting.comBlog

cURLcanbealsousedtodownloadmultiplefilessimultaneously,asshownintheexamplebelow

curlOhttps://domain.com/file.zipOhttps://domain.com/file2.zip

cURLcanbealsousedtodownloadfilessecurelyviaSSHusingthefollowingcommand

curluusersftp://server.domain.com/path/to/file

Notethatyouhavetousethefullpathofthefileyouwanttodownload

4.GetHTTPheaderinformationfromawebsite
YoucaneasilygetHTTPheaderinformationfromanywebsiteyouwantbyaddingtheIoption(capitali)to

cURL.

curlIhttp://domain.com

HTTP/1.1200OK
Date:Sun,16Oct201623:37:15GMT
Server:Apache/2.4.23(Unix)
XPoweredBy:PHP/5.6.24
Connection:close
ContentType:text/html;charset=UTF8

5.AccessanFTPserver
ToaccessyourFTPserverwithcURLusethefollowingcommand

curlftp://ftp.domain.comuserusername:password

https://www.rosehosting.com/blog/curlcommandexamples/ 3/4
5/29/2017 5basiccURLcommandexamplesRoseHosting.comBlog

cURLwillconnecttotheFTPserverandlistallfilesanddirectoriesinusershomedirectory

YoucandownloadafileviaFTP

curlftp://ftp.domain.com/file.zipuserusername:password

anduploadafileottheFTPserver

curlTfile.zipftp://ftp.domain.com/userusername:password

YoucancheckcURLmanualpagetoseeallavailablecURLoptionsandfunctionalities

mancurl

https://www.rosehosting.com/blog/curlcommandexamples/ 4/4

You might also like