PowerShell Upload und Download mit Invoke-Webrequest

QRS uses NextCloud WebDAV as basis for its files

Automated upload and download is operated using Windows PowerShell Scripts

Besides cURL the scripts also make direct use of Invoke-Webrequest

What?

Mounting Nexcloud directories as logical drives is not reliable. The HTTP-methods provided by  cURL are reliable and perform sufficiently for the QRS data volumes. In order to use cURL in Windows, the scripts need to know the path to the exe file. The Invoke-Webrequest cmdlet performs the same without this requirement.

Download

For downloading a file, the path onto the cloud is required:

$URI = "https://ppp.woelkli.com/remote.php/dav/files/user[/subfolder]/file"

The Credentials for the DAV are passed to a PSCredential-Objec using the -ArugmentList parameter of its constructor.

$PSC = New-Object System.Management.Automation.PSCredential -ArgumentList($Usr, $PwS)

To avoid unnecessary analysis of the downloaded content the -UseBasicParsing is included in the call.

downloadin a file into a destination folder $Dst is intuitive:

Invoke-Webrequest -UseBasicParsing -Uri $URI -Credential $PSC -OutFile $Dst

Upload

An Upload requires specifying the method to the web server. The method is PUT and is specified as the value for the -Method parameter. The path to the local file is specified in the -InFile Parameter:

$WRS = Invoke-Webrequest -UseBasicParsing -URI $URI -Method PUT -Credential-PSC -InFile $Src

The Cmdlet returns a WebResponse object which contains two useful properties containing transfer status information:

$WRS.StatusCode values of a successful transfer are 201 (Created) and 204 (no content)

$WRS.StatusDescription contains a corresponding description message

 

Comments and Responses

×

Name is required!

Enter valid name

Valid email is required!

Enter valid email address

Comment is required!

Comments :

  • user
    kqCpSamCaJ 21/11/2024 At 01:00
  • user
    BelLkIxx 15/11/2024 At 07:49
  • user
    aMmRqgcgJBBPGn 09/11/2024 At 14:24
Top