使用 http 复制 Windows 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/607625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows file copy using http
提问by Pablote
Is there a windows command to copy or download files from a http url to the filesystem? I've tried with copy, xcopy and robocopy and they dont seem to support http urls.
是否有 Windows 命令可以将文件从 http url 复制或下载到文件系统?我尝试过使用 copy、xcopy 和 robocopy,但它们似乎不支持 http url。
回答by notandy
You can use a powershell script to accomplish this.
Get-Web http://www.msn.com/-toFile www.msn.com.html
您可以使用 powershell 脚本来完成此操作。
Get-Web http://www.msn.com/-toFile www.msn.com.html
function Get-Web($url,
[switch]$self,
$credential,
$toFile,
[switch]$bytes)
{
#.Synopsis
# Downloads a file from the web
#.Description
# Uses System.Net.Webclient (not the browser) to download data
# from the web.
#.Parameter self
# Uses the default credentials when downloading that page (for downloading intranet pages)
#.Parameter credential
# The credentials to use to download the web data
#.Parameter url
# The page to download (e.g. www.msn.com)
#.Parameter toFile
# The file to save the web data to
#.Parameter bytes
# Download the data as bytes
#.Example
# # Downloads www.live.com and outputs it as a string
# Get-Web http://www.live.com/
#.Example
# # Downloads www.live.com and saves it to a file
# Get-Web http://wwww.msn.com/ -toFile www.msn.com.html
$webclient = New-Object Net.Webclient
if ($credential) {
$webClient.Credential = $credential
}
if ($self) {
$webClient.UseDefaultCredentials = $true
}
if ($toFile) {
if (-not "$toFile".Contains(":")) {
$toFile = Join-Path $pwd $toFile
}
$webClient.DownloadFile($url, $toFile)
} else {
if ($bytes) {
$webClient.DownloadData($url)
} else {
$webClient.DownloadString($url)
}
}
}
回答by ayaz
回答by zehnaseeb
Use BITSAdmin Tool(bitsadmin is a command line utility on windows)
使用BITSAdmin 工具(bitsadmin 是 Windows 上的命令行实用程序)
example :
例子 :
bitsadmin /transfer "Download_Job" /download /priority high "http://www.sourceWebSite.com/file.zip" "C:\destination\file.zip"
where, Download_Job - Any relevant job name you want
其中,Download_Job - 您想要的任何相关工作名称
回答by Serge Wautier
回答by Serge Wautier
Just use Win32 api (1 line of code in C...)
只需使用 Win32 api(C 中的 1 行代码...)
回答by begray
I can't remember any command line utility for this. Maybe you can implement something similar using JavaScript (with WinHttpRequest) and running it like that:
我不记得任何用于此的命令行实用程序。也许您可以使用 JavaScript(使用 WinHttpRequest)实现类似的东西并像这样运行它:
wscript your_script.js
Or just install msys with wget.
或者直接用 wget 安装 msys。