SHARE
TWEET

Powershell webclient.UploadFile

a guest Oct 20th, 2015 555 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Source = @"
  2.  using System.Net;
  3.  public class ExtendedWebClient : WebClient
  4.  {
  5.    public int Timeout;
  6.    protected override WebRequest GetWebRequest(System.Uri address)
  7.    {
  8.      WebRequest request = base.GetWebRequest(address);
  9.      if (request != null)
  10.      {
  11.        request.Timeout = Timeout;
  12.        var httpRequest = request as HttpWebRequest;
  13.      }
  14.      return request;
  15.    }
  16.    public ExtendedWebClient()
  17.    {
  18.      Timeout = 100000; // the standard HTTP Request Timeout default
  19.    }
  20.  }
  21. "@;
  22.  
  23. $debugPreference = "Continue"
  24. #Write-Output "Output msg"
  25. #Write-Debug "Debug msg"
  26. Add-Type -TypeDefinition $Source -Language CSharp
  27.  
  28. $webclient = New-Object ExtendedWebClient;
  29. $webclient.Timeout=10000000;
  30. $fileName = "0.iso";
  31. $sourceFilePath = "C:\\$fileName";
  32. $siteAddress = "http://nexus.lab.local:8081/nexus/content/sites/myproj/$fileName";
  33. #$webclient.Headers.Add("Content-Length", "$sourceFilePath.Length")
  34. $webclient.Headers.Add("Content-Type", "application/zip")
  35. $webclient.Credentials = New-Object System.Net.NetworkCredential("admin", "admin123");
  36. $webclient.AllowWriteStreamBuffering = $false;
  37. $webclient.UploadFile($siteAddress, "Post", $sourceFilePath);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top