Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save munfaqqiha/44ab04e9020bc8d887591fa88ce3355b to your computer and use it in GitHub Desktop.
Save munfaqqiha/44ab04e9020bc8d887591fa88ce3355b to your computer and use it in GitHub Desktop.
### BY: MUNFAQQIHA ####################################################################################################################################
######################### A BASH SHELL SCRIPT FOR LINUX AND WINDOWS TO AUTOMATICALLY NON-STOP UPLOAD FILES TO WWW.TERABOX.COM #########################
#######################################################################################################################################################
### ----------------------------------------------------------------------------------------------------------------------------------------------- ###
### | sample of successful upload: on linux: https://s.id/teraupnix || on windows: https://s.id/teraupwin | ###
### ----------------------------------------------------------------------------------------------------------------------------------------------- ###
### it is possible to upload multiple different types of files recursively, except 0-byte file size, in a folder where you run it. The maximum size ###
### of a single uploaded file allowed by terabox is 2147483648 Bytes (2.00 GiB). if a file exceeds that, this script will split it into pieces, and ###
### 120MiB is the upper limit of a single segment size allowed for multipart upload. however, terabox limits the maximum size of a single file that ###
### can be stored on their server. the total size of a single file for premium user is limited to 21474836479 Bytes (20.00 GiB), & 4294967296 Bytes ###
### (4.00 GiB) for a free member - https://s.id/1IMx2. ###
### ----------------------------------------------------------------------------------------------------------------------------------------------- ###
### ###
### catch the following steps to make it successful (run it on VPS / RDP for faster speed): ###
### ###
### 1. install jq: ###
### ###
### a. on linux do as usual. ###
### b. on windows: choose one of the following: ###
### (1). install linux with WSL: ubuntu or debian (highly recommended). ###
### (2). install gitforwindows (gitforwindows.org). ###
### (*). choose all of its default options. ###
### (*). run this on its shell: curl -Lo /usr/bin/jq.exe https://github.com/stedolan/jq/releases/latest/download/jq-win64.exe && jq -V ###
### ###
### 2. set the value for each of the following variables: ###
### ###
### it is all those little steps to get the value of the following 3 variables jt (jsToken), bt (bdstoken), and co (cookie): ###
### ###
### a. login to terabox account via chrome on desktop. ###
### b. press CTRL + R, then F12, next type "getinfo" in the "Filter" column ###
### c. so click "Networks" tab, right-click the url that says "getinfo" ###
### d. select copy >> Copy as cURL (bash), and don't event miss to paste it into your text editor. its usage is below: ###
### ###
### (1). for "jt" value, copy from "jsToken" section after "=" sign and before "&". ###
### (2). for "bt" value, copy from "bdstoken" section after as "jt" above. ###
### (3). for "co" value, copy from "cookie" section as usually. ###
### ###
### jt="" ###
### bt="" ###
### co="" ###
### ###
### e. the next let you go to fill out all variables (pay attention to text case): ###
### ###
### (1). full location path of a folder containing the files to be uploaded to terabox. ###
### ###
### # sample output of pwd command on linux shell. ###
### fl="/home/munfaqqiha/Pilem/Jadul" ###
### ###
### # sample output of pwd command on gitforwindows shell. ###
### fl="/c/Pilem/Jadul" ###
### ###
### (2). full path of your terabox folder where you'd like to store your files. ###
### ###
### rf="/Pilem/Jadul" ###
### ###
### (3). do you wanna move your files to another place after they're uploaded?: <yes/no>. ###
### ###
### mv="no" ###
### ###
### (4). if you decide that, please specify a full path of a backup folder to move them. ###
### ###
### # sample output of pwd command on linux shell. ###
### bu="/home/munfaqqiha/Pilem/Backup" ###
### ###
### # sample output of pwd command on gitforwindows shell. ###
### bu="/c/Pilem/Backup" ###
### ###
### (5). would you like to get a shared & download link of each uploaded file?: <yes/no>. all will be saved into a text file named "link.id". ###
### ###
### ds="yes" ###
### ###
### (6). while you'd agree to the points above, set its expiration date either 7, 30 (days), or 0 (forever). ###
### ###
### on="0" ###
### ###
### (7). please decide whether files may be deleted from the folder after they're uploaded: <yes/no>. ###
### ###
### rm="no" ###
### ###
#######################################################################################################################################################
### ALERT: ###
### .... After you've obtained your credentials, DO NOT press the "Sign Out" on the terabox.com when leaving it. It is enough to clear your cookies ###
### .... via the browser's built-in feature. If you do, then you'll not be able to upload files. You'll get an error something like: "need verify". ###
### ###
### NOTES: ###
### (*). it is also possible to run the code with the command: "bash yours.sh". if you picking on this, please include all variables in your file. ###
### (*). don't forget to watch a sample of successful upload on linux & windows at here: https://cuty.io/teraput. ###
### (*). for the multiple lines bash command code get it at here: https://cuty.io/linuxwintera. ###
#######################################################################################################################################################
### THE CODE STARTS FROM HERE #########################################################################################################################
set +H
jt="your stuffing"
bt="............."
co="............."
fl="............."
rf="............."
mv="............."
bu="............."
ds="............."
on="............."
rm="............."
[[ -n ${fl} && -d ${fl} ]] && cd "${fl}" && ua='okhttp/7.4' && bo='https://www.terabox.com' && set +H && find . -name "*piece[[:digit:]]*" ! -regex ".*\.\(sh\|id\)" -delete && echo -e "\n$(ls 2>&- --color -Ss1pq --block-size=1 "${PWD}/"*)" && readarray -t mi <<<"$(find . -type f ! -regex ".*\.\(sh\|id\)" -size +0 -printf "%f\n")" && vi=$(curl -s "${bo}/rest/2.0/membership/proxy/user?method=query" -A "${ua}" -b "${co}" -e "${bo}/" | jq -r '.data.member_info.is_vip') && for yu in "${mi[@]}"; do nfo=$(curl -sL "${bo}" -A "${ua}" -b "${co}" -e "${bo}/" | perl -pe 's/\%(\w\w)/chr hex $1/ge' | sed "s#\"#\\n#g;s|:||g;s|,||g" | awk 'NF') && jt=$(echo "$nfo" | grep -i 'jstok.*' -A1 | tail -1) && bt=$(echo "$nfo" | grep -i 'bdsto.*' -A1 | tail -1) && sz=$(du -b "${yu}" 2>&- | awk '{print $1}') && fn=${yu} && qt=$(curl -s "${bo}/api/quota?checkexpire=1&checkfree=1&app_id=250528&jsToken=${jt}" -A "${ua}" -b "${co}" -e "${bo}/") && to=$(echo "$qt" | jq -r '.total') && us=$(echo "$qt" | jq -r '.used') && if [[ ! ( $(grep -s '[[:digit:]]' <<<${to}) ) || ! ( $(grep -s '[[:digit:]]' <<<${on}) ) || ( -z ${rf} || -z ${mv} || -z ${bu} || -z ${ds} || -z ${on} || -z ${rm} ) ]]; then echo -e "\n$(echo "# recheck: the value of your variables, and don't forget to paste all on the shell." | sed 's/# re.*ck:/\o033[1;41m&\o033[0m/I')" && break; elif [[ $((to - us)) -lt ${sz} ]]; then echo -e "\n$(echo "# quota: is smaller than the size of current file ($(numfmt --to=iec-i --suffix=B --format='%.2f' ${sz} | sed 's/[0-9]\+/& /2')). your remaining space is $(numfmt --to=iec-i --suffix=B --format='%.2f' $((to - us)) | sed 's/[0-9]\+/& /2')." | sed 's/# quota:/\o033[1;41m&\o033[0m/I')" && break; elif [[ -z "${sz/[ ]*\n/}" ]]; then echo -e "\n$(echo '# notice: please double check whether your file exists or not!.' | sed 's/# notice:/\o033[1;41m&\o033[0m/I')" && break; else echo -e "\n$(echo '### TERABOX: preparing..! ||' "$(echo "QUOTA:" $(numfmt --to=iec-i --suffix=B --format='%.2f' "$us" | sed 's/[0-9]\+/& /2') / $(numfmt --to=iec-i --suffix=B --format='%.2f' "$to" | sed 's/[0-9]\+/& /2'))" $(printf "%$(tput cols)s" | tr " " "#") | cut -c -$COLUMNS | sed -E 's/t.*x:|q.*:/\o033[1;41m&\o033[0m/Ig')\n" && if [[ ( ${vi} -eq 1 && ${sz} -le 21474836479 ) || ( ${vi} -eq 0 && ${sz} -le 4294967296 ) ]]; then [[ ${sz} -ge 2147483648 ]] && echo -e "$(echo "# info: your file is larger than 2147483648 bytes (2.00 GiB). please wait it will be splitted into pieces!." | sed 's/# info:/\o033[1;41m&\o033[0m/I')\n" && sleep 3 && (split --verbose -b 120M "${yu}" --suffix-length=3 --numeric-suffixes=0 "${yu}".piece && echo -e "$(ls -1 *piece[[:digit:]]* > piece0a)") || echo "${yu}" > piece0a; else echo -e "$(echo "# info: size limit exceeded!. the total size of a single file for vip user is limited to 21474836479 bytes, and 4294967296 bytes for a non." | sed 's/# info:/\o033[1;41m&\o033[0m/I')\n" && break; fi && cat piece0a | while read md; do md5sum <<<"${md}" | md5sum | cut -d ' ' -f1 >> piece0b; done && md5=$(cat piece0b | sed -n 's/^/"/;s/$/"/;H;${x;s/\n/,/g;s/^,//;p}' | awk '{print "["$0"]"}') && fp=$(echo "${rf}/${yu}" | jq -Rr @uri) && tp=$(echo "${rf}/" | sed 's#/*$##;${s|$|/|}') && pc=$(curl -s "${bo}/api/precreate?app_id=250528&jsToken=${jt}" -A "${ua}" -b "${co}" -H "Origin: ${bo}" -e "${bo}/" --data-raw "path=${fp}&size=${sz}&autoinit=1&rtype=3&target_path=${tp}&block_list=${md5}") && echo "$pc" | jq -C --arg fs "$(numfmt --to=iec-i --suffix=B --format='%.2f' <<<${sz} | sed 's/[0-9]\+/& /2') (${sz} Bytes)" '.filesize = $fs | .block_list |= tostring' 2>&- || true && sleep 3 && if grep -Eiq 'uploadid.*' <<<${pc}; then echo -e "\n$(echo '### TERABOX: uploading..!' $(printf "%$(tput cols)s" | tr " " "#") | cut -c -$COLUMNS | sed "s,t.*:,\o033[1;41m&\o033[0m,I")" && ui=$(echo $pc | jq -r '.uploadid') && bl=$(cat piece0a | wc -l) && ls -1 *part* >1 2>1 && pr=0 || pr=1 && ps=0 && while read mi; do ls -1 *piece[[:digit:]]* &>/dev/null && echo -e "\n$(echo "# uploading: piece #${pr} of #${bl} left | file: ${mi} | md5: $(cat piece0b | head -1 && sed -i '1d' piece0b)" | sed -e 's/# up.*ng:/\o033[1;41m&\o033[0m/Ig' -Ee 's/piece\s|left|file:|md5:/\x1b[32m&\x1b[0m/Ig')\n" || echo -e "$(true)" && up=$(curl -iF "file=@${mi}" "$(echo $bo | sed 's/www/c-jp/')/rest/2.0/pcs/superfile2?method=upload&type=tmpfile&app_id=250528&path=${fp}&uploadid=${ui}&partseq=${ps}" -A "${ua}" -b "${co}" -H "Origin: ${bo}" -e "${bo}/") && echo -e "\n$(echo "${up}" | tail -1 | jq -C 2>&-)" && echo "${up}" | sed '$!d' | jq -r '.md5' >> piece0c && ((bl--)) && pr=$((pr+1)) && ps=$(expr $ps + 1); done < piece0a && md5=$(cat piece0c | sed -n 's/^/"/;s/$/"/;H;${x;s/\n/,/g;s/^,//;p}' | awk '{print "["$0"]"}') && if grep -Eiq 'md5.*' <<<${up}; then echo -e "\n$(echo '### TERABOX: finishing..!' $(printf "%$(tput cols)s" | tr " " "#") | cut -c -$COLUMNS | sed "s,t.*:,\o033[1;41m&\o033[0m,I")\n" && if [[ ${mv} == *"yes"* ]]; then mkdir -p ${bu} && mv -f ${yu} ${bu}; elif [[ ${rm} == *"yes"* ]]; then rm -rf ${yu}; fi && create=$(curl -s "${bo}/api/create?isdir=0&rtype=1&bdstoken=${bt}&app_id=250528&jsToken=${jt}" -A "${ua}" -b "${co}" -H "Origin: ${bo}" -e "${bo}/" --data-raw "path=${fp}&size=${sz}&uploadid=${ui}&target_path=${tp}&block_list=${md5}") && fi=$(echo -e "$(echo ${create} | jq --arg fs "$(numfmt --to=iec-i --suffix=B --format='%.2f' <<<${sz} | sed 's/[0-9]\+/& /2') (${sz} Bytes)" '.size = $fs | {"uploaded": "Glory to God for His great work!"} + .')") && grep -Eiq 'yes' <<<${ds} && pl=$(echo ${create} | jq '.path' | jq -Rr @uri) && pl=$(echo $pl | sed -n 'H;${x;s/\n/,/g;s/^,//;p}' | awk '{print "["$0"]"}') && sl=$(curl -s "${bo}/share/pset?app_id=250528&bdstoken=${bt}" -A "${ua}" -b "${co}" -e "${bo}/" --data-raw "schannel=0&channel_list=[0]&period=${on}&path_list=${pl}&public=1" | jq -r '.link') && ma=$(echo $sl | awk -F 's/1' '{print $2}') && dl=$(curl -s "${bo}/share/list?shorturl=${ma}&root=1&app_id=250528&jsToken=${jt}" -A "${ua}" -b "${co}" -e "${bo}/" | jq -r '.list[].dlink') && echo "$fi" | jq -C '.sharedlink="'"${sl}"'" | .downloadlink="'"${dl}"'"' && echo -e "Storedname: ${yu}\nSharedlink: ${sl}\nD/loadlink: ${dl}\n" >> link.id || echo "$fi" | jq -C && sleep 3 && rm -rf *piece[[:digit:]]*; else echo -e "\n$(echo '# notice: look at the uploading log above..!' $(echo "${up}" | grep -oi 'http.*' | head -1 | sed 's/\s$//') | sed -e 's/# notice:/\o033[1;41m&\o033[0m/I' -e 's/http.*/\x1b[91m&\x1b[0m/Ig')"; fi; else echo -e "\n$(echo '# notice: please, look at the precreate section..!' | sed 's/# notice:/\o033[1;41m&\o033[0m/I')\n"; fi; fi; done && echo -e "\n$(ls 2>&- --color -Ss1pq --block-size=1 *)" || echo -e "\n$(echo "# notice: check the variable values of your file source directory and its exist or not!." | sed 's/# notice:/\o033[1;41m&\o033[0m/I')\n"
### CODE ENDS HERE ####################################################################################################################################
@joandeno
Copy link

hello friend, it worked for a week but not anymore, can you please confirm this? im getting this error:
curl: (26) Failed to open/read local data from file/application

@munfaqqiha
Copy link
Author

munfaqqiha commented Sep 29, 2023

hello friend, it worked for a week but not anymore, can you please confirm this? im getting this error: curl: (26) Failed to open/read local data from file/application

Hello All. Sorry, I've been a bit busy lately so I rarely visit GitHub, so I'm a little late in hearing about your comments :-)).

@joandeno: a few minutes ago, I had no problem successfully uploading some files via the Linux terminal. So, friend:

  1. Can you try the recent version of the code (there're some things I updated)?.
  2. What OS or application are you using it on?.
  3. Are you in the correct directory containing your files (full path)?.
  4. Don't forget to pay attention to your variables. It's best to use the latest "cookies".
  5. Read the contents of the discussion here https://is.gd/5inLjv. Maybe it can inspire.

Thanks so much.

@VigramK
Copy link

VigramK commented Oct 11, 2023

Hi @munfaqqiha I have come across a problem when uploading large files. I have a file that is almost 12 GB and the files split into 103 parts of 120 MB files, but once it starts uploading it only uploads till part 100 and the file upload completes, leaving out the last 3 parts. Because of this the file that gets uploaded is incomplete. How do i fix this? I noticed that when the upload starts the "block_list" section only shows till 99 so that would explain why only the 100 parts are getting uploaded.

@VigramK
Copy link

VigramK commented Dec 17, 2023

@munfaqqiha I am not sure if you are aware, but the script isn't working right now. Been having trouble for more than a week now. Whenever i run it, i am getting "check the variable values of your file source directory and its exist or not!." error, i have tried refreshing the necessary values and still getting the error. I did try an older version of the script from June 23rd and that seems to work, but the session doesn't stay connected for long, and i need to refresh the cookie and jsToken for it to work again.

@munfaqqiha
Copy link
Author

Hello, VigramK:

The two problems you mentioned above have been resolved.

I apologize, because I've only now been able to reply to yours. This's because I rarely log in to GitHub and check my email, too.

If later you have problems again, to be quicker, you can send me a DM and/or reply to my thread on this vbulletin forum where I often discuss things. To be able to interact there you need to register.

Hope that all helps. Thanks a lot.

@AminSiddika
Copy link

AminSiddika commented Dec 21, 2023

TERABOX: preparing..! || QUOTA: 84.57 GiB / 2.00 TiB
{
"errno": 4000023,
"errmsg": "need verify",
"request_id": 157529253627312320,
"filesize": "1.58 GiB (1689685247 Bytes)",
"block_list": "null"
}
notice: please, look at the precreate section..!

How to fix this ?

@VigramK
Copy link

VigramK commented Dec 21, 2023

Hi @munfaqqiha,

Thank you for fixing the issues, i really appreciate your help. By the way there is no need to apologize, i am simply grateful that your script exists because i have been using it very extensively, and it has been so helpful for me.

I will be registering on that forum and let you know if any other issues arise in future. Thank you again.

@AminSiddika Have you tried refreshing your jsToken and Cookie in the script? Edit: I tried running the script and getting the same error

@munfaqqiha
Copy link
Author

munfaqqiha commented Dec 22, 2023

Hello, AminSiddika & VigramK:

I'm sorry. I have checked the script and it turns out that the error is in the code which turns out to cut off the required credentials. Thus, I apologize. And of course, I have corrected the script.

FYI, you can also follow a method that looks like this:

bt='d94d5a4f537413da2e4a5c1377ce43ac'
jt='01C0B19833CB93331C1720BE6B48EC48663B5C4CBD1EC79E97D0B38BA7E21FE0AF2DC76963DA652D919320A0A430A520542F6F2CF10089E8BCB406B77B74A57C'
co='ndus=YqNsh3xteHui1kjTp_Liu6NgK35P5ETQAhIN8yOM'

set +H
fl="/home/munfaqqiha/stuff"
rf="/"
mv="no"
bu="/home/munfaqqiha/stuff/backup"
ds="no"
on="0"
rm="no"

BTW, that's on Linux, adjust it to the one on Windows, and don't forget to pay attention to the info in the "ALERT" part above.

Hope that all helps. Thanks a lot.

@VigramK
Copy link

VigramK commented Dec 22, 2023

Thanks @munfaqqiha the corrected script is working perfectly!

@AminSiddika
Copy link

AminSiddika commented Dec 22, 2023

Thanks a lot @munfaqqiha ...
A Big Thanks
Your Work Is Awesome

@nis267
Copy link

nis267 commented Jan 6, 2024

I added the possibility to upload multiple files simultaneously here are the changes in my fork.
it's much faster now for example to upload pictures I had 50.000 to uplaod.
Maybe add it in your scipt? @munfaqqiha
And maybe create a repository in github so people can contribute and create pull requests?

@nis267
Copy link

nis267 commented Jan 6, 2024

In the script you use some sleeps for what are they necessary? @munfaqqiha
I removed the sleeps in my changes.

@munfaqqiha
Copy link
Author

Hello, nis267:

I'm very sorry for my delay in responding.

In the script you use some sleeps for what are they necessary? @munfaqqiha. I removed the sleeps in my changes.

It's just to see the output during the process.

I added the possibility to upload multiple files simultaneously here are the changes in my fork. It's much faster now for example to upload pictures I had 50.000 to uplaod.

I'm very happy to see you were able to add capabilities to the script.

And maybe create a repository in github so people can contribute and create pull requests?

Sure, I've activities in real life that I can't leave behind. So, I decided to give you a full freedom of access to improve, including to create a repository to organize the script. I trust your abilities. No worries, the entire script is free.

Maybe add it in your scipt? @munfaqqiha.

I haven't tried it, also I read in your fork that there's a user who are having problems with the script. So, you can fix it and do it as it should.

Good luck, and thanks a lot. Have a nice day.

@nis267
Copy link

nis267 commented Feb 8, 2024

I fixed the problems with the script and it's working now here are the changes in my fork

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