Welcome Forums General PowerShell Q&A WEBDAV Upload

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 2 months ago.

  • Author
  • #35156

    Topics: 4
    Replies: 3
    Points: 0
    Rank: Member

    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘WEBDAV Upload’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort