Upload files to http server using power shell

Welcome Forums General PowerShell Q&A Upload files to http server using power shell

This topic contains 2 replies, has 2 voices, and was last updated by

9 months, 1 week ago.

  • Author
  • #98310

    Points: 0
    Rank: Member

    I want to transfer a XML file to http server (http://abcdef.com/somefolder/abcdef.xml) . 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 = "http://abcdef.net/inetpub/temp/XML/"
    $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


    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: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException
    Can anyone help me on this . Any clue will be helpful.

  • #98340

    Points: 502
    Helping Hand
    Rank: Major Contributor

    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.

    • #98341

      Points: 0
      Rank: Member

      thanks for reply 🙂 . I'm pretty sure the server isn't down but may be the url is wrong.

The topic ‘Upload files to http server using power shell’ is closed to new replies.