4

How could i upload a log file from my local system to a webpage (http://abc..) using powershell script? Thanks in advance

2
  • please also provide more detail on what you've tried already. Commented Aug 18, 2014 at 4:15
  • You can try this one too, if file upload is for REST API. Commented Aug 19, 2014 at 5:37

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Care to elaborate for HTTPS?
Is it the same for HTTPS?
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.