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

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


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


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

rm directory/somefile.ziprmdir directorymkdir directorycurl --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.


The simplest way is to cd inside a subshell

  (cd somedir; wget example.com/file.zip)

and you could make that a shell function (e.g. in your ~/.bashrc)

  wgetinside() {    ( cd $1 ; shift; wget $* )  }

then type wgetinside somedir http://example.com/file.zip