Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A simple Bash based downloader for
# A simple Bash/Curl downloader for
# Usage: / "" (any URL)
# You can export your credentials via ~/.bashrc:
# export ULOZTO_USER="username"
# export ULOZTO_PASS="password"
# Or you can edit this script and make them default (don't forget to chmod 0700
# in that case!)
# We need couple temporary files, one to get token and second for
# login and download, last one for filename change...
# Get the form token first (srsly, using tokens to prevent script download? ;-)
token=$(curl -sqLc $token_cookie "" | \
perl -ne 'if (m/frmloginForm\-_token_" value="(\w+)" /g) { print "$1" }')
[ -z "$token" ] && echo "Unable to get token. Wrong username/password?" && exit 1
# Login to you WIP account and get the session
curl -sLb $token_cookie -c $login_cookie \
--data "username=${ULOZTO_USER}&password=${ULOZTO_PASS}&_token_=${token}" \
"" > /dev/null
[ "$?" != "0" ] && echo "Unable to login :-(" && exit 1
# Download the file and save HTTP headers
# After download, we extract the Content-Disposition from them and rename
# the file afterwards.
src=`TMPDIR=$(pwd) mktemp`
curl -D $headers --progress-bar -L -b $login_cookie "$1?do=directDownload" > $src
# I srsly sux in Perl :`(
dst=`perl -ne 'if (m/attachment;filename\*=UTF-8..(.*)$/g) { $s=$1;$s =~ s/^\s+|\s+$//g;print $s;}' $headers`
if [ -z "$dst" ]; then
echo "Unable to get original filename, keeping download in '$src'"
mv -fv "$src" "$dst"
# Cleanup...
rm -f $headers $login_cookie $token_cookie
Copy link

davidisko commented Apr 12, 2016

I've exported login credentials but getting "Unable to get token. Wrong username/password?".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment