Issue
Is there an option for curl to automatically change the downloaded file's filename if that filename already exists on disk?
Wget does this automatically by appending a .1, .2, .3, .4 etc... to the end of the file name.
Curl Example:
$ ls -al
drwx------. 3 user user 219 Sep 6 17:12 .
drwxr-xr-x. 3 user user 21 May 12 18:54 ..
-rw-rw-r--. 1 user user 147415 Sep 6 16:47 image.jpg
$ curl -O https://website/context/path/image.jpg
$ ls -al
drwx------. 3 user user 219 Sep 6 17:12 .
drwxr-xr-x. 3 user user 21 May 12 18:54 ..
-rw-rw-r--. 1 user user 147415 Sep 6 17:35 image.jpg
The above curl command will overwrite the original image.jpg. Is there a way in curl to cause the new file to be named image.jpg.1
, or something similar, like in wget?
Wget Example:
$ rm image.jpg*
$ wget https://website/context/path/image.jpg
$ ls -al
drwx------. 3 user user 219 Sep 6 17:12 .
drwxr-xr-x. 3 user user 21 May 12 18:54 ..
-rw-rw-r--. 1 user user 147415 Sep 6 17:42 image.jpg
$ wget https://website/context/path/image.jpg
$ wget https://website/context/path/image.jpg
$ wget https://website/context/path/image.jpg
$ ls -al
drwx------. 3 user user 219 Sep 6 17:12 .
drwxr-xr-x. 3 user user 21 May 12 18:54 ..
-rw-rw-r--. 1 user user 147415 Sep 6 17:42 image.jpg
-rw-rw-r--. 1 user user 147415 Sep 6 17:42 image.jpg.1
-rw-rw-r--. 1 user user 147415 Sep 6 17:42 image.jpg.2
-rw-rw-r--. 1 user user 147415 Sep 6 17:42 image.jpg.3
Solution
Nope. curl has no such option. If you really need it, you can most often work around it by doing the check yourself in a script or other wrapper program.
This feature is mentioned in curl's TODO as something that would be neat to have, so it might be added at a future point in time...
Answered By - Daniel Stenberg Answer Checked By - Robin (WPSolving Admin)