# CMake Authenticated Download From Artifactory

**URL:** https://discourse.cmake.org/t/cmake-authenticated-download-from-artifactory/8148
**Category:** Usage
**Created:** [May 17, 2023, 7:02pm UTC](https://discourse.cmake.org/t/cmake-authenticated-download-from-artifactory/8148 "2023-05-17T19:02:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cmacd122](https://discourse.cmake.org/user_avatar/discourse.cmake.org/cmacd122/32/3451_2.png) [@cmacd122](https://discourse.cmake.org/u/cmacd122)
#### Post date: [May 17, 2023, 7:02pm UTC](https://discourse.cmake.org/t/cmake-authenticated-download-from-artifactory/8148/1 "2023-05-17T19:02:46Z")

</div>

I have been trying to perform an authenticated download using the ‘file’ command. I have tried setting up the HTTPHEADER option several ways:

First with a token:

set(ART\_HEADER “"Authorization: Bearer mytoken"”)

and I have also tried an API key:

set(ART\_HEADER “"X-JFrog-Art-Api: myapikey"”)

Then running the file command as such:

file(  
DOWNLOAD “[https://myartifcatoryserver/server/repolocation/filename.zip](https://myartifcatoryserver/server/repolocation/filename.zip)” “/file/saveas/location/file.zip”  
STATUS DOWNLOAD\_STATUS  
LOG DOWNLOAD\_LOG  
SHOW\_PROGRESS  
HTTPHEADER ${ART\_HEADER} )

All attempts to download return a status of 22.  
I have tried downloading without the header using anonymous download, and that works fine.  
If I add the header to try and download from that same repo, I still get an error.

Any ideas on what I might be doing wrong? This is using cmake version 3.22.  
Thanks for any help!

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [May 18, 2023, 7:27am UTC](https://discourse.cmake.org/t/cmake-authenticated-download-from-artifactory/8148/2 "2023-05-18T07:27:23Z")

</div>

We use **FetchContents** that use `ExternalProject_Add()` which has an `HTTP_HEADER` argument?

That works, but we use **no space** in `set(HTTP_HEADER "X-JFrog-Art-Api:myapikey")`!

@ben.boeckel Why has `file()` a different argument for the same option?

see too [Extra HTTP headers for `file(UPLOAD|DOWNLOAD)`](https://discourse.cmake.org/t/extra-http-headers-for-file-upload-download/1152)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 18, 2023, 12:09pm UTC](https://discourse.cmake.org/t/cmake-authenticated-download-from-artifactory/8148/3 "2023-05-18T12:09:55Z")

</div>

> [@ClausKlein](#):
>
> Why has `file()` a different argument for the same option?

`file()` is older and probably just copies the `libcurl` name as an argument.

> [@cmacd122](#):
>
> HTTPHEADER ${ART\_HEADER} )

Does it work if you use `"${ART_HEADER}"` (with quotes)?

---

<div class="post-metadata">

### Author: ![cmacd122](https://discourse.cmake.org/user_avatar/discourse.cmake.org/cmacd122/32/3451_2.png) [@cmacd122](https://discourse.cmake.org/u/cmacd122)
#### Post date: [May 18, 2023, 12:16pm UTC](https://discourse.cmake.org/t/cmake-authenticated-download-from-artifactory/8148/4 "2023-05-18T12:16:49Z")

</div>

@ben.boeckel I tried that as well. Did not make a difference.  
I think I found a solution for my use case by using ‘USERPWD’ instead. I will still be able to use a token with the user name. This will work with a service account we have setup for automated CMake builds.

Thanks to all for the input!
