0

I'm trying to use Curl to download a .zip File from Artifactory. For that I'm using

System.Diagnostics.Process()

Is there a Way to see how far the download progressed or is there a better Way to get a .zip File from Artifactory than my used approach? Here is the Code I'm using, grateful for any suggested improvements

System.Diagnostics.Process process = new System.Diagnostics.Process()
            {
                StartInfo = new System.Diagnostics.ProcessStartInfo()
                {
                    FileName = "curl",
                    Arguments = "-H \"X-JFrog-Art-Api:<Token>\" -X GET \"" + url + "\" -O \"" + path + "\"",
                    UseShellExecute = false,
                    CreateNoWindow = true,
                    RedirectStandardOutput = true
                }
            };
            process.Start();

            System.IO.StreamReader reader = process.StandardOutput;
            string output = reader.ReadToEnd();
            process.WaitForExit();
Deto24
  • 63
  • 5

1 Answers1

1

You should use an HttpClient and HttpRequestMessage like this:

(from https://stackoverflow.com/a/40707446/8800752)

        string baseURL = "";
        string path = "";
        string token = "";
        using (HttpClient client = new HttpClient())
        {
            client.BaseAddress = new Uri(baseURL);

            using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, path))
            {
                requestMessage.Headers.Add("X-JFrog-Art-Api", token);

                var response = client.Send(requestMessage);
            }
        }

You can change it to await + SendAsync and if you're going to make multiple calls, use a HttpFactory or make the client static.

LoLo2207
  • 103
  • 5
  • I tried this, but then I get a Byte Stream which I need to bring into a .zip File and I'm not 100% sure how to handle a Bytestream to .zip easily. Also, is there a way to log the Progress of the HttpRequestMessage? Like a % on how far the download progressed? – Deto24 Nov 09 '22 at 11:17
  • try with File.WriteAllBytes(path, bytes) – LoLo2207 Nov 09 '22 at 11:37