• Beitrags-Kategorie:PowerShell
  • Lesedauer:2 min Lesezeit

With your own Nextcloud server, you can access your stored data from anywhere. It can also be used to share data with others. Folders can be shared with the upload only file drop option. With this share, data can only be uploaded to the server via a web interface. This solution is perfect for project data, surveys or similar application examples.

Is there a possibility to access these shars with a script?
The answer is YES and it is very simple.


I found this Blog from Georgi Nikolov. He create a script for Linux that can upload data to Nextcloud File-Drop shares using CURL. But I don’t work with Linux. Unfortunately, I have not found an Windows alternative either. That’s why I built one myself.

The Solution

create File Drop

Create a shared link for a Nextcloud folder. Select the “File Drop (upload only)” option, or “Allow upload and editing” when creating the shared link.

create shared link

… and copy the shared link url

copy shared link url

My link looks like this:
https://mynextcloudserver.at/xxx/s/Y4cQ2DLJeCAXRLD

We need to separate this URL into two parts. The first part is the NextcloudUrl, the second is the ShareToken.
$NextcloudUrl = "https://mynextcloudserver.at/xxx/"
$sharetoken = 'Y4cQ2DLJeCAXRLD'

Now we just need to specify the file for upload.
$Item = "C:\Temp\test.zip"

edit and run the script

$Item = "C:\Temp\test.zip"
$NextcloudUrl = "https://mynextcloudserver.at/xxx/"
$sharetoken = 'Y4cQ2DLJeCAXRLD'

$Item = Get-Item $Item
$Headers = @{
    "Authorization"=$("Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($("$($sharetoken):"))))");
    "X-Requested-With"="XMLHttpRequest";
}
$webdav = "$($NextcloudUrl)/public.php/webdav/$($Item.Name)"
Invoke-RestMethod -Uri $webdav -InFile $Item.Fullname -Headers $Headers -Method Put  

Output

Powershell output

File in Nextcloud 🙂

uploaded file in nextcloud

Now we can easily upload files directly to our File Drop Nextcloud link in 2 easy steps. Enjoy!

P.S: Powershell rocks!

5 / 5. 14

Schreibe einen Kommentar

*

code