Ubuntu: Using curl to download an image
curl
without any options will perform a GET request. It will simply return the data from the URI specified. Not retrieve the file itself to your local machine.
When you do,
$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png
You will receive binary data:
|�>�$! <R�HP@T*�Pm�Z��jU֖��ZP+UAUQ@�
��{X\� K���>0c�yF[i�}4�!�V̧�H_�)nO#�;I��vg^_ ��-Hm$$N0.
���%Y[�L�U3�_^9��P�T�0'u8�l�4 ...
In order to save this, you can use:
$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png > image.png
to store that raw image data inside of a file.
An easier way though, is just to use wget
.
$ wget https://www.python.org/static/apple-touch-icon-144x144-precomposed.png
$ ls
.
..
apple-touch-icon-144x144-precomposed.png
How do I download an file(image) in a folder on my Ubuntu server?
If you want to be able to access the files over HTTP then you need to setup a webserver.
If you want to simply download the files really quick, the fastest way is to go into the directory you want to download and run
python3 -m http.server
This will make your files accessible at http://ip_of_server:8080/.
If you however intend to make the files accessible for a large amount of people, you will want to install a dedicated webserver such as for example apache or nginx. These will allow full customisation such as for example password protecting files/directories.
Downloading a file to Ubuntu with libcurl C++, simple example doesn't work
Your link does not point to an existing file. With a correct link it works for me. Try this:
const char *url = "https://i.imgur.com/oRtvmGT.jpg";
wget/curl large file from google drive
WARNING: This functionality is deprecated. See warning below in comments.
Have a look at this question: Direct download from Google Drive using Google Drive API
Basically you have to create a public directory and access your files by relative reference with something like
wget https://googledrive.com/host/LARGEPUBLICFOLDERID/index4phlat.tar.gz
Alternatively, you can use this script: https://github.com/circulosmeos/gdown.pl
Download Multiple Images with Curl
Hello,
You found the answer by yourself.
You must as you said put the images in an array and loop on it.
$urls = ['https://images.somesite.1.jpg', 'https://images.somesite.2.jpg'];
$my_save_dir = 'images/';
foreach ($urls as $url) {
$ch = curl_init($url_to_image);
$filename = basename($url);
$complete_save_loc = $my_save_dir . $filename;
$fp = fopen($complete_save_loc, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
Download Images from a site via a command line
You get the same behavior when running wget https://www.bunlongheng.com/
without all that stuff with images. Running wget -d https://www.bunlongheng.com/ 2>&1 | less
provides some information: there is an index error in a php file :
ErrorException: Undefined offset: 1 (View: /home/forge/bheng/resources/views/layouts/fe/meta.blade.php) (View: /home/forge/bheng/resources/views/layouts/fe/mSkipping 512 bytes of body: [eta.blade.php) in file /home/forge/bheng/storage/framework/views/0b4178e309ed0339363606e08a7e6d3f33347b7f.php on line 76
Stack trace:
1. ErrorException->() /home/forge/bheng/storage/framework/views/0b4178e309ed0339363606e08a7e6d3f33347b7f.php:76
...
etc
As proposed by @mhdINbY, if you put a user agent of an existing browser (I tried mine : -U "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
everything went OK.
I would suspect that your framework analyses the user agent HTTP header in order to format the output accordingly and has a bug when it doesn't know the user agent you are using, here User-Agent: Wget/1.17.1 (linux-gnu)
How to download a file into a directory using curl or wget?
The following line will download all the files to a directory mentioned by you.
wget -P /home/test www.xyz.com
Here the files will be downloaded to /home/test
directory
Related Topics
Why Does the Linux Kernel Repository Have Only One Branch
Linux Distribution Binary Compatibility
How to Give a Linux User Sudo Access
How to Fetch Java Version Using Single Line Command in Linux
Fata[0000] Get Http:///Var/Run/Docker.Sock/V1.17/Version: Dial Unix /Var/Run/Docker.Sock
Convert Multipage PDF to a Single Image
How to Get "Requests Per Second" for Apache in Linux
Ubuntu: Using Curl to Download an Image
Can't Install Python-Dev on Centos 6.5
Check If File Exists on Remote Host with Ssh
Install Zsh Without Root Access
Run a Shell Script in New Terminal from Current Terminal
How to Generate PDF from Docbook 5.0
How to Download a File from the Internet to My Linux Server with Bash
How to Install Packages in Linux (Centos) Without Root User with Automatic Dependency Handling