This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 5 months ago.

  • Author
  • #35156
    Profile photo of derek ebeling
    derek ebeling

    Helpful friends,

    I am trying to use powershell to upload files to a WebDAV server. I am able to upload using a simple username and password using various apps on my iPhone/iPad. However, I continually receive the error "The remote server returned an error: (401) Unauthorized." This seems like a credential error, but nothing seems to work. I am using powershell 2.0. Code below:

    $ServerURL = "http://website.com/location"
    $Username = "Name"
    $Password = "Pass"

    function Publish-File {
    param (
    [parameter( Mandatory = $true, HelpMessage="URL pointing to a SharePoint document library (omit the '/forms/default.aspx' portion)." )]
    [parameter( Mandatory = $true, ValueFromPipeline = $true, HelpMessage="One or more files to publish. Use 'dir' to produce correct object type." )]
    Add-Type -AssemblyName System.Web

    $wc = new-object System.Net.WebClient
    $wc.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)

    $FileName | ForEach-Object {

    $DestUrl = [system.Web.HttpUtility]::UrlPathEncode( ( "{0}{1}{2}" -f $Url.ToString().TrimEnd("/"), "/", $_.Name ) )
    Write-Host "$( get-date -f s ): Uploading file: $_"
    Write-Host "url: $DestUrl"
    $wc.UploadFile( $DestUrl , "PUT", $_.FullName )
    Write-Host "$( get-date -f s ): Upload completed"



    ##upload document
    dir "c:\temp2" | Publish-File -Url $ServerURL


  • #35167
    Profile photo of Don Jones
    Don Jones

    WebDAV usually has its own authentication apart from the HTTP socket, and that's likely what you're running into. I'm not familiar enough with your setup to offer a suggestion though.

You must be logged in to reply to this topic.