Invoke-WebRequest not downloading proper exe file - powershell-4.0

Using Powershell version 4.0 I'm trying to download Firefox browser programatically:
$uri = "https://www.mozilla.org/en-US/firefox/new/?scene=2"
$out = "C:\Users\bhatsubh\Downloads\Firefox Setup Stub 48.0.2.exe"
Invoke-WebRequest -Uri $uri -OutFile $out
But it is not downloading the correct file. Instead the file is the wrong one with a size of 65 KB.
When I copy-paste the URL in the web browser the download starts automatically and the correct file is downloaded with a size of 237 KB.

The site uses javascript to start the download, so the wrong file you're getting is actually HTML page. Looking at its source we can see the actual link of setup "stub":
https://download.mozilla.org/?product=firefox-stub&os=win&lang=en-US
It's also possible to download the full installer:
https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US

Here is the solution for you:
Use this command: Invoke-WebRequest $URL -OutFile 'c:\local-name.exe'
The problem is with your URL. The url you are using is not the exact one pointing to original exe.
So For getting correct URL, follow below steps
Start downloading required exe and cancel that download in Chrome Browser
Goto downloads and right-click and click "Copy link adress" and set that value to $URL varible and retry. This works in most of the cases.

Related

Deprecated: mysql_connect() message and Warnings occur in step 3 of the opencart configuration setup after we enter the details and hit continue

We need help trying to upload our opencart templatemonster.com template correctly on godaddy but we are not clear on how to do that.
FYI our public_html/system/database folder contains a mysqli.php file as well.
We made sure to upload the template via fullpackage (The name of the file is themeXXX(full).zip, where XXX is your theme number) to the public_html folder.
Extracted the zip files in the public_html folder.
Performed the installation using the installation manager .
At step 3 configuration we were prompted to input our database access details and made sure the database was empty. (GoDaddy told us to use the localhost)
After hitting continue:
The deprecated: mysql_connect() message and Warnings occur in step 3 of the opencart configuration setup after we enter the details and hit continue.
Where ‘store’ is the new directory name. Where ‘user’ is your server
account address. Where ‘yourdomainname.co.uk’ is the web domain of
your new website:
(DUMMY LINK FOR DEMONSTRATION PURPOSES) http://www.yourdomainname.co.uk/install/index.php?route=step_3
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/user /public_html/system/database/mysql.php on line 6
Lines 5-16:
public function __construct($hostname, $username, $password, $database) {
if (!$this->link = mysql_connect($hostname, $username, $password)) {
trigger_error('Error: Could not make a database link using ' . $username . '#' . $hostname);
}
if (!mysql_select_db($database, $this->link)) {
trigger_error('Error: Could not connect to database ' . $database);
}
Errors:
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/system/database/mysql.php:6) in /home/user/public_html/system/engine/controller.php on line 28
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/system/database/mysql.php:6) in /home/user/public_html/system/engine/controller.php on line 29
Lines 27-31
protected function redirect($url, $status = 302) {
header('Status: ' . $status);
header('Location: ' . str_replace(array('&', "\n", "\r"), array('&', '', ''), $url));
exit();
}
Template Features
OpenCart Compatibility: 1.5.6.x
OpenCart Engine: 1.5.6.4
(Trimmed)
Sources Available
PSD PNG PHP TPL JS
Hosting Requirements
Web Server (preferably Apache)
PHP (at least 5.2)
MySQL
Curl
Fsock
OpenCart Templates Help Center
Software Required
Adobe Photoshop CS+
For uncompressing a template ZIP package: WinZip 9+ (Windows);
Stuffit Expander 10+ (Mac)
Apache Server
PHP v. 5 or higher
MySQL 4.1.14 or later
OpenCart 1.5.6.4
Sublime Text2 or later, Notepad++ or any php-editor
A commenter stated
mysql_ calls will work on this server but are causing deprecation
notices. A quick fix would be to turn off warnings in your php.ini
file, in your error_reporting value. Or you could try turning off
display errors, set display_errors to 0.
I like the comment but could someone provide a slightly more comprehensive explanation or visual resource to this suggestion? Such as articulating a little further how to proceed? Should I download the file through GoDaddys public FTP or should I use FileZilla FTP client (does it matter), make a copy, make the proper changes then re-upload?
I like the possible solution but I am curious to know if these are the only ones.
UPDATE
I just changed display_errors = 1; to display_errors = 0;
saved the file (I edited the file withing GoDaddy's text editor)
re-input our database access details
hit continue on step 3 configuration and got the same error.
php.ini
magic_quotes_gpc = Off;
register_globals = Off;
default_charset = UTF-8;
memory_limit = 64M;
max_execution_time = 36000;
upload_max_filesize = 999M;
safe_mode = Off;
mysql.connect_timeout = 20;
session.use_only_cookies = On;
session.use_trans_sid = Off;
session.cookie_httponly = On;
session.gc_maxlifetime = 172800;
allow_url_fopen = on;
;display_errors = 0;
;error_reporting = E_ALL;
???
I have a similar experience! You don't need to enable these extensions the PHP Version needs to be update:
Sign into GoDaddy
Go to My Products under your sign in name at the top right.
Go to Web Hosting and click the Manage button.
Click manage again.
Scroll to the Software header and click "Select PHP Version"
Then change to an earlier version, in which this extension is not deprecated.
Let me know how that works for you.

How to add URL to IDM by program

How to add URL to IDM by program ? I am trying to develop a software what to add URL to the IDM. I have no idea how to do that could help me ? I found this temp folder C:\Users[USER]\AppData\Roaming\IDM\DwnlData but no idea how to add URL.
You can add links to IDM by passing the "-d" argument to IDMan.exe
From in your program or script, (you can use ShellExecute or the equivalent in whatever language you're using,) call [IDM Install Path]\IDMan.exe -d [link]
[IDM Install Path]: The directory where idm is installed
(eg. C:\Program Files\Internet Download Manager)
[link]: The url you want to add to IDM
enter link description here
Let us know if there is anything else we can help u with

Tell selenium to look in my C:/Downloads folder (Ruby)

me again!!
I have a question based around the download of a file. I was helped with setting up a Firefox profile to set a download to save a file directly without a pop up window. Now I need to tell Selenium to confirm that the said downloaded file is in my downloads folder on C drive to complete the test. Is there a way to do this? I've trawled for answers and have gotten nothing.
I first tried by setting a path like so on my env.rb file but didn't get very far with it:
$download_location = 'C:/Users/User/Downloads'
def download_location(path)
$download_location + path
end
Then telling cucumber to visit this location and confirm the name of the file.
Any help on pointing selenium to the location and confirming the name of a csv file would be hugely appreciated
Thanks
If you want to use ruby instead of selenium, you can use the exists? method to check the downloads directory for a given file, and it will return a Boolean result. For example:
File.exists?('C:\Users\User\Downloads\foo.txt')
I have found a solution that worked for me:
puts Dir["C:/Users/OSAT TESTING/Downloads/**/fleet_#{export}_export_all_*.csv"]
This confirmed the download of the file by looking in my downloads folder and returning the file path + name of any file that contained "fleet_#{export}_export_all_*.csv" in cmd prompt.
Thank you all for your help
:-)

PHPUnit + Selenium: How to set Firefox about:config options?

When running Selenium tests remotely with PHPUnit and Firefox, onChange events are not fired as they are when a user is operating the browser.
The solution to this seems to be to set the focusmanager.testmode option to true in Firefox's preferences (i.e. about:config), as suggested in a Selenium bug report.
However all the examples are using Selenium directly, while I am using PHPUnit which has its own API hiding the Selenium internals. I can't figure out how to set this Firefox option using PHPUnit, so I'm hoping someone else can tell me how this can be done!
(No, I can't go into about:config and set it myself manually because the tests create a new clean browser profile each time the tests are run, so any manual config changes are lost.)
Thanks to the Selenium developers I have a solution!
Short version
Put this in your test so that it gets called in the setUp() function:
// Firefox mini-profile that sets focusmanager.testmode=true in about:config
define('FIREFOX_PROFILE',
'UEsDBAoAAAAAADqAxkSBK46tKgAAACoAAAAIABwAcHJlZnMuanNVVAkAA1BZkVM6WZFTdXgLAAEE
6AMAAARkAAAAdXNlcl9wcmVmKCJmb2N1c21hbmFnZXIudGVzdG1vZGUiLCB0cnVlKTsKUEsBAh4D
CgAAAAAAOoDGRIErjq0qAAAAKgAAAAgAGAAAAAAAAQAAAKSBAAAAAHByZWZzLmpzVVQFAANQWZFT
dXgLAAEE6AMAAARkAAAAUEsFBgAAAAABAAEATgAAAGwAAAAAAA==');
protected function setUp()
{
$this->setDesiredCapabilities(Array('firefox_profile' => FIREFOX_PROFILE));
}
This sets focusmanager.testmode to true.
Long version
You need to create your own mini Firefox profile with the preferences you want set, and pass it along at the start of your tests. Here's how to do it:
Create a new folder and put the files you want in the Firefox profile in there. This can be anything (bookmarks, extensions, a copy of your own profile, etc.) but all we need here is a file called prefs.js which stores our about:config settings.
Create prefs.js in this folder with the following content:
user_pref("focusmanager.testmode", true);
Zip up the folder (prefs.js should be in the root of the archive), and base64 encode it.
If you're using Linux, you can do it all like this:
mkdir firefox-profile
cd firefox-profile
echo 'user_pref("focusmanager.testmode", true);' >> prefs.js
zip -r ../firefox-profile.zip *
base64 < ../firefox-profile.zip
Then take the base64 value and set it as the "firefox_profile" capability as per the short version above.

How do I set up TeamCity CI so that it unpacks Xamarin components?

In Visual Studio everything works and a Components directory is created with the appropriate dlls. However, TeamCity is not able to retrieve the Android Support Library dlls because the trigger for the restore is a Xamarin VS plugin that runs when loading the solution. The equivalent of nuget package restore for Xamarin is xamarin-component. I have placed the xamarin-component.exe in my C:\Windows directory. To configure TeamCity, I prepended a Command Line build step with
Command executable: xamarin-component
Command parameters: restore mysolution.sln
TeamCity runs as NT Authority\System. So using PsExec,
psexec -i -s %SystemRoot%\system32\cmd.exe
If I then run 'xamarin-component login'
INFO (login): Computed cookie jar path: C:\Windows\system32\config\systemprofile\.xamarin-credentials
INFO (login): Computed cookie jar path: C:\Windows\system32\config\systemprofile\.xamarin-credentials
INFO (login): Credentials successfully stored.
When I go to my solution in cmd and attempt the restore, I get an attempt to download the componet, and then a Json parsing error. This is the same error I get in TeamCity.
I get the error if I use 'Administrator' (which stores the credential in C:\Users\Administrator. Earlier when I was using my personal account, it did work. However, once I deleted the C:\Users\tim\AppData\Local\Xamarin\Cache\Components, the same issue emerged. Fiddler shows that rather than getting Json back (as we do when we enter an invalid token) we are getting a 302 redirect that says Object moved here. And here is the xamarin
login page - obviously not Json.
Tried.
1. Set COOKIE_JAR_PATH to C:\Users\tim.xamarin-credentials - xpkg picks up but same error
2. Copy .xamarin-credentials from Config\system32 to D:\, set COOKIE_JAR_PATH to D:.xamarin-credentials - xpkg picks up but same error
3. Move .xamarin-credentials to C:\, set COOKIE_JAR_PATH - same error
4. Re-login in NT Authority with COOKIE_JAR_PATH to C:.xamarin-credentials - same error
My temporary idea now is to figure out where the NT Authority xamarin-component looks for Cache and put the files there.
C:\Windows\system32\config\systemprofile\AppData\Local\Xamarin\Cache\Components\xamandroidsupportv4-18-4.18.1.xam
The version of my xamarin-component is 0.99 - for 100, we try harder...
I’ve had trouble actually getting the cookie jar to load correctly from the system32 path. I think this is a path virtualization issue that I just don't understand well enough to make heads or tails of.
I ended up adding an environment variable that the tool will read from (I'm its principal author at Xamarin :-) that specifies the cookie jar path to read from, and this solved the problem for others using TeamCity. The environment variable is COOKIE_JAR_PATH.
You can set it from TeamCity's environment settings to point to a cookie jar path outside of the system32 profile directory (I think in my original testing, I put it in the root of the C: drive, but it can be anywhere, really).
As a hack, I copied the Cache folder from
C:\Users\tim\AppData\Local\Xamarin
to
C:\Windows\system32\config\systemprofile\AppData\Local\Xamarin\
That bypassed communication with the Xamarin server.
Update. I suspect it might be a bad link or setup on their server side. When xamarin-component restore is called, a call is made to
GET /api/available_versions?alias=xamandroidsupportv4-18 HTTP/1.1
which returns "Object moved to here" where "here" is nowhere.
If you start Visual Studio after deleting the Cache and Components folder (next to the solution), Xamarin makes a call to
GET /api/download/xamandroidsupportv4-18/4.18.1 HTTP/1.0
which has a similar looking Object moved to, but this time it directs you to xamarin-components.s3.amazonaws.com/
GET /fdca922d2b77799fe208a08c9f3444fe/xamandroidsupportv4-18-4.18.1.xam HTTP/1.0
Perhaps something changed, or the available_versions API has changed.
Thanks very much for this question and your answers to it. I didn't really like the idea of storing an auth cookie on the build node or having to copy a cache there manually, so I came up with my own solution so I hacked around this problem with a quick Powershell script that mimics the behaviour of the xamarin-component.exe restore action:
param
(
[Parameter(Mandatory=$true)]
$authCookie,
[Parameter(Mandatory=$true)]
$componentDirectory,
[Parameter(Mandatory=$true)]
$project
)
[void]([System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem'))
$xml = [xml] $(cat $project);
$components = $xml.Project.ItemGroup.XamarinComponentReference | ? { $_.Include.Length -gt 0 } | % { $_.Include };
if (!(test-path $componentDirectory))
{
echo "$componentDirectory didn't exist, so it was created.";
[void](mkdir $componentDirectory);
}
foreach ($component in $components)
{
$source = "http://components.xamarin.com/download/$component";
$destination = "$componentDirectory\$component.zip";
if (test-path $destination)
{
echo "$destination already exists, skipping...";
continue;
}
echo "Downloading $component from $source to $destination...";
$client = New-Object System.Net.WebClient
$client.Headers.Add([System.Net.HttpRequestHeader]::Cookie, "XAM_AUTH=$authCookie");
try
{
$client.DownloadFile($source, $destination);
}
catch
{
# The error message will be on one of these lines hopefully:
write-error "Failed to download! Errors are below:";
write-error $_
write-error $_.Exception
write-error $_.Exception.InnerException
write-error $_.Exception.InnerException.InnerException
exit 1;
}
if (!(test-path $destination))
{
write-error "$destination doesn't exist - the download must have failed!";
exit 1;
}
echo "Decompressing $source to $componentDirectory"
[System.IO.Compression.ZipFile]::ExtractToDirectory($destination, $componentDirectory)
echo ""
}
echo "Done!";
The -authCookie parameter can be extracted from either the XAM_AUTH cookie in your browser or from the .xamarin-credentials "cookiejar" in your home directory. It's nice to have it parameterised like this so you can store it as a secret variable in TeamCity.
The componentDirectory parameter must be the full path to the component directory - it will be created if it doesn't exist.
The project parameter should be the path to your project that you want to restore packages for - if you have multiple projects that need this then you'll have to execute the script for each one. Don't specify your solution as it won't work.
Unfortunately, this isn't very resilient to Xamarin's whims - a simple API change could render this useless, so obviously the best solution is to wait for Xamarin to fix this. I e-mailed Xamarin support to complain about this problem but I don't imagine I'll get a timely response (they seem very very busy these days). I hope this is useful!
Create directory and put that directory path in environment variable XAMARIN_CACHEPATH

Resources