下载几秒钟后,PowerShell WebClient.DownloadFile()停止

时间:2020-06-03 09:02:29

标签: powershell

该程序应该将两个文件下载到一个目录中,但是当我运行该程序时,第一个20KB下载会停止。

这是我的代码:

$javaURL = "https://download.oracle.com/otn-pub/java/jdk/14.0.1+7/664493ef4a6946b186ff29eb326336a2/jdk-14.0.1_windows-x64_bin.exe"
$eclipseURL = "https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2020-03/R/eclipse-inst-win64.exe&mirror_id=1099"

$outpathJava = "C:\myPath\file1.exe"
$outpathEclipse = "C:\myPath\file.exe"

$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($javaURL, $outpathJava)
$webClient.DownloadFile($eclipseURL, $outpathEclipse)

1 个答案:

答案 0 :(得分:1)

如果使用浏览器导航至刚刚共享的链接,您将看到这些链接不是可执行文件。

对于Java,如果以文本文件file1.exe打开,则会看到类似以下内容的

<html>
<head>
<title>Unauthorized Request</title>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<link rel="stylesheet" type="text/css" href="/errors/us/assets/hp-styles.css" />
<link rel="stylesheet" type="text/css" href="/errors/us/assets/master-master.css" />

<body style="margin: 0px" bgcolor=#ffffff>
<div id="banner">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td rowspan="2" valign="middle" nowrap><a href="http://www.oracle.com"><img src="/errors/us/assets/oralogo-small.gif" width="154" height="19" hspace="10" vspace="25" border="0" ></a></td>
      <td align="right" valign="top" width="70%" nowrap class="padMid"><div id="bannerMid"> </div></td>

      <td width="30%" align="left" valign="bottom" nowrap></td>
    </tr>
    <tr>
      <td align="right" valign="bottom" nowrap class="padMid"></td>
      <td width="30%" align="left" valign="bottom" nowrap></td>
    </tr>
  </table>
</div>
<!-- Header END //-->
<table  BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
...

eclipse链接类似。

我建议您也许使用Chocolatey来安装软件。

Eclipse Java

安装Chocolatey:https://chocolatey.org/install

然后以Powershell(以管理员身份)进入:

choco install eclipse