none
Upload files to http server using power shell RRS feed

  • Question

  • 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.


    Monday, April 9, 2018 2:07 PM

Answers

All replies