Friday, January 2, 2015

Powershell vs. Curl or Wget

I wanted to do silent downloads using the command line, so this way I can install tools like Homebrew, RVM or GVM using Puppet.

On Linux or Unix, you can use curl or wget:
source=http://website/somepackage.tgz
path=/tmp/packages
file_path=${path}/somepackage.tgz
username='jdoe'
password='secret'

curl -u ${username}:${password} -o ${file_path} ${source}
wget --user ${username} --password ${password} ${source} -P ${path}
On Windows, I found a cool Puppet module called pget.  This module does something like this in Powershell to get the same effect:
$source = http://website/somepackage.tgz
$target_file = somepackage.tgz
$username = 'jdoe'
$password = 'secret'

$wc = New-Object System.Net.WebClient;
$wc.Credentials = New-Object System.Net.NetworkCredential(${username},${password});
$wc.DownloadFile(${source},${target_file})

No comments:

Post a Comment