使用Curl和Powershell下载后文件不存在

时间:2017-08-08 18:41:27

标签: powershell curl scripting

我创建了一个Powershell脚本,其中包含一个Curl命令,可以从Bitbucket上的一个repos下载文件。当我使用Powershell执行脚本时,文件无处可寻 - 我希望它位于Powershell脚本所在的位置,但它不在那里。我确定它已下载,因为每次运行命令时我都能看到Bitbucket的下载次数增加。这是Powershell代码 - 我错过了什么吗?

curl.exe -s -u myUserName -X GET https://api.bitbucket.org/2.0/repositories/MyTeam/myRepo/downloads/Hello.txt

1 个答案:

答案 0 :(得分:1)

如果您确实需要正确的状态对象来测试下载,可以使用以下方式镜像CURL:

$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'
 }