How to download artifacts using wget from Sonatype Nexus

dr0n3 picture dr0n3 · May 11, 2014 · Viewed 38.2k times · Source

I got a Sonatype Nexus instance up and running and need to write a script to download a specific artifact manually.

I tried using the REST API and wget:

wget --user=username --password=password http://<ip>:<port>/nexus/service/local/artifact/maven/content?g=<group>&a=<artifact>&v=<version>&r=snapshots

Resolving <ip stuff>
Connecting to <ipv6 stuff>... failed: Connection refused.
Connecting to <ipv4 stuff>... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Reusing existing connection to <ip>:<port>.
HTTP request sent, awaiting response... 400 Bad Request
2014-05-11 20:17:01 ERROR 400: Bad Request.

Does anyone know, how to get this to work?

Edit: I'm able to download the artifact using my browser (and being logged in to the webinterface)

Answer

rseddon picture rseddon · May 12, 2014

The URL looks correct, but you're to have to quote it because it contains special characters.

wget --user=username --password=password "http://<ip>:<port>/nexus/service/local/artifact/maven/content?g=<group>&a=<artifact>&v=<version>&r=snapshots"

You also might want to add --content-disposition in order for the downloaded file name to be correct. See here for more information:

https://support.sonatype.com/entries/23674267