Curl download file example

Curl download file example

curl download file example

As an example, curl can be used to download a Linux distribution, which are available as ISO files. Open a terminal and type the following. Download to a File. Get a web page and store in a local file with a specific name: curl -o totalfon.net totalfon.net Get a web page and store in a. Example files. There are The examples in this post download the images from The -O flag tells curl to write the file out as a file instead of to standard output.

Curl download file example - share your

Casually: Curl download file example

Photofiltre download cracked version 84
Tp link ce1588 driver download 439
Top 10 secrets and mysteries episode 1 download free 509
Fakebook music pdf torrents download 341
curl download file example

Curl download file example - consider, that

15 Practical Linux cURL Command Examples (cURL Download Examples)

cURL is a software package which consists of command line tool and a library for transferring data using URL syntax.

cURL supports various protocols like, DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP.

This article provides 15 practical cURL usage examples.

1. Download a Single File

The following command will get the content of the URL and display it in the STDOUT (i.e on your terminal).

$ curl totalfon.net

To store the output in a file, you an redirect it as shown below. This will also display some additional download statistics.

$ curl totalfon.net > totalfon.net % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 k 0 k

2. Save the cURL Output to a file

We can save the result of the curl command to a file by using -o/-O options.

  • -o (lowercase o) the result will be saved in the filename provided in the command line
  • -O (uppercase O) the filename in the URL will be taken and it will be used as the filename to store the result
$ curl -o totalfon.net totalfon.net

Now the page totalfon.net will be saved in the file named &#;totalfon.net&#;. You can also note that when running curl with -o option, it displays the progress meter for the download as follows.

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 66 k 66 k 0 0 0 k k 0 0 0

When you use curl -O (uppercase O), it will save the content in the file named &#;totalfon.net&#; itself in the local machine.

$ curl -O totalfon.net

Note: When curl has to write the data to the terminal, it disables the Progress Meter, to avoid confusion in printing. We can use &#;>&#;|&#;-o&#;|&#;-O&#; options to move the result to a file.

Similar to cURL, you can also use wget to download files. Refer to wget examples to understand how to use wget effectively.

3. Fetch Multiple Files at a time

We can download multiple files in a single shot by specifying the URLs on the command line.
Syntax:

$ curl -O URL1 -O URL2

The below command will download both totalfon.net and totalfon.net and save it in the same name under the current directory.

$ curl -O totalfon.net -O totalfon.net

Please note that when we download multiple files from a same sever as shown above, curl will try to re-use the connection.

4. Follow HTTP Location Headers with -L option

By default CURL doesn&#;t follow the HTTP Location headers. It is also termed as Redirects. When a requested web page is moved to another place, then an HTTP Location header will be sent as a Response and it will have where the actual web page is located.

For example, when someone types totalfon.net in the browser from India, it will be automatically redirected to &#;totalfon.net&#;. This is done based on the HTTP Location header as shown below.

$ curl totalfon.net <TITLE> Moved</TITLE> <H1> Moved</H1> The document has moved <A HREF="totalfon.net">here</A>

The above output says that the requested document is moved to &#;totalfon.net&#;.

We can insists curl to follow the redirection using -L option, as shown below. Now it will download the totalfon.net&#;s html source code.

$ curl -L totalfon.net

5. Continue/Resume a Previous Download

Using curl -C option, you can continue a download which was stopped already for some reason. This will be helpful when you download large files, and the download got interrupted.

If we say &#;-C -&#;, then curl will find from where to start resuming the download. We can also give an offset &#;-C <offset>&#;. The given offset bytes will be skipped from the beginning for the source file.

Start a big download using curl, and press Ctrl-C to stop it in between the download.

$ curl -O totalfon.net ############## %

Note: -# is used to display a progress bar instead of a progress meter.

Now the above download was stopped at %. Using &#;curl -C -&#;, we can continue the download from where it left off earlier. Now the download continues from %.

curl -C - -O totalfon.net ############### %

6. Limit the Rate of Data Transfer

You can limit the amount at which the data gets transferred using &#;limit-rate option. You can specify the maximum transfer rate as argument.

$ curl --limit-rate B -O totalfon.net

The above command is limiting the data transfer to Bytes/second. curl may use higher transfer rate for short span of time. But on an average, it will come around to B/second.

The following was the progress meter for the above command. You can see that the current speed is near to the Bytes.

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 1 k 1 0 0 0 1 k 1 0 0 0 1 k 1 0 0 0

7. Download a file only if it is modified before/after the given time

We can get the files that are modified after a particular time using -z option in curl. This will work for both FTP & HTTP.

$ curl -z Dec totalfon.net

The above command will download the totalfon.net only if it is modified later than the given date and time

$ curl -z Dec totalfon.net

The above command will download the totalfon.net, if it is modified before than the given date and time.

Please refer &#;man curl_getdate&#; for the various syntax supported for the date expression

8. Pass HTTP Authentication in cURL

Sometime, websites will require a username and password to view the content ( can be done with .htaccess file ). With the help of -u option, we can pass those credentials from cURL to the web server as shown below.

$ curl -u username:password URL

Note: By default curl uses Basic HTTP Authentication. We can specify other authentication method using &#;ntlm | &#;digest.

9. Download Files from FTP server

cURL can also be used to download files from FTP servers. If the given FTP path is a directory, by default it will list the files under the specific directory.

$ curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/totalfon.net

The above command will download the totalfon.net file from the ftp server and save it in the local directory.

$ curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/

Here, the given URL refers to a directory. So cURL will list all the files and directories under the given URL

If you are new to FTP/sFTP, refer ftp sftp tutorial for beginners.

List/Download using Ranges

cURL supports ranges to be given in the URL. When a range is given, files matching within the range will be downloaded. It will be helpful to download packages from the FTP mirror sites.

$ curl ftp://totalfon.net[a-z]/

The above command will list out all the packages from a-z ranges in the terminal.

Upload Files to FTP Server

Curl can also be used to upload files to the FTP server with -T option.

$ curl -u ftpuser:ftppass -T totalfon.net ftp://totalfon.net

The above command will upload the file named totalfon.net to the FTP server. You can also upload multiple files at a same time using the range operations.

$ curl -u ftpuser:ftppass -T "{file1,file2}" ftp://totalfon.net

Optionally we can use &#;.&#; to get the input from STDIN and transfer to the remote.

$ curl -u ftpuser:ftppass -T - ftp://totalfon.net

The above command will get the input from the user from Standard Input and save the contents in the ftp server under the name &#;myfile_totalfon.net&#;.

You can provide one &#;-T&#; for each URL and the pair specifies what to upload where.

More Information using Verbose and Trace Option

You can get to know what is happening using the -v option. -v option enable the verbose mode and it will print the details

curl -v totalfon.net

The about command will output the following

* About to connect() to totalfon.net port 80 (#0) * Trying connected * Connected to totalfon.net () port 80 (#0) > GET / HTTP/ > User-Agent: curl/ (ipc-linux-gnu) libcurl/ OpenSSL/o zlib/ libidn/ libssh2/ > Host: totalfon.net > Accept: */* > * HTTP , assume close after body < HTTP/ OK < Date: Tue, 10 Apr GMT < Expires: -1 < Cache-Control: private, max-age=0 < Content-Type: text/html; charset=ISO < Set-Cookie: PREF=ID=7ca6b15ccd:FF=0:TM=LM=S=UORpBwxFmTRkbXLj; expires=Thu, Apr GMT; path=/; domain=totalfon.net . .

If you need more detailed information then you can use the &#;trace option. The trace option will enable a full trace dump of all incoming/outgoing data to the given file

=> Send header, bytes (0xa9) 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a GET / HTTP/ 55 73 65 72 2d 41 67 65 6e 74 3a 20 63 75 72 6c User-Agent: curl .. 2e 32 2e 33 2e 34 20 6c 69 62 69 64 6e 2f 31 2e libidn/ 31 35 20 6c 69 62 73 73 68 32 2f 31 2e 32 2e 36 15 libssh2/ 0d 0a 48 6f 73 74 3a 20 77 77 77 2e 67 6f 6f 67 totalfon.net: totalfon.net 6c 65 2e 63 6f 2e 69 6e 0d 0a 41 63 63 65 70 74 totalfon.net 00a0: 3a 20 2a 2f 2a 0d 0a 0d 0a : */* == Info: HTTP , assume close after body <= Recv header, 17 bytes (0x11) 48 54 54 50 2f 31 2e 30 20 32 30 30 20 4f 4b 0d HTTP/ OK. 0a

This verbose and trace option will come in handy when curl fails due to some reason and we don&#;t know why.

Get Definition of a Word using DICT Protocol

You can use cURL to get the definition for a word with the help of DICT protocol. We need to pass a Dictionary Server URL to it.

$ curl dict://totalfon.net:bash

The above command will list the meaning for bash as follows

"Bash" gcide "The Collaborative International Dictionary of English v" Bash \Bash\, v. t. [imp. & p. p. {Bashed}; p. pr. & vb. n. {Bashing}.] [Perh. of imitative origin; or cf. Dan. baske to strike, bask a blow, Sw. basa to beat, bas a beating.] To strike heavily; to beat; to crush. [Prov. Eng. & Scot.] --Hall Caine. [ Webster] Bash her open with a rock. --Kipling. [Webster Suppl.] . "Bash" gcide "The Collaborative International Dictionary of English v" Bash \Bash\, n. 1. a forceful blow, especially one that does damage to its target. [PJC] . .

Now you can see that it uses &#;The Collaborative International Dictionary of English&#;. There are many dictionaries are available. We can list all the dictionaries using

$ curl dict://totalfon.net:db jargon "The Jargon File (version , 29 Dec )" foldoc "The Free On-line Dictionary of Computing (26 July )" easton "Easton's Bible Dictionary" hitchcock "Hitchcock's Bible Names Dictionary (late 's)" bouvier "Bouvier's Law Dictionary, Revised 6th Ed ()"

Now in-order to find the actual meaning of Bash in computer we can search for bash in &#;foldoc&#; dictionary as follows

$ curl dict://totalfon.net:bash:foldoc

The result will be,

bash Bourne Again SHell. {GNU}'s {command interpreter} for {Unix}. Bash is a {Posix}-compatible {shell} with full {Bourne shell} syntax, and some {C shell} commands built in. The Bourne Again Shell supports {Emacs}-style command-line editing, job control, functions, and on-line help. Written by Brian Fox of {UCSB}.

For more details with regard to DICT please read RFC

Use Proxy to Download a File

We can specify cURL to use proxy to do the specific operation using -x option. We need to specify the host and port of the proxy.

$ curl -x totalfon.net totalfon.net

Send Mail using SMTP Protocol

cURL can also be used to send mail using the SMTP protocol. You should specify the from-address, to-address, and the mailserver ip-address as shown below.

$ curl --mail-from blah@totalfon.net --mail-rcpt foo@totalfon.net smtp://totalfon.net

Once the above command is entered, it will wait for the user to provide the data to mail. Once you&#;ve composed your message, type . (period) as the last line, which will send the email immediately.

Subject: Testing This is a test mail .

If you enjoyed this article, you might also like..



Источник: [totalfon.net]

Curl download file example

1 thoughts to “Curl download file example”

Leave a Reply

Your email address will not be published. Required fields are marked *