Wget – Fix Not Saving File After Download

powershellwget

So I am currently using the wget command on windows 10 powershell to download various files. However, when testing this command, files do not actually download.

For example, say I want to download an image, say https://picsum.photos/200, I would use the following command:

PS C:\Users\myname\Desktop> wget https://picsum.photos/200

Which returns an apparently successful result:

StatusCode        : 200
StatusDescription : OK
Content           : {255, 216, 255, 224...}
RawContent        : HTTP/1.1 200 OK
                Access-Control-Expose-Headers: Content-Length
                Content-Disposition: inline;filename=""
                Vary: Origin
                Access-Control-Allow-Origin: *
                X-Content-Type-Options: nosniff
                X-XSS-Protection...
Headers           : {[Access-Control-Expose-Headers, Content-Length], [Content-Disposition, inline;filename=""],
                [Vary, Origin], [Access-Control-Allow-Origin, *]...}
RawContentLength  : 31273

Once this process finishes, I do not observe any new files on my desktop.

However, this code does work:

wget https://picsum.photos/200 -O image.jpg

So what is going on? Why does wget alone not download the file?

Best Answer

The Powershell implementation of wget is not wget. So it doesn't behave like the UNIX/Linux utility wget.

As pointed out by user4556274, Powershell uses wget and curl as aliases for its own Invoke-WebRequest.

Looking at that (or running Get-Help wget under Powershell) it can be seen that the -O [filename] flag is an acceptable abbreviation for -Output [filename], and that Invoke-WebRequest [URI] actually returns an object representing a web page rather than writing a file named from the basename of the URL.

Thus, this returns "nothing" unless you assign it to a variable or pipe it to another command:

wget http://example.net/path/to/page.html

But this delivers a web page "as expected":

wget http://example.net/path/to/page.html -O page.html
Related Question