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:
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?
With PowerShell 2.0 (Windows 7 preinstalled) you can use:
(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
:
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)