Windows批处理文件从一个URL下载。

时间:2022-01-19 02:23:20

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

我正在尝试使用一个Windows批处理文件从一个网站下载一个文件(http://www.example.com/package.zip)。当我写下面的函数时,我得到一个错误代码:

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

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?

批处理文件似乎不喜欢http之后的“/”。有没有什么方法可以避免这些字符,所以它不认为它们是函数参数?

18 个解决方案

#1


86  

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

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

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

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

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

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

From a batch file they are called:

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

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

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

(PowerShell 2.0可以在XP上安装,Windows 7的3.0版本)

#2


79  

There's a standard Windows component which can achieve what you're trying to do: BITS. It has been included in Windows since XP and 2000 SP3.

有一个标准的Windows组件可以实现你想要做的事情:比特。它已经被包括在Windows XP和2000 SP3中。

Run:

运行:

bitsadmin.exe /transfer "JobName" http://download.url/here.exe C:\destination\here.exe

The job name is simply the display name for the download job - set it to something that describes what you're doing.

作业名称只是下载作业的显示名称——将其设置为描述您正在做的事情的内容。

#3


27  

This might be a little off topic, but you can pretty easily download a file using Powershell. Powershell comes with modern versions of Windows so you don't have to install any extra stuff on the computer. I learned how to do it by reading this page:

这可能有点偏离主题,但是您可以很容易地使用Powershell下载文件。Powershell提供了现代版本的Windows,所以你不必在电脑上安装任何额外的东西。我通过阅读这一页学会了如何做到这一点:

http://teusje.wordpress.com/2011/02/19/download-file-with-powershell/

http://teusje.wordpress.com/2011/02/19/download-file-with-powershell/

The code was:

的代码是:

$webclient = New-Object System.Net.WebClient
$url = "http://www.example.com/file.txt"
$file = "$pwd\file.txt"
$webclient.DownloadFile($url,$file)

#4


22  

Last I checked, there isn't a command line command to connect to a URL from the MS command line. Try wget for Windows:
http://gnuwin32.sourceforge.net/packages/wget.htm

最后我检查了,没有命令行命令从MS命令行连接到一个URL。尝试Windows: http://gnuwin32 sourceforge.net/packages/wget.htm。

or URL2File:
http://www.chami.com/free/url2file_wincon.html

或URL2File:http://www.chami.com/free/url2file_wincon.html

In Linux, you can use "wget".

在Linux中,您可以使用“wget”。

Alternatively, you can try VBScript. They are like command line programs, but they are scripts interpreted by the wscript.exe scripts host. Here is an example of downloading a file using VBS:
https://serverfault.com/questions/29707/download-file-from-vbscript

或者,您可以尝试VBScript。它们类似于命令行程序,但它们是由wscript解释的脚本。exe脚本主机。这里有一个使用VBS下载文件的示例:https://serverfault.com/questions/29707/download-vbscript。

#5


11  

' Create an HTTP object
myURL = "http://www.google.com"
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send
intStatus = objHTTP.Status

If intStatus = 200 Then
  WScript.Echo " " & intStatus & " A OK " +myURL
Else
  WScript.Echo "OOPS" +myURL
End If

then

然后

C:\>cscript geturl.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

200 A OK http://www.google.com

or just double click it to test in windows

或者双击它在windows中进行测试。

#6


5  

AFAIK, Windows doesn't have a built-in commandline tool to download a file. But you can do it from a VBScript, and you can generate the VBScript file from batch using echo and output redirection:

AFAIK, Windows没有内置的命令行工具来下载文件。但是您可以从一个VBScript中完成,您可以使用echo和输出重定向来从批处理生成VBScript文件:

@echo off

rem Windows has no built-in wget or curl, so generate a VBS script to do it:
rem -------------------------------------------------------------------------
set DLOAD_SCRIPT=download.vbs
echo Option Explicit                                                    >  %DLOAD_SCRIPT%
echo Dim args, http, fileSystem, adoStream, url, target, status         >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo Set args = Wscript.Arguments                                       >> %DLOAD_SCRIPT%
echo Set http = CreateObject("WinHttp.WinHttpRequest.5.1")              >> %DLOAD_SCRIPT%
echo url = args(0)                                                      >> %DLOAD_SCRIPT%
echo target = args(1)                                                   >> %DLOAD_SCRIPT%
echo WScript.Echo "Getting '" ^& target ^& "' from '" ^& url ^& "'..."  >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo http.Open "GET", url, False                                        >> %DLOAD_SCRIPT%
echo http.Send                                                          >> %DLOAD_SCRIPT%
echo status = http.Status                                               >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo If status ^<^> 200 Then                                            >> %DLOAD_SCRIPT%
echo    WScript.Echo "FAILED to download: HTTP Status " ^& status       >> %DLOAD_SCRIPT%
echo    WScript.Quit 1                                                  >> %DLOAD_SCRIPT%
echo End If                                                             >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo Set adoStream = CreateObject("ADODB.Stream")                       >> %DLOAD_SCRIPT%
echo adoStream.Open                                                     >> %DLOAD_SCRIPT%
echo adoStream.Type = 1                                                 >> %DLOAD_SCRIPT%
echo adoStream.Write http.ResponseBody                                  >> %DLOAD_SCRIPT%
echo adoStream.Position = 0                                             >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo Set fileSystem = CreateObject("Scripting.FileSystemObject")        >> %DLOAD_SCRIPT%
echo If fileSystem.FileExists(target) Then fileSystem.DeleteFile target >> %DLOAD_SCRIPT%
echo adoStream.SaveToFile target                                        >> %DLOAD_SCRIPT%
echo adoStream.Close                                                    >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
rem -------------------------------------------------------------------------

cscript //Nologo %DLOAD_SCRIPT% http://example.com targetPathAndFile.html

More explanation here

更多的解释

#7


4  

  1. Download Wget from here http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe

    从这里下载Wget, http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe。

  2. Then install it.

    然后安装它。

  3. Then make some .bat file and put this into it

    然后做一些。bat文件,并把它放入其中。

    @echo off
    
    for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set y=%%k
    for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set d=%%k%%i%%j
    for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set t=%%i%%j
    set t=%t%_
    if "%t:~3,1%"=="_" set t=0%t%
    set t=%t:~0,4%
    set "theFilename=%d%%t%"
    echo %theFilename%
    
    
    cd "C:\Program Files\GnuWin32\bin"
    wget.exe --output-document C:\backup\file_%theFilename%.zip http://someurl/file.zip
    
  4. Adjust the URL and the file path in the script

    调整脚本中的URL和文件路径。

  5. Run the file and profit!
  6. 运行文件和利润!

#8


3  

If bitsadmin isn't your cup of tea, you can use this PowerShell command:

如果bitsadmin不是您的cup of tea,您可以使用这个PowerShell命令:

Start-BitsTransfer -Source http://www.foo.com/package.zip -Destination C:\somedir\package.zip

#9


3  

Use Bat To Exe Converter

Create a batch file and put something like the code below into it

使用Bat到Exe转换器创建一个批处理文件,并将如下代码放入其中。

%extd% /download http://www.examplesite.com/file.zip file.zip

or

%extd% /download http://*.com/questions/4619088/windows-batch-file-file-download-from-a-url thistopic.html

and convert it to exe.

把它转化为exe。

#10


2  

You cannot use xcopy over http. Try downloading wget for windows. That may do the trick. It is a command line utility for non-interactive download of files through http. You can get it at http://gnuwin32.sourceforge.net/packages/wget.htm

您不能在http上使用xcopy。尝试下载wget窗口。这可能会奏效。它是通过http进行非交互式下载文件的命令行实用程序。您可以在http://gnuwin32 sourceforge.net/packages/wget.htm获得它。

#11


2  

BATCH may not be able to do this, but you can use JScript or VBScript if you don't want to use tools that are not installed by default with Windows.

批处理可能无法做到这一点,但是如果您不想使用默认安装在Windows上的工具,那么您可以使用JScript或VBScript。

The first example on this page downloads a binary file in VBScript: http://www.robvanderwoude.com/vbstech_internet_download.php

这个页面的第一个示例下载了VBScript中的二进制文件:http://www.robvanderwoude.com/vbstech_internet_download.php。

This SO answer downloads a file using JScript (IMO, the better language): Windows Script Host (jscript): how do i download a binary file?

因此,使用JScript (IMO,更好的语言)下载一个文件:Windows脚本主机(JScript):如何下载二进制文件?

Your batch script can then just call out to a JScript or VBScript that downloads the file.

您的批处理脚本可以调用一个JScript或VBScript来下载该文件。

#12


2  

This should work i did the following for a game server project. It will download the zip and extract it to what ever directory you specify.

我为一个游戏服务器项目做了以下工作。它将下载zip并将其解压到您指定的目录中。

Save as name.bat or name.cmd

另存为的名字。蝙蝠或name.cmd

@echo off
set downloadurl=http://media.steampowered.com/installer/steamcmd.zip
set downloadpath=C:\steamcmd\steamcmd.zip
set directory=C:\steamcmd\
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Import-Module BitsTransfer;Start-BitsTransfer '%downloadurl%' '%downloadpath%';$shell = new-object -com shell.application;$zip = $shell.NameSpace('%downloadpath%');foreach($item in $zip.items()){$shell.Namespace('%directory%').copyhere($item);};remove-item '%downloadpath%';}"
echo download complete and extracted to the directory.
pause

Original : https://github.com/C0nw0nk/SteamCMD-AutoUpdate-Any-Gameserver/blob/master/steam.cmd

原:https://github.com/C0nw0nk/SteamCMD-AutoUpdate-Any-Gameserver/blob/master/steam.cmd

#13


1  

I found this VB script:

我发现这个VB脚本:

http://www.olafrv.com/?p=385

http://www.olafrv.com/?p=385

Works like a charm. Configured as a function with a very simple function call:

就像一个魅力。配置为具有非常简单函数调用的函数:

SaveWebBinary "http://server/file1.ext1", "C:/file2.ext2"

Originally from: http://www.ericphelps.com/scripting/samples/BinaryDownload/index.htm

来自:http://www.ericphelps.com/scripting/samples/BinaryDownload/index.htm

Here is the full code for redundancy:

下面是冗余的完整代码:

Function SaveWebBinary(strUrl, strFile) 'As Boolean
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const ForWriting = 2
Dim web, varByteArray, strData, strBuffer, lngCounter, ado
    On Error Resume Next
    'Download the file with any available object
    Err.Clear
    Set web = Nothing
    Set web = CreateObject("WinHttp.WinHttpRequest.5.1")
    If web Is Nothing Then Set web = CreateObject("WinHttp.WinHttpRequest")
    If web Is Nothing Then Set web = CreateObject("MSXML2.ServerXMLHTTP")
    If web Is Nothing Then Set web = CreateObject("Microsoft.XMLHTTP")
    web.Open "GET", strURL, False
    web.Send
    If Err.Number <> 0 Then
        SaveWebBinary = False
        Set web = Nothing
        Exit Function
    End If
    If web.Status <> "200" Then
        SaveWebBinary = False
        Set web = Nothing
        Exit Function
    End If
    varByteArray = web.ResponseBody
    Set web = Nothing
    'Now save the file with any available method
    On Error Resume Next
    Set ado = Nothing
    Set ado = CreateObject("ADODB.Stream")
    If ado Is Nothing Then
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set ts = fs.OpenTextFile(strFile, ForWriting, True)
        strData = ""
        strBuffer = ""
        For lngCounter = 0 to UBound(varByteArray)
            ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1)))
        Next
        ts.Close
    Else
        ado.Type = adTypeBinary
        ado.Open
        ado.Write varByteArray
        ado.SaveToFile strFile, adSaveCreateOverWrite
        ado.Close
    End If
    SaveWebBinary = True
End Function

#14


1  

Instead of wget you can also use aria2 to download the file from a particular URL.

而不是wget,你也可以使用aria2从一个特定的URL下载文件。

See the following link which will explain more about aria2:

请参阅下面的链接,它将更多地解释aria2:

https://aria2.github.io/

https://aria2.github.io/

#15


1  

Downloading files in PURE BATCH.

A lot of people are saying it's impossible, but it's not! I wrote a very simple function and it's working well for most URLs. It's using the "bitsadmin" command for downloading files which is part of Windows by default. (No need to download of install anything).

很多人都说这是不可能的,但事实并非如此!我编写了一个非常简单的函数,它对大多数url都很有效。它使用“bitsadmin”命令下载文件,默认情况下是Windows的一部分。(不需要下载安装任何东西)。

No JScript, no VBScript, no Powershell... Only pure Batch!

没有JScript,没有VBScript,没有Powershell…只有纯批!

Enjoy!

享受吧!


Here is a simple script showing how to use use this function.

这里有一个简单的脚本,说明如何使用这个函数。

@echo off
setlocal


:VARIABLES

rem EINSTEIN PICTURE (URL)
SET "FILE_URL=http://www.deism.com/images/Einstein_laughing.jpeg"

rem SAVE FILE WHERE THE SCRIPT IS LOCATED (DEFAULT)
SET "SAVE_TO=%~dp0"
SET "SAVE_TO=%SAVE_TO%Einstein_laughing.jpeg"

rem SAVE FILE IN CUSTOM PATH
rem SET "SAVE_TO=C:\Folder\Einstein_laughing.jpeg"



:FUNCTION_CALL

rem HERE WE CALL OUR FUNCTION (WRITTEN BELOW) THEN WE EXIT THE SCRIPT
CALL :DOWNLOAD %FILE_URL% %SAVE_TO%

ECHO.
PAUSE & EXIT /B



rem DOWNLOAD FUNCTION

:DOWNLOAD

setlocal

SET "_URL_=%1"
SET "_SAVE_TO_=%2"

ECHO.
ECHO DOWNLOADING: "%_URL_%"
ECHO SAVING TO:   "%_SAVE_TO_%"
ECHO.

bitsadmin /transfer mydownloadjob /download /priority normal "%_URL_%" "%_SAVE_TO_%"

rem BITSADMIN DOWNLOAD EXAMPLE
rem bitsadmin  /transfer mydownloadjob  /download  /priority normal http://example.com/filename.zip  C:\Users\username\Downloads\filename.zip

endlocal

GOTO :EOF

If you want more info about BITSadmin ...

如果您想了解更多关于BITSadmin的信息…

#16


0  

This question has very good answer in here. My code is purely based on that answer with some modifications.

这个问题在这里有很好的答案。我的代码完全基于这个答案,并进行了一些修改。

Save below snippet as wget.bat and put it in your system path (e.g. Put it in a directory and add this directory to system path.)

将下面的片段保存为wget。bat并将其放入您的系统路径(例如,将其放在目录中,并将该目录添加到系统路径中)。

You can use it in your cli as follows:

您可以在cli中使用它:

wget url/to/file [?custom_name]

wget url / /文件[? custom_name]

where url_to_file is compulsory and custom_name is optional

其中url_to_file是强制的,custom_name是可选的?

  1. If name is not provided, then downloaded file will be saved by its own name from the url.
  2. 如果没有提供名称,那么下载的文件将以自己的名称从url中保存。
  3. If the name is supplied, then the file will be saved by the new name.
  4. 如果提供了名称,则新名称将保存该文件。

The file url and saved filenames are displayed in ansi colored text. If that is causing problem for you, then check this github project.

文件url和保存的文件名显示在ansi彩色文本中。如果这对您造成了问题,那么请检查这个github项目。

@echo OFF
setLocal EnableDelayedExpansion
set Url=%1
set Url=!Url:http://=!
set Url=!Url:/=,!
set Url=!Url:%%20=?!
set Url=!Url: =?!

call :LOOP !Url!

set FileName=%2
if "%2"=="" set FileName=!FN!

echo.
echo.Downloading: [1;33m%1[0m to [1;33m\!FileName![0m

powershell.exe -Command wget %1 -OutFile !FileName!

goto :EOF
:LOOP
if "%1"=="" goto :EOF
set FN=%1
set FN=!FN:?= !
shift
goto :LOOP

P.S. This code requires you to have PowerShell installed.

这段代码要求您安装PowerShell。

#17


0  

You can setup a scheduled task using wget, use the “Run” field in scheduled task as:

您可以使用wget设置一个预定的任务,在预定任务中使用“Run”字段:

C:\wget\wget.exe -q -O nul "http://www.google.com/shedule.me"

#18


-2  

use ftp:

使用ftp:

(ftp *yourewebsite.com*-a)
cd *directory*
get *filename.doc*
close

Change everything in asterisks to fit your situation.

改变所有的星号来适应你的情况。

#1


86  

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

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

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

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

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

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

From a batch file they are called:

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

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

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

(PowerShell 2.0可以在XP上安装,Windows 7的3.0版本)

#2


79  

There's a standard Windows component which can achieve what you're trying to do: BITS. It has been included in Windows since XP and 2000 SP3.

有一个标准的Windows组件可以实现你想要做的事情:比特。它已经被包括在Windows XP和2000 SP3中。

Run:

运行:

bitsadmin.exe /transfer "JobName" http://download.url/here.exe C:\destination\here.exe

The job name is simply the display name for the download job - set it to something that describes what you're doing.

作业名称只是下载作业的显示名称——将其设置为描述您正在做的事情的内容。

#3


27  

This might be a little off topic, but you can pretty easily download a file using Powershell. Powershell comes with modern versions of Windows so you don't have to install any extra stuff on the computer. I learned how to do it by reading this page:

这可能有点偏离主题,但是您可以很容易地使用Powershell下载文件。Powershell提供了现代版本的Windows,所以你不必在电脑上安装任何额外的东西。我通过阅读这一页学会了如何做到这一点:

http://teusje.wordpress.com/2011/02/19/download-file-with-powershell/

http://teusje.wordpress.com/2011/02/19/download-file-with-powershell/

The code was:

的代码是:

$webclient = New-Object System.Net.WebClient
$url = "http://www.example.com/file.txt"
$file = "$pwd\file.txt"
$webclient.DownloadFile($url,$file)

#4


22  

Last I checked, there isn't a command line command to connect to a URL from the MS command line. Try wget for Windows:
http://gnuwin32.sourceforge.net/packages/wget.htm

最后我检查了,没有命令行命令从MS命令行连接到一个URL。尝试Windows: http://gnuwin32 sourceforge.net/packages/wget.htm。

or URL2File:
http://www.chami.com/free/url2file_wincon.html

或URL2File:http://www.chami.com/free/url2file_wincon.html

In Linux, you can use "wget".

在Linux中,您可以使用“wget”。

Alternatively, you can try VBScript. They are like command line programs, but they are scripts interpreted by the wscript.exe scripts host. Here is an example of downloading a file using VBS:
https://serverfault.com/questions/29707/download-file-from-vbscript

或者,您可以尝试VBScript。它们类似于命令行程序,但它们是由wscript解释的脚本。exe脚本主机。这里有一个使用VBS下载文件的示例:https://serverfault.com/questions/29707/download-vbscript。

#5


11  

' Create an HTTP object
myURL = "http://www.google.com"
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send
intStatus = objHTTP.Status

If intStatus = 200 Then
  WScript.Echo " " & intStatus & " A OK " +myURL
Else
  WScript.Echo "OOPS" +myURL
End If

then

然后

C:\>cscript geturl.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

200 A OK http://www.google.com

or just double click it to test in windows

或者双击它在windows中进行测试。

#6


5  

AFAIK, Windows doesn't have a built-in commandline tool to download a file. But you can do it from a VBScript, and you can generate the VBScript file from batch using echo and output redirection:

AFAIK, Windows没有内置的命令行工具来下载文件。但是您可以从一个VBScript中完成,您可以使用echo和输出重定向来从批处理生成VBScript文件:

@echo off

rem Windows has no built-in wget or curl, so generate a VBS script to do it:
rem -------------------------------------------------------------------------
set DLOAD_SCRIPT=download.vbs
echo Option Explicit                                                    >  %DLOAD_SCRIPT%
echo Dim args, http, fileSystem, adoStream, url, target, status         >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo Set args = Wscript.Arguments                                       >> %DLOAD_SCRIPT%
echo Set http = CreateObject("WinHttp.WinHttpRequest.5.1")              >> %DLOAD_SCRIPT%
echo url = args(0)                                                      >> %DLOAD_SCRIPT%
echo target = args(1)                                                   >> %DLOAD_SCRIPT%
echo WScript.Echo "Getting '" ^& target ^& "' from '" ^& url ^& "'..."  >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo http.Open "GET", url, False                                        >> %DLOAD_SCRIPT%
echo http.Send                                                          >> %DLOAD_SCRIPT%
echo status = http.Status                                               >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo If status ^<^> 200 Then                                            >> %DLOAD_SCRIPT%
echo    WScript.Echo "FAILED to download: HTTP Status " ^& status       >> %DLOAD_SCRIPT%
echo    WScript.Quit 1                                                  >> %DLOAD_SCRIPT%
echo End If                                                             >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo Set adoStream = CreateObject("ADODB.Stream")                       >> %DLOAD_SCRIPT%
echo adoStream.Open                                                     >> %DLOAD_SCRIPT%
echo adoStream.Type = 1                                                 >> %DLOAD_SCRIPT%
echo adoStream.Write http.ResponseBody                                  >> %DLOAD_SCRIPT%
echo adoStream.Position = 0                                             >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
echo Set fileSystem = CreateObject("Scripting.FileSystemObject")        >> %DLOAD_SCRIPT%
echo If fileSystem.FileExists(target) Then fileSystem.DeleteFile target >> %DLOAD_SCRIPT%
echo adoStream.SaveToFile target                                        >> %DLOAD_SCRIPT%
echo adoStream.Close                                                    >> %DLOAD_SCRIPT%
echo.                                                                   >> %DLOAD_SCRIPT%
rem -------------------------------------------------------------------------

cscript //Nologo %DLOAD_SCRIPT% http://example.com targetPathAndFile.html

More explanation here

更多的解释

#7


4  

  1. Download Wget from here http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe

    从这里下载Wget, http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe。

  2. Then install it.

    然后安装它。

  3. Then make some .bat file and put this into it

    然后做一些。bat文件,并把它放入其中。

    @echo off
    
    for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set y=%%k
    for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set d=%%k%%i%%j
    for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set t=%%i%%j
    set t=%t%_
    if "%t:~3,1%"=="_" set t=0%t%
    set t=%t:~0,4%
    set "theFilename=%d%%t%"
    echo %theFilename%
    
    
    cd "C:\Program Files\GnuWin32\bin"
    wget.exe --output-document C:\backup\file_%theFilename%.zip http://someurl/file.zip
    
  4. Adjust the URL and the file path in the script

    调整脚本中的URL和文件路径。

  5. Run the file and profit!
  6. 运行文件和利润!

#8


3  

If bitsadmin isn't your cup of tea, you can use this PowerShell command:

如果bitsadmin不是您的cup of tea,您可以使用这个PowerShell命令:

Start-BitsTransfer -Source http://www.foo.com/package.zip -Destination C:\somedir\package.zip

#9


3  

Use Bat To Exe Converter

Create a batch file and put something like the code below into it

使用Bat到Exe转换器创建一个批处理文件,并将如下代码放入其中。

%extd% /download http://www.examplesite.com/file.zip file.zip

or

%extd% /download http://*.com/questions/4619088/windows-batch-file-file-download-from-a-url thistopic.html

and convert it to exe.

把它转化为exe。

#10


2  

You cannot use xcopy over http. Try downloading wget for windows. That may do the trick. It is a command line utility for non-interactive download of files through http. You can get it at http://gnuwin32.sourceforge.net/packages/wget.htm

您不能在http上使用xcopy。尝试下载wget窗口。这可能会奏效。它是通过http进行非交互式下载文件的命令行实用程序。您可以在http://gnuwin32 sourceforge.net/packages/wget.htm获得它。

#11


2  

BATCH may not be able to do this, but you can use JScript or VBScript if you don't want to use tools that are not installed by default with Windows.

批处理可能无法做到这一点,但是如果您不想使用默认安装在Windows上的工具,那么您可以使用JScript或VBScript。

The first example on this page downloads a binary file in VBScript: http://www.robvanderwoude.com/vbstech_internet_download.php

这个页面的第一个示例下载了VBScript中的二进制文件:http://www.robvanderwoude.com/vbstech_internet_download.php。

This SO answer downloads a file using JScript (IMO, the better language): Windows Script Host (jscript): how do i download a binary file?

因此,使用JScript (IMO,更好的语言)下载一个文件:Windows脚本主机(JScript):如何下载二进制文件?

Your batch script can then just call out to a JScript or VBScript that downloads the file.

您的批处理脚本可以调用一个JScript或VBScript来下载该文件。

#12


2  

This should work i did the following for a game server project. It will download the zip and extract it to what ever directory you specify.

我为一个游戏服务器项目做了以下工作。它将下载zip并将其解压到您指定的目录中。

Save as name.bat or name.cmd

另存为的名字。蝙蝠或name.cmd

@echo off
set downloadurl=http://media.steampowered.com/installer/steamcmd.zip
set downloadpath=C:\steamcmd\steamcmd.zip
set directory=C:\steamcmd\
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Import-Module BitsTransfer;Start-BitsTransfer '%downloadurl%' '%downloadpath%';$shell = new-object -com shell.application;$zip = $shell.NameSpace('%downloadpath%');foreach($item in $zip.items()){$shell.Namespace('%directory%').copyhere($item);};remove-item '%downloadpath%';}"
echo download complete and extracted to the directory.
pause

Original : https://github.com/C0nw0nk/SteamCMD-AutoUpdate-Any-Gameserver/blob/master/steam.cmd

原:https://github.com/C0nw0nk/SteamCMD-AutoUpdate-Any-Gameserver/blob/master/steam.cmd

#13


1  

I found this VB script:

我发现这个VB脚本:

http://www.olafrv.com/?p=385

http://www.olafrv.com/?p=385

Works like a charm. Configured as a function with a very simple function call:

就像一个魅力。配置为具有非常简单函数调用的函数:

SaveWebBinary "http://server/file1.ext1", "C:/file2.ext2"

Originally from: http://www.ericphelps.com/scripting/samples/BinaryDownload/index.htm

来自:http://www.ericphelps.com/scripting/samples/BinaryDownload/index.htm

Here is the full code for redundancy:

下面是冗余的完整代码:

Function SaveWebBinary(strUrl, strFile) 'As Boolean
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const ForWriting = 2
Dim web, varByteArray, strData, strBuffer, lngCounter, ado
    On Error Resume Next
    'Download the file with any available object
    Err.Clear
    Set web = Nothing
    Set web = CreateObject("WinHttp.WinHttpRequest.5.1")
    If web Is Nothing Then Set web = CreateObject("WinHttp.WinHttpRequest")
    If web Is Nothing Then Set web = CreateObject("MSXML2.ServerXMLHTTP")
    If web Is Nothing Then Set web = CreateObject("Microsoft.XMLHTTP")
    web.Open "GET", strURL, False
    web.Send
    If Err.Number <> 0 Then
        SaveWebBinary = False
        Set web = Nothing
        Exit Function
    End If
    If web.Status <> "200" Then
        SaveWebBinary = False
        Set web = Nothing
        Exit Function
    End If
    varByteArray = web.ResponseBody
    Set web = Nothing
    'Now save the file with any available method
    On Error Resume Next
    Set ado = Nothing
    Set ado = CreateObject("ADODB.Stream")
    If ado Is Nothing Then
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set ts = fs.OpenTextFile(strFile, ForWriting, True)
        strData = ""
        strBuffer = ""
        For lngCounter = 0 to UBound(varByteArray)
            ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1)))
        Next
        ts.Close
    Else
        ado.Type = adTypeBinary
        ado.Open
        ado.Write varByteArray
        ado.SaveToFile strFile, adSaveCreateOverWrite
        ado.Close
    End If
    SaveWebBinary = True
End Function

#14


1  

Instead of wget you can also use aria2 to download the file from a particular URL.

而不是wget,你也可以使用aria2从一个特定的URL下载文件。

See the following link which will explain more about aria2:

请参阅下面的链接,它将更多地解释aria2:

https://aria2.github.io/

https://aria2.github.io/

#15


1  

Downloading files in PURE BATCH.

A lot of people are saying it's impossible, but it's not! I wrote a very simple function and it's working well for most URLs. It's using the "bitsadmin" command for downloading files which is part of Windows by default. (No need to download of install anything).

很多人都说这是不可能的,但事实并非如此!我编写了一个非常简单的函数,它对大多数url都很有效。它使用“bitsadmin”命令下载文件,默认情况下是Windows的一部分。(不需要下载安装任何东西)。

No JScript, no VBScript, no Powershell... Only pure Batch!

没有JScript,没有VBScript,没有Powershell…只有纯批!

Enjoy!

享受吧!


Here is a simple script showing how to use use this function.

这里有一个简单的脚本,说明如何使用这个函数。

@echo off
setlocal


:VARIABLES

rem EINSTEIN PICTURE (URL)
SET "FILE_URL=http://www.deism.com/images/Einstein_laughing.jpeg"

rem SAVE FILE WHERE THE SCRIPT IS LOCATED (DEFAULT)
SET "SAVE_TO=%~dp0"
SET "SAVE_TO=%SAVE_TO%Einstein_laughing.jpeg"

rem SAVE FILE IN CUSTOM PATH
rem SET "SAVE_TO=C:\Folder\Einstein_laughing.jpeg"



:FUNCTION_CALL

rem HERE WE CALL OUR FUNCTION (WRITTEN BELOW) THEN WE EXIT THE SCRIPT
CALL :DOWNLOAD %FILE_URL% %SAVE_TO%

ECHO.
PAUSE & EXIT /B



rem DOWNLOAD FUNCTION

:DOWNLOAD

setlocal

SET "_URL_=%1"
SET "_SAVE_TO_=%2"

ECHO.
ECHO DOWNLOADING: "%_URL_%"
ECHO SAVING TO:   "%_SAVE_TO_%"
ECHO.

bitsadmin /transfer mydownloadjob /download /priority normal "%_URL_%" "%_SAVE_TO_%"

rem BITSADMIN DOWNLOAD EXAMPLE
rem bitsadmin  /transfer mydownloadjob  /download  /priority normal http://example.com/filename.zip  C:\Users\username\Downloads\filename.zip

endlocal

GOTO :EOF

If you want more info about BITSadmin ...

如果您想了解更多关于BITSadmin的信息…

#16


0  

This question has very good answer in here. My code is purely based on that answer with some modifications.

这个问题在这里有很好的答案。我的代码完全基于这个答案,并进行了一些修改。

Save below snippet as wget.bat and put it in your system path (e.g. Put it in a directory and add this directory to system path.)

将下面的片段保存为wget。bat并将其放入您的系统路径(例如,将其放在目录中,并将该目录添加到系统路径中)。

You can use it in your cli as follows:

您可以在cli中使用它:

wget url/to/file [?custom_name]

wget url / /文件[? custom_name]

where url_to_file is compulsory and custom_name is optional

其中url_to_file是强制的,custom_name是可选的?

  1. If name is not provided, then downloaded file will be saved by its own name from the url.
  2. 如果没有提供名称,那么下载的文件将以自己的名称从url中保存。
  3. If the name is supplied, then the file will be saved by the new name.
  4. 如果提供了名称,则新名称将保存该文件。

The file url and saved filenames are displayed in ansi colored text. If that is causing problem for you, then check this github project.

文件url和保存的文件名显示在ansi彩色文本中。如果这对您造成了问题,那么请检查这个github项目。

@echo OFF
setLocal EnableDelayedExpansion
set Url=%1
set Url=!Url:http://=!
set Url=!Url:/=,!
set Url=!Url:%%20=?!
set Url=!Url: =?!

call :LOOP !Url!

set FileName=%2
if "%2"=="" set FileName=!FN!

echo.
echo.Downloading: [1;33m%1[0m to [1;33m\!FileName![0m

powershell.exe -Command wget %1 -OutFile !FileName!

goto :EOF
:LOOP
if "%1"=="" goto :EOF
set FN=%1
set FN=!FN:?= !
shift
goto :LOOP

P.S. This code requires you to have PowerShell installed.

这段代码要求您安装PowerShell。

#17


0  

You can setup a scheduled task using wget, use the “Run” field in scheduled task as:

您可以使用wget设置一个预定的任务,在预定任务中使用“Run”字段:

C:\wget\wget.exe -q -O nul "http://www.google.com/shedule.me"

#18


-2  

use ftp:

使用ftp:

(ftp *yourewebsite.com*-a)
cd *directory*
get *filename.doc*
close

Change everything in asterisks to fit your situation.

改变所有的星号来适应你的情况。