Create two files, remember to have +x execution right on both and ensure you have used commands in your system. And ssh cert for user to be copied by ssh-copy-id, so we don’t need to worry about passwords.
definition ~/.local/share/kio/servicemenus/upload.desktop
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KonqPopupMenu/Plugin
MimeType=all/all;
Actions=UploadToServer
X-KDE-Priority=TopLevel
[Desktop Action UploadToServer]
Name=Upload to my external http server
Icon=folder-upload
Exec=/home/oxef/.local/bin/upload-to-server.sh %U
script itself, optimally in ~/.local/bin/
#!/usr/bin/env bash
# Configuration
SSH_USER="root"
SSH_HOST="example.com"
REMOTE_PATH="/my/apache/or/nginx/or/whatever/folder"
WEB_DOMAIN="https://example.com/location/folder"
for f in "$@"
do
# Get filename
filename=$(basename "$f")
# Upload file/directory
scp -r "$f" "${SSH_USER}@${SSH_HOST}:${REMOTE_PATH}/${filename}"
# Schedule deletion in 60 minutes
ssh "${SSH_USER}@${SSH_HOST}" "nohup sh -c 'sleep 3600 && rm -rf \"${REMOTE_PATH}/${filename}\"' > /dev/null 2>&1 &"
# Build URL and copy to clipboard
url="${WEB_DOMAIN}/${filename}"
echo -n "$url" | wl-copy
# Show notification
kdialog --passivepopup "URL copied to clipboard (expires in 60 min)" 5 --title "File uploaded" 2>/dev/null
done
Effect is the link automatically placed in clipboard and a notification saying that everything went correctly.
