Sixem

Upload File SSH/SFTP w/ Clipboard & Open URL

Dec 1st, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # requirements: sudo apt-get install sshpass zenity
  4.  
  5. beep() {
  6.     paplay /usr/share/sounds/KDE-Im-Irc-Event.ogg &
  7. }
  8.  
  9. filename="$(zenity --file-selection)"
  10.  
  11. # your final url, the filename will be added at the end (remember / at the end)
  12. prefix_url='https://website.co/'
  13.  
  14. # server side upload location (remember / at the end)
  15. ssh_location='/var/www/img/'
  16. # server password
  17. ssh_pass='my_password'
  18. # server username
  19. ssh_user='admin'
  20. # server domain (no www/http etc)
  21. ssh_domain='website.co'
  22. # what to chmod the file to after upload
  23. ssh_chmod=777
  24.  
  25. # self explanatory
  26. after_play_sound=true
  27. after_open_browser=true
  28. after_copy_to_clipboard=true
  29.  
  30. escaped=$(printf %q "$ssh_location"$(basename "$filename"))
  31.  
  32. sshpass -p $ssh_pass scp "$filename" $ssh_user@$ssh_domain:$ssh_location
  33. sshpass -p $ssh_pass ssh $ssh_user@$ssh_domain chmod -R $ssh_chmod "$escaped"
  34.  
  35. url=$prefix_url$(basename "$filename")
  36.  
  37. if [ "$after_copy_to_clipboard" = true ] ; then
  38.     echo -n $url | xclip -selection c
  39. fi
  40.  
  41. if [ "$after_play_sound" = true ] ; then
  42.     beep
  43. fi
  44.  
  45. if [ "$after_open_browser" = true ] ; then
  46.     xdg-open "$url"
  47. fi
Add Comment
Please, Sign In to add comment