====== hubiC upload ====== #!/bin/bash # # By Oros & Mitsu # # Licence Public Domaine # # apt-get install curl # pacman -S curl if [ -z "$1" ] then echo 'error: please append the file to upload.'; exit fi fullfile="$1" if [ -f '/tmp/cookiefile' ]; then rm '/tmp/cookiefile' fi # change login and password login="MY@LOGIN" password="MY_PASSWORD" echo "logging in..." # connection to hubic curl -sq --cookie-jar '/tmp/cookiefile' --request GET "https://hubic.com/" >/dev/null curl -sq --cookie-jar '/tmp/cookiefile' --request POST --data "sign-in-email=${login}&sign-in-password=${password}" "https://hubic.com/home/actions/nasLogin.php" >/dev/null echo "generating file metadata..." file=$(basename "$fullfile") filesize=$(stat -c%s "$fullfile") filesize_human=$(stat -c%s "$fullfile") filetype=$(file --mime-type "$fullfile" | awk -F' ' '{print $2}') filemtime=$(stat -c %Y "$fullfile") filedate=$(date -u --rfc-3339=seconds --date="@$filemtime" | awk -F'+' '{print $1}' | tr " " T) # upload the file destination='/Documents' echo "#### summary ####" echo "file: $file" echo "filepath: $fullfile" echo "filesize: $filesize" echo "filetype: $filetype" echo "file mod date: $filedate" echo "destination: $destination" echo "#### end summary ####" echo "uploading..." output=$(curl -sq --cookie '/tmp/cookiefile' --request PUT -H "Content-Type:$filetype" -H "Content-Disposition:attachment; filename='$file'" -H "X-File-Name:$file" -H "X-File-Type:$filetype" -H "X-File-Size:$filesize" -H 'X-Action:upload' -H "X-File-Dest:$destination" -H 'X-File-Container:default' -H "X-File-Modified:$filedate" -H 'X-Requested-With:XMLHttpRequest' -H "Content-Length:$filesize" -H 'Connection:keep-alive' -T "$fullfile" 'https://hubic.com/home/actions/ajax/hubic-browser.php') echo "upload done." echo "server response: " echo $output # log off curl -s --cookie --request GET "https://hubic.com/home/actions/logoff.php" >/dev/null if [ -f "/tmp/cookiefile " ]; then rm '/tmp/cookiefile' fi echo "== end of script ==" echo ""