I successfully uploaded a file from Artifactory (Generic Repo) through a WebClient object. I am having trouble downloading a file using the same method. I am trying to figure out the easiest way to download via Powershell to our server.
Please note that installing other utilities, such as Curl, is currently not an option. I am writing automation scripts and want to stick to the base server of Windows 2008 r2 without installing other utilities, since I cannot count on the fact that they are on all servers.
If anyone has an example script using the Rest API, that would be great!
Sample download code (this works):
$SOURCE = "https://artifactory.example.com/artifactory/net-generic-local/APP/BF_1.0.zip" $DESTINATION = ".\BF_1.0.zip" $AF_USER ="user" $AF_PWD ="password" $WebClient = New-Object System.Net.WebClient $WebClient.Credentials = New-Object System.Net.NetworkCredential($AF_USER,$AF_PWD) $WebClient.DownloadFile($SOURCE,$DESTINATION)
This is an example download code (doesn't work):
$SOURCE = ".\BF_2.0.zip" $DESTINATION = "https://artifactory.example.com/artifactory/net-generic-local/APP/BF_2.0.zip" $AF_USER ="user" $AF_PWD ="password" $WebClient = New-Object System.Net.WebClient $WebClient.Credentials = New-Object System.Net.NetworkCredential($AF_USER, $AF_PWD) $URI = New-Object System.Uri($DESTINATION) $WebClient.UploadFile($URI,$SOURCE)
This is the error I get from the download:
Exception calling "UploadFile" with "2" argument(s): "The remote server returned an error: (405) Method Not Allowed." At E:\transient\af_put.ps1:8 char:1 + $WebClient.UploadFile($URI,$SOURCE) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
source share