# How to read from a text file being hosted on a website in a batch file

I want to read the contents of a text file line by line being hosted on a website with a batch file. Ex: from example.com/text.txt

@echo off
for /f "tokens=*" %%A in (http://example.com/text.txt) do (echo%%A)


But it looks for a file named that not the url.

• run for /f to see what is supported. Looks like http was not on the list Jul 15, 2018 at 16:44

Assuming you are on a Windows that supports powershell and you are using batch (otherwise just use Powershell and directly use the command in quotes):

@echo off
for /f "tokens=*" %%A in (txtfile.txt) do (echo%%A)


The 2nd line will download the text.txt file from the specified link and save it as txtfile.txt in the same directory.

EDIT: If you have a newer Windows version that supports PowerShell 3.0 and up, check @rahuldottech's answer, it's simpler and faster.

You can use the following code:

powershell wget http://example.com/file.txt -OutFile file.txt
for /f "tokens=*" %%A in (file.txt) do (echo%%A)


We use powershell to download the file, and then process it in batch. Using wget is simpler than creating an object and then downloading the file.

• This requires PowerShell 3.0 or newer so it does not work on eg. Windows 7. Jun 28, 2018 at 12:06
• Since wget is only an alias Get-Alias -Definition Invoke-WebRequest for Invoke-WebRequest I'd use the real/underlying cmdlet name. Jun 28, 2018 at 16:40
• @KonradBotor Things may need to be upgraded, but Windows 7 SP1 supports PowerShell versions 3.0 - 5.1 per Microsoft. Jun 28, 2018 at 17:22
• It supports newer versions of PowerShell, but comes preinstalled with version 2.0 and I doubt somebody who wants to use a batch script has upgraded it to newer version. Jun 28, 2018 at 18:03
• @lotpings why? Aliases exist to make life easier
– undo
Jun 28, 2018 at 20:33

call winhhtpjs.bat http://example.com/text.txt -saveTo c:\text.txt
for /f "usebackq tokens=*" %%A in ("c:\text.txt") do (echo%%A)


More on how you can download a file with a batch file

• While this technically works, it may cause issues with HTTPS and unusual headers. It's better to use powershell (which is built-in) because it has commands designed specifically to download files and there's no hackery involved
– undo
Jun 28, 2018 at 12:05
• @rahuldottech - powershell is not installed by default on XP,Vista and Windows Server 2003. In these cases using the activex objects for internet download is probably the only option. Jun 28, 2018 at 12:12
• @nlocmaka in those cases, you can use VBS. Plenty of scripts on the internet. That said, using an unsupported version of Windows is highly discouraged
– undo
Jun 28, 2018 at 12:13
• @rahuldottech - this is basically VBS (well... jscript which is also WSH language) and is pretty backward compatible. Though at the end it is matter of personal preferences what approach will be used. Probably I'll prefer powershell too in the most of cases as it ...powerful :) Jun 28, 2018 at 12:18

@echo off
Color 0A