Windows批处理文件从URL下载 [英] Windows batch file file download from a URL

查看:162
本文介绍了Windows批处理文件从URL下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从网站下载文件(例如 http://www.foo.com/package.zip )使用Windows批处理文件。当我写下面的功能时,我收到错误代码:

I am trying to download a file from a website (ex. http://www.foo.com/package.zip) using a Windows batch file. I am getting an error code when I write the function below:

xcopy /E /Y "http://www.foo.com/package.zip"

批处理文件似乎不像/ http。有没有办法逃避这些字符,所以它不认为它们是函数参数?

The batch file doesn't seem to like the "/" after the http. Are there any ways to escape those characters so it doesn't assume they are function parameters?

推荐答案

使用PowerShell 2.0(Windows 7预装)可以使用:

With PowerShell 2.0 (Windows 7 preinstalled) you can use:

(New-Object Net.WebClient).DownloadFile('http://www.foo.com/package.zip', 'package.zip')

从PowerShell 3.0开始(Windows 8预装),您可以使用 Invoke-WebRequest

Starting with PowerShell 3.0 (Windows 8 preinstalled) you can use Invoke-WebRequest:

Invoke-WebRequest http://www.foo.com/package.zip -OutFile package.zip

从批处理文件中调用它们:

From a batch file they are called:

powershell -Command "(New-Object Net.WebClient).DownloadFile('http://www.foo.com/package.zip', 'package.zip')"
powershell -Command "Invoke-WebRequest http://www.foo.com/package.zip -OutFile package.zip"

(PowerShe II 2.0可用于XP,3.0 for Windows 7上安装)

(PowerShell 2.0 is available for installation on XP, 3.0 for Windows 7)

这篇关于Windows批处理文件从URL下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆