How to download a "publicly shared" (WebClient!) file via PowerShell
Foreword: we need to bear in mind that Syncplify Server! is, at its core, a security software, therefore even when you use its WebClient! to create a "publicly shared object" (a shared object that's not password-protected), downloading such object is not as simple as pasting its URI into a plain Invoke-WebRequest in your PowerShell, there's a lot more to it than that.
You have to account for the security measures Syncplify Server! employs, so all these operations must be indirect. First you have to invoke the URI of the shared object, read the JWT from there, then perform a POST request with that token to a specific URL built according to the documentation here: https://openapi.syncplify.com/v6/webclient/#post-/shr/down/-path-
The give you a jump-start, here's a ready-made script for you to customize with your own URLs:
$response = Invoke-WebRequest -Uri "https://webclient.example.com:6444/api/v1/share/2retezypuhQdpEXRD5fNguyMbgI"
$jsonObject = $response.Content | ConvertFrom-Json
$token = $jsonObject.token
$headers = @{
"Authorization" = "Bearer $token"
}
Invoke-WebRequest -Uri "https://webclient.example.com:6444/api/v1/shr/down/test.txt" -Method Post -Headers $headers -Outfile ./test.txt
This script will download the shared file named "test.txt"
from a shared object with ID "2retezypuhQdpEXRD5fNguyMbgI"
, (which must not be password-protected) to a local file also named "test.txt"
.
For the Linux users among you, here's the same script trancoded to bash (also works in zsh, and should work in any other POSIX shell) using curl
and jq
:
#!/bin/bash
# Fetch the JSON response and extract the token
token=$(curl -s "https://webclient.example.com:6444/api/v1/share/2retezypuhQdpEXRD5fNguyMbgI" | jq -r '.token')
# Download the file using the Bearer token for authentication
curl -X POST \
-H "Authorization: Bearer $token" \
"https://webclient.example.com:6444/api/v1/shr/down/test.txt" \
-o ./test.txt
Enjoy!