Upload files to http server using power shell

I want to transfer a XML file to http server (abcdef.com) . I wrote scripts for this and it’s running but actually it’s not uplaoding the files to http server .

My code

$sourceFilePath = “C:\Temp\NEWFOLDER\ABCDEF.XML”
$siteAddress = “abcdef.net - This website is for sale! - abcdef Resources and Information.
$urlDest = “{0}/{1}” -f ($siteAddress, “ABCDEF.XML”);
$UserName = “XXXXX”
$Password = “XXXXX”

function uploadFile()
{

Param ([string] $sourceFilePath,
       [string] $siteAddress ,
       [string] $urlDest,
       [string] $UserName,
       [string] $Password)

    $webClient = New-Object System.Net.WebClient;
    $webClient.Credentials = New-Object System.Net.NetworkCredential($UserName,$Password);

   ("*** Uploading {0} file to {1} ***" -f ($sourceFilePath, $siteAddress) ) | write-host -ForegroundColor Green 
    $webClient.UploadFile($urlDest, "PUT", $sourceFilePath);

}

uploadFile $sourceFilePath $siteAddress $urlDest $UserName $Password

ERROR

Exception calling “UploadFile” with “3” argument(s): "The remote server returned an error: (503) Server Unavailable."At
C:\ABCDEF-documents\upload-file.ps1:40 char:13

  •         $webClient.UploadFile($urlDest, "PUT", $sourceFilePath);
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:slight_smile: , MethodInvocationException
    • FullyQualifiedErrorId : WebException
      Can anyone help me on this . Any clue will be helpful.

Well, that error is pretty specific.
Either the URL you are using is wrong or the server is down.
You should validate / fix the server side first.

thanks for reply :slight_smile: . I’m pretty sure the server isn’t down but may be the url is wrong.