Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a file into a directory using curl or wget? [closed]

I know I can use the following 2 commands to download a file:

curl -O example.com/file.zip wget example.com/file.zip 

But I want them to go into a specific directory. So I can do the following:

curl -o mydir/file.zip example.com/file.zip wget -O mydir/file.zip example.com/file.zip 

Is there a way to not have to specify the filename? Something like this:

curl -dir mydir example.com/file.zip 
like image 762
at. Avatar asked Oct 17 '13 01:10

at.


People also ask

Can I use curl to download a file?

Introduction : cURL is both a command line utility and library. One can use curl to download file or transfer of data/file using many different protocols such as HTTP, HTTPS, FTP, SFTP and more. The curl command line utility lets you fetch a given URL or file from the bash shell.

Should I use curl or wget?

Differences Between wget and cURLWget is a simple transfer utility, while curl offers so much more. Curl provides the libcurl library, which can be expanded into GUI applications. Wget, on the other hand, is a simple command-line utility. Wget supports fewer protocols compared to cURL.

How do I download all files in a directory using curl?

To download multiple files at the same time, use –O followed by the URL to the file that you wish to download. If you curl without any options except for the URL, the content of the URL (whether it's a webpage, or a binary file, such as an image or a zip file) will be printed out to screen.


2 Answers

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

like image 156
2 revs, 2 users 86% Avatar answered Sep 23 '22 01:09

2 revs, 2 users 86%


I know this is an old question but it is possible to do what you ask with curl

rm directory/somefile.zip rmdir directory mkdir directory curl --http1.1 http://example.com/somefile.zip --output directory/somefile.zip 

first off if this was scripted you would need to make sure the file if it already exist is deleted then delete the directory then curl the download otherwise curl will fail with a file and directory already exist error.

like image 37
mewasthere Avatar answered Sep 23 '22 01:09

mewasthere