Ask A Question

View Question

I've got a working PowerShell 'download' script for a NuGet package feed from my company's Proget server:

$targetUri = "https://path/to/my/nuget/package"
$credentialUser = "{AD username}"
$credentialPwd = "{AD password}"

$secureString = ConvertTo-SecureString -String $credentialPwd -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($credentialUser, $secureString)
$webClient = New-Object System.Net.WebClient
$webClient.Credentials = $credential
$webClient.DownloadFile($targetUri, "C:\\Tools\octopus-tentacle.2.6.1.796.nupkg")

Now I need to do this same thing in Ruby. Having no luck getting anything but HTTP 401s. Trying rubyntlm gem now (https://github.com/WinRb/rubyntlm/blob/master/examples/http.rb), but if anyone has a working example, I'd be quite appreciative.

-/- flagellum

Product: ProGet
Version: 3.4.7

Hi Jeff, it sounds like you're on the right track.

If you have ProGet set-up to use Windows Authentication (i.e. NTLM), then you will need to get your ruby script to speak in NTLM. Otherwise, the script cannot pass the authentication barrier.

NTLM is not trivial to implement, so hopefully the rubyntlm gem will be helpful.

Answering my own question using this solution. Hope anyone else who has to do this with Ruby will find this helpful:

require 'rubygems'
require 'httpclient'  #latest, with rubyntlm also installed

http_client = HTTPClient.new
http_client.set_auth(nil, '<domain>\<username>', '<password>')
local_file = File.new("C:\\temp\\<package>.<version>.nupkg", "wb")
local_file.write( http_client.get_content("https://<server>/nuget/<feed>/package/<package>/<version>") )

-/- flagellum

Answer Question