Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download web content through CMD

I want some way of getting an online content on the command prompt window (Windows CMD).

Imagine some content online stored either on a hosting service or the MySql database provided to you by that hosting service. It can be any data stored in any form. I just want to remotely view it with the help of a CMD window anywhere in the world. What command should I be using?

To make it more clear, lets just say you have one day to prepare for your exam. Rather than preparing for it, you are making a plan to cheat.

Now your exam is going to be conducted on a computer that has been allotted to you and you are not allowed to use a browser or download any new application on the PC. But you can use Command Prompt, so your task being a cheat is to put the answers somewhere online. You cannot install anything new.

How will you go about if you are stuck in the above scene?

P.S This is for educational purpose only. I have no such such exams.

like image 206
Prakhar Sharma Avatar asked Mar 20 '26 16:03

Prakhar Sharma


2 Answers

Windows 10 build 17063 and later ships curl.exe (ref: https://techcommunity.microsoft.com/t5/containers/tar-and-curl-come-to-windows/ba-p/382409). Assuming you don't need to support earlier Windows versions, including earlier Windows 10 builds, you can use it in your batch files like this

curl http://example.com/ --output content.txt
notepad content.txt
like image 195
Esme Povirk Avatar answered Mar 22 '26 13:03

Esme Povirk


It depends entirely on how the content is stored and accessed. CMD knows how to get things from SMB network shares (\computername\folder), but you need to run a program to access most other stuff. (eg: sqlcmd for a database)

CMD does not support downloading web content. You will need to use another program to connect to the website and download the page. Obviously a browser would work. Another option is to download wget.exe from UnxUtils. Or use another scripting language like PowerShell or Wscript.

If you have access to launch PowerShell (pre-installed on Windows 7-10), you can use the .NET library to download web resources.

PS> Invoke-Webrequest 'www.mywebsite.com/myfile.txt' -OutFile '.\myfile.txt'

This will use .NET to connect to the page and download it into the local directory. To download to another directory or filename, change the -OutFile argument.

To launch this from CMD, go into a PowerShell prompt by simply typing powershell in CMD, and running the PS commands from there. Alternatively, you can run PS commands from CMD using the powershell -c command.

powershell.exe -c "invoke-webrequest 'www.mywebsite.com/myfile.txt' -outfile .\myfile.txt"
like image 29
Ryan Bemrose Avatar answered Mar 22 '26 13:03

Ryan Bemrose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!