I want try transfer my bash script from linux to powershell but cant understand why it failed.
Linux command:
wget -q -x --user-agent="blablabla" --keep-session-cookies --load-cookies cook.txt http://site.com/qqq
powershell code:
$source = "http://site.com/qqq"
$destination = "d:\site\qqq"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($source, $destination)
but this code only download page without cookies. And i cant find how i can send PHPSESSID to site.
Please explain to me how to do it.
Ok so you have two options.
The first one is easy, just download the Windows version of wget.
Here is the code for the second one.
$source = "http://site.com/qqq"
$destination = "d:\site\qqq"
$wc = New-Object System.Net.WebClient
# Single Example
$wc.Headers.Add([System.Net.HttpRequestHeader]::Cookie, "name=value")
# Multi Example
$wc.Headers.Add([System.Net.HttpRequestHeader]::Cookie, "name=value; name2=value2");
$wc.DownloadFile($source, $destination)
Look inside your cookies.txt file to get the name value pairs.
I'm not sure how to replicate the -x
functionality of wget
. Give the above a try and see what it does with the file after downloading.
Note - I can't test this...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With