Programatically download a Jira Cloud attachment versus Jira Software Server (8.7)

I have a customer using Jira Software Server 8.7 while I am using Jira Cloud. I am in need to replicate some issues from customer site where I have 1 user access, to my site where I have the entire team access. Of course I want to automate it all to skip the need to trips to customer Jira installation in order to bring data into the cloud issue. I have done a pretty well job using REST API except for the attachments.

I created a PHP webservice as a kind of broker where I intend to sync all attachments between any number of issues residing on various Jira platforms. I am able to upload new attachments via Jira API but I am stuck with actual downloading the attachment files from Jira Cloud.

I was able to deal with the Jira Software instance because I reutilized all cookies that were send at the first connection when I read the issue, and the list of attachments and url of the files in the content field. Reading these files went well. Access to this instance works completely with Basic Authentication (and unless Jira Cloud, I can use the username and password here, not username and token).

However this technique does not work on Jira Cloud. No matter if I intend to use token based Basic Authentication or reuse the cookies obtained via REST API calls (where I used Basic Authentication) I am constantly redirected to the login page. This also is sometimes accompanied by weird error codes such as 426 Upgrade Required while using HTTP/1.1 and 505 when trying HTTP/2.0

Nevertheless the only solution I still need to explore is to install PhantomJS and try to trick Jira Cloud into replicating an actual user session but I really do not like this, seems too extreme.

I am not sure if a cURL with username/password credentials for Jira Cloud would work, this would be simpler to deal with.

Does anyone have an opinion about this challenge?

I watched more closely the response headers. Apparently there are some redirects happening and with the HTTP request I was using there was no session management.

Using cURL solved the issue, so Basic Auth with token plus cURL allows for the file content to be downloaded both in Jira Server and in Jira Cloud.