How could i upload a log file from my local system to a webpage (http://abc..) using powershell script? Thanks in advance
Asked
Active
Viewed 1.2k times
4
-
please also provide more detail on what you've tried already. – JackDev Aug 18 '14 at 04:15
-
You can try [this one](http://stackoverflow.com/questions/14860864/powershell-http-post-file-upload-for-rest-api) too, if file upload is for REST API. – ekostadinov Aug 19 '14 at 05:37
1 Answers
4
If you are using HTTP, try something like this:
$sourceFilePath = "c:\MyLocalFolder\LocalLogFileName.log"
$siteAddress = "http://192.168.15.12/DestinationFolder"
$urlDest = "{0}/{1}" -f ($siteAddress, "DestinationLogFileName.log";
$webClient = New-Object System.Net.WebClient;
$webClient.Credentials = New-Object System.Net.NetworkCredential("MyUserName", "MyPassword");
("*** Uploading {0} file to {1} ***" -f ($sourceFilePath, $siteAddress) ) | write-host -ForegroundColor Green -BackgroundColor Yellow
$webClient.UploadFile($urlDest, "PUT", $sourceFilePath);

Andrew Shepherd
- 44,254
- 30
- 139
- 205
-
1
-
-
I run this script and I got this error Exception calling "UploadFile" with "3" argument(s): "The remote server returned an error: (503) Server Unavailable."At C:\ABCDEF-documents\upload-file.ps1:36 char:13 + $webClient.UploadFile($urlDest, "PUT", $sourceFilePath); any clue how to solve it – Apr 09 '18 at 13:28