From 2080e8c24c1bdab1298ea4d51b2a79f5dc9b1c48 Mon Sep 17 00:00:00 2001 From: joseph <joseph@X6> Date: Mon, 18 Apr 2022 09:40:25 +0100 Subject: [PATCH] Now prepending a random string of numbers to the file to avoid people finding other uploaded files by noting potential patterns in file names. --- srvrupload.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/srvrupload.sh b/srvrupload.sh index 4c8f6b2..ce2610d 100755 --- a/srvrupload.sh +++ b/srvrupload.sh @@ -3,19 +3,35 @@ #### EDIT THESE VARIABLES #### # The URL or IP of your server serverURL="yourserver.com" + # The username and password of the remote user you'll be using SFTP with serverUsername="user" serverPassword="strongandcomplicatedpassword" -# The port expected by the server + +# The port expected by the server for sftp serverPort=22 + # Remote path to upload the file to remote_path=/var/www/public/ + # The URL (excluding file name) you expect the file to have to be accessible expectedURL="https://yourserver.com/public/" +# Path to the file to be uploaded local_path=$1 -sshpass -p $serverPassword scp -P $serverPort $local_path $serverUsername@$serverURL:$remote_path + +# Name of the file to be uploaded fileName=$(basename $local_path) -link=$expectedURL$fileName + +# Generates a random number to be prepended to the file name +randomString=$(shuf -i 100000000000-999999999999 -n 1) + +cp $local_path /tmp/$fileName +mv /tmp/$fileName /tmp/$randomString$fileName +local_path=/tmp/$randomString$fileName + +# Uploading the file +sshpass -p $serverPassword scp -P $serverPort $local_path $serverUsername@$serverURL:$remote_path +link=$expectedURL$randomString$fileName echo $link | xclip -notify-send --app-name="Server Upload" --icon="cloud-upload" "Link copied to xclip $link" --expire-time=5000 > /dev/null 2>&1 \ No newline at end of file +notify-send --app-name="Server Upload" --icon="cloud-upload" "Link copied to xclip $link" --expire-time=5000 > /dev/null 2>&1 -- GitLab