Upload files to http server using power shell

This topic contains 2 replies, has 2 voices, and was last updated by  sahasudipta 2 weeks, 1 day ago.

  • Author
    Posts
  • #98310

    sahasudipta
    Participant

    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

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

  • #98340

    postanote
    Participant

    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

      sahasudipta
      Participant

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

You must be logged in to reply to this topic.