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

 
Participant
1 year, 1 month ago.

  • Author
    Posts
  • #98310

    Participant
    Topics: 1
    Replies: 1
    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

    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

    Participant
    Topics: 2
    Replies: 933
    Points: 1,611
    Helping Hand
    Rank: Community Hero

    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

      Participant
      Topics: 1
      Replies: 1
      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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort