Skip to content

Instantly share code, notes, and snippets.

@c4p-n1ck
Created March 1, 2022 10:58
Show Gist options
  • Save c4p-n1ck/bb8b9453fabb418b0bf8407409733dc1 to your computer and use it in GitHub Desktop.
Save c4p-n1ck/bb8b9453fabb418b0bf8407409733dc1 to your computer and use it in GitHub Desktop.
Uploads files to https://Gofile.io using curl, cut, jq.
#!/bin/bash
export FPATH=$1; export URL="https://$(curl -s https://api.gofile.io/getServer | cut -d '"' -f 10).gofile.io/uploadFile"
export API_TOKEN=""; export ROOT_FOLDER_ID="" # Please insert your variables here from https://gofile to make folder creation possible on the server.
# INFO: TODO: Iterate over given arguments (Iterate than using $1).
if [ -f $FPATH ]; then
echo "[*] Uploading File -> $1"
if [ $API_TOKEN ]; then
curl --progress-bar -F file="@$1" $URL -F "token=$API_TOKEN" | jq
else
curl --progress-bar -F file="@$1" $URL -F | jq
fi
elif [ -d $FPATH ]; then
if [ $API_TOKEN ]; then
echo "[*] Zipping the directory, since the token isn't present."
RDIR="/tmp/$RANDOM"; mkdir $RDIR
FNAME="$RDIR/$1.zip"
zip -r "$1" "$FNAME"
curl --progress-bar -F file="@$FNAME" $URL -F | jq
rm -rf $RDIR
else
cd $FPATH; echo "[*] Creating Folder -> $FPATH"
NEW_FOLDER_ID=$(curl -s https://api.gofile.io/createFolder -X PUT -d "parentFolderId=$ROOT_FOLDER_ID&token=$API_TOKEN&folderName=$FPATH" | cut -d '"' -f 10)
for FILENAME in *; do
echo "[*] Uploading File -> $FILENAME"
curl --progress-bar -F file="@$FILENAME" $URL -F "token=$API_TOKEN" -F "folderId=$NEW_FOLDER_ID" | jq
done
cd ->/dev/null;
fi
else
echo "[-] File/FOLDER -> $1 doesn't exist."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment