I want to transfer a XML file to http server ( http://abcdef.com/somefolder/abcdef.xml<\/a> ) . I wrote scripts for this and it’s running but actually it’s not uplaoding the files to http server .<\/p>\n
My code<\/p>\n
$sourceFilePath = “C:\\Temp\\NEWFOLDER\\ABCDEF.XML” function uploadFile() Param ([string] $sourceFilePath, $httprequest = [System.Net.HttpWebRequest]::create($sourceFilePath) (“*** Uploading {0} file to {1} ***” -f ($sourceFilePath, $siteAddress) ) | write-host -ForegroundColor Green $httpresponse = $httprequest.GetResponse()<\/p>\n }<\/p>\n uploadFile $sourceFilePath $siteAddress $urlDest $UserName $Password<\/p>\n ERROR<\/p>\n Exception calling “UploadFile” with “3” argument(s): \"The remote server returned an error: (503) Server Unavailable.\"At I want to transfer a XML file to http server ( http://abcdef.com/somefolder/abcdef.xml<\/a> ) . I wrote scripts for this and it’s running but actually it’s not uplaoding the files to http server .<\/p>\n My code<\/p>\n $sourceFilePath = “C:\\Temp\\NEWFOLDER\\ABCDEF.XML” function uploadFile() Param ([string] $sourceFilePath, $httprequest = [System.Net.HttpWebRequest]::create($sourceFilePath) (“*** Uploading {0} file to {1} ***” -f ($sourceFilePath, $siteAddress) ) | write-host -ForegroundColor Green $httpresponse = $httprequest.GetResponse()<\/p>\n }<\/p>\n uploadFile $sourceFilePath $siteAddress $urlDest $UserName $Password<\/p>\n ERROR<\/p>\n Exception calling “UploadFile” with “3” argument(s): \"The remote server returned an error: (503) Server Unavailable.\"At Looks perfect however verify that the location being written to has R/W Permissions. Since this also appears to be a live site the changes may not be showing until IIS (etc.) is restarted. Maybe add a call to the end of the script to restart the WebService once it is written. Or first stop IIS in the script, run copy, restart.<\/p>","upvoteCount":0,"datePublished":"2018-04-09T12:32:00.000Z","url":"https://community.spiceworks.com/t/upload-file-to-http-server-using-power-shell/645065/2","author":{"@type":"Person","name":"johnboyle","url":"https://community.spiceworks.com/u/johnboyle"}},{"@type":"Answer","text":" You’re invoking a web request to the local file (which will use the file:// protocol), shouldn’t it be to the server instead?<\/p>\n You also haven’t declared $webClient anywhere, I’m presuming it should be like this from info elsewhere<\/p>\n In fact I can see on this<\/a> stack overflow link you left a comment on the answer an hour ago for the same problem, why not just copy their code and use the WebClient object instead of the HttpWebRequest one?<\/p>","upvoteCount":0,"datePublished":"2018-04-09T12:58:09.000Z","url":"https://community.spiceworks.com/t/upload-file-to-http-server-using-power-shell/645065/4","author":{"@type":"Person","name":"francishagyard2","url":"https://community.spiceworks.com/u/francishagyard2"}},{"@type":"Answer","text":" thanks for reply
\n$siteAddress = \" http://abcdef.net/inetpub/temp/XML/\"<\/a> ;
\n$urlDest = “{0}/{1}” -f ($siteAddress, “ABCDEF.XML”);
\n$UserName = “XXXXX”
\n$Password = “XXXXX”<\/p>\n
\n{<\/p>\n
\n[string] $siteAddress ,
\n[string] $urlDest,
\n[string] $UserName,
\n[string] $Password)<\/p>\n
\n$httprequest.Credentials = New-Object System.Net.NetworkCredential($UserName,$Password)<\/p>\n
\n$webClient.UploadFile($urlDest, “PUT”, $sourceFilePath);<\/p>\n
\nC:\\ABCDEF-documents\\upload-file.ps1:40 char:13<\/p>\n\n
<\/code><\/pre>\n<\/li>\n
<\/span>, MethodInvocationException<\/li>\n
\nCan anyone help me on this . Any clue will be helpful.<\/li>\n<\/ul>","upvoteCount":3,"answerCount":9,"datePublished":"2018-04-09T12:16:01.000Z","author":{"@type":"Person","name":"sudiptasaha177","url":"https://community.spiceworks.com/u/sudiptasaha177"},"suggestedAnswer":[{"@type":"Answer","text":"
\n$siteAddress = \" http://abcdef.net/inetpub/temp/XML/\"<\/a> ;
\n$urlDest = “{0}/{1}” -f ($siteAddress, “ABCDEF.XML”);
\n$UserName = “XXXXX”
\n$Password = “XXXXX”<\/p>\n
\n{<\/p>\n
\n[string] $siteAddress ,
\n[string] $urlDest,
\n[string] $UserName,
\n[string] $Password)<\/p>\n
\n$httprequest.Credentials = New-Object System.Net.NetworkCredential($UserName,$Password)<\/p>\n
\n$webClient.UploadFile($urlDest, “PUT”, $sourceFilePath);<\/p>\n
\nC:\\ABCDEF-documents\\upload-file.ps1:40 char:13<\/p>\n\n
<\/code><\/pre>\n<\/li>\n
<\/span>, MethodInvocationException<\/li>\n
\nCan anyone help me on this . Any clue will be helpful.<\/li>\n<\/ul>","upvoteCount":3,"datePublished":"2018-04-09T12:16:01.000Z","url":"https://community.spiceworks.com/t/upload-file-to-http-server-using-power-shell/645065/1","author":{"@type":"Person","name":"sudiptasaha177","url":"https://community.spiceworks.com/u/sudiptasaha177"}},{"@type":"Answer","text":"$httprequest = [System.Net.HttpWebRequest]::create($siteAddress)\n<\/code><\/pre>\n
$webClient = New-Object System.Net.WebClient\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-04-09T12:54:12.000Z","url":"https://community.spiceworks.com/t/upload-file-to-http-server-using-power-shell/645065/3","author":{"@type":"Person","name":"francishagyard2","url":"https://community.spiceworks.com/u/francishagyard2"}},{"@type":"Answer","text":"
. I used $webClient = New-Object System.Net.WebClient but same error …<\/p>\n