CMake Authenticated Download From Artifactory

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:

DOWNLOAD “https://myartifcatoryserver/server/repolocation/” “/file/saveas/location/”

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!

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)`

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

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

@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!