cd /news/developer-tools/send-files-to-nextcloud-owncloud-sha… · home topics developer-tools article
[ARTICLE · art-9362] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Send files to Nextcloud/Owncloud shared folder using curl

This article provides a bash script called `cloudsend.sh` that uses `curl` to upload files to shared folders on Nextcloud or Owncloud. The script accepts a file path and a folder link as arguments, and includes options for quiet mode, insecure HTTPS connections, and password authentication via an environment variable. The project has been migrated to a GitHub repository and will no longer be updated in its original location.

read3 min views21 publishedSep 24, 2018

cloudsend.sh

  This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.

Learn more about bidirectional Unicode characters

Show hidden characters

#!/usr/bin/env bash

############################################################

#

############################################################

############################################################

#

#

#

#

#

#

#

############################################################

CS_VERSION="0.1.6"

CLOUDURL=""

FOLDERTOKEN=""

PUBSUFFIX="public.php/webdav"

HEADER='X-Requested-With: XMLHttpRequest' INSECURE=''

log() {

	[ "$VERBOSE" == " -s" ] || printf "%s\n" "$1"

}

printVersion() {

        printf "%s\n" "CloudSender v$CS_VERSION"

}

initError() {

        printVersion >&2

        printf "%s\n" "Init Error! $1" >&2

        printf "%s\n" "Try: $0 --help" >&2

        exit 1

}

usage() {

        printVersion

        printf "\n%s%s\n" "Parameters:" "

  -h | --help      Print this help and exits

  -q | --quiet     Be quiet

  -V | --version   Prints version and exits

  -k | --insecure  Uses curl with -k option (https insecure)

-p | --password Uses env var $CLOUDSEND_PASSWORD as share password

               You can 'export CLOUDSEND_PASSWORD' at your system, or set it at the call.

               Please remeber to also call -p to use the password set."
        printf "\n%s\n%s\n%s\n" "Use:" "  $0 <filepath> <folderLink>" "  CLOUDSEND_PASSWORD='MySecretPass' $0 -p <filepath> <folderLink>"

        printf "\n%s\n%s\n%s\n" "Example:" "  $0 './myfile.txt' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28'"  "   CLOUDSEND_PASSWORD='MySecretPass' $0 -p './myfile.txt' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28'"

}

##########################

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then

        usage

        exit 0

fi

if [ "$1" = "-V" ] || [ "$1" = "--version" ]; then

        printVersion

        exit 0

fi

if [ "$1" = "-q" ] || [ "$1" = "--quiet" ]; then

        VERBOSE=" -s"
shift

fi

if [ "$1" = "-k" ] || [ "$1" = "--insecure" ]; then

        INSECURE=' -k'

        log " > Insecure mode ON"

        shift

fi

if [ "$1" = "-p" ] || [ "$1" = "--password" ]; then

        PASSWORD=${CLOUDSEND_PASSWORD}

        log " > Using password from env"

        shift

fi

##########################

FILENAME="$1"

CLOUDURL=''

if [[ $2 == *"index.php"* ]]; then

        CLOUDURL="${2%/index.php/s/*}"

else

    CLOUDURL="${2%/s/*}"

fi

FOLDERTOKEN="${2##*/s/}"

if [ ! -f "$FILENAME" ]; then

        initError "Invalid input file: $FILENAME"

fi

if [ -z "$CLOUDURL" ]; then

        initError "Empty URL! Nowhere to send..."

fi

if [ -z "$FOLDERTOKEN" ]; then

        initError "Empty Folder Token! Nowhere to send..."

fi

##########################

CURLBIN='/usr/bin/curl'

if [ ! -x "$CURLBIN" ]; then

        CURLBIN="$(which curl 2>/dev/null)"

        if [ ! -x "$CURLBIN" ]; then

                initError "No curl found on system!"

        fi

fi

##########################

BFILENAME=$(/usr/bin/basename $FILENAME) ##########################

#echo "$CURLBIN"$INSECURE$VERBOSE -T "$FILENAME" -u "$FOLDERTOKEN":"$PASSWORD" -H "$HEADER" "$CLOUDURL/$PUBSUFFIX/$BFILENAME"

"$CURLBIN"$INSECURE$VERBOSE -T "$FILENAME" -u "$FOLDERTOKEN":"$PASSWORD" -H "$HEADER" "$CLOUDURL/$PUBSUFFIX/$BFILENAME"
── more in #developer-tools 4 stories · sorted by recency
── more on @nextcloud 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/send-files-to-nextcl…] indexed:0 read:3min 2018-09-24 ·