1

I created a Powershell script that contains a Curl command that downloads a file from one of my repos on Bitbucket. when I execute the script using Powershell, the file is nowhere to be found - I expected it to be inside the location where the Powershell script was but it is not there. I'm sure it downloaded because I can see the download count increase on Bitbucket every time I run the command. Here is the Powershell code - am I missing something?

curl.exe -s -u myUserName -X GET https://api.bitbucket.org/2.0/repositories/MyTeam/myRepo/downloads/Hello.txt
Roka545
  • 3,404
  • 20
  • 62
  • 106
  • 1
    It should be in the working directory when the command was executed. Perhaps in the root of your user folder C:\users\Roka545\hello.txt. I use [Everything by VoidTools](https://www.voidtools.com/) to help me locate files I know the names of. – Matt Aug 08 '17 at 18:43
  • Was the download successful? – Tobias Wollgam Aug 08 '17 at 18:53
  • As far as I can tell yes. The file is hosted on Bitbucket which contains a counter for the number of times it has been downloaded - it increments every time I run the command. I guess it's possible that the download fails - but I don't receive any error or message indicating that it does fail. Is there anyway to check that? – Roka545 Aug 08 '17 at 18:59
  • 1
    @Roka545 Do you have a response to my questions yet? Have you looked for this file on your machine yet to see if it was downloaded somewhere else. You can specify the output file as well https://stackoverflow.com/questions/9744973/is-there-a-way-to-give-a-specific-file-name-when-saving-a-file-via-curl-in-mac-o – Matt Aug 08 '17 at 19:16
  • @Matt The file isn't in the working directory and it isn't at the root. I will try specifying the output file when I am back to my dev computer and let you know how it goes. – Roka545 Aug 08 '17 at 20:31

1 Answers1

1

If you really want a proper status object to test for download, you can mirror CURL using:

$strUrl = "http://URL FILE"
$outFile = "C:\Outfile.zip"
$downloadStatus = (Invoke-WebRequest -Uri $strUrl -OutFile $outFile).statuscode

if($downloadStatus -ne 200)
 { 
     Write-Host "Download failed!" -Fore 'Red'
 }
 else
 {
     Write-Host "Download success!" -Fore 'Green'
 }
Collin Chaffin
  • 872
  • 9
  • 15