Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SFTP upload script example? #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
germain-italic opened this issue Sep 15, 2021 · 4 comments
Closed

SFTP upload script example? #709

germain-italic opened this issue Sep 15, 2021 · 4 comments

Comments

@germain-italic
Copy link

I'm aware of the the custom script upload feature, but I have no idea how to make a script that would upload an image to my SFTP server. Hints, anybody?

Ref: #268

@DamirPorobic
Copy link
Member

Not sure about the script, I would have to google it my self but I can try to implement this feature in the next upcoming release #104 which I have open since 2018

@germain-italic
Copy link
Author

That'd be awesome for end-users like me!

@DamirPorobic
Copy link
Member

SFTP seems to be a bit more complex way to go then ftp but there should be a way. Let's move further discussion to the initial issue.

@ztjuh
Copy link

ztjuh commented Jan 8, 2024

This will upload the image to the server and copy the url to clipboard.

You need to install sshpass and put your ssh password in a file, or you can use a ssh key, customize to your own need.

#!/bin/bash
# God bless you
#
# Credits: https://www.lexo.ch/blog/2023/08/ksnip-custom-ftp-upload-script-upload-screenshots-to-your-ftp-server-fully-automatic/
#
# requirements: sshpass rsync libnotify-bin

DATE=$(date +%Y%m%d-%H%M%S)
SAVE_DIR=~/Pictures
SAVE_NAME=ksnip_${DATE}.png

FILE=${SAVE_DIR}/${SAVE_NAME}
cp $@ ${FILE}
chmod 644 ${FILE}

PASS=passwordfile
USER=
HOST=
PORT=
REMOTE_DIR=
URL=https://domain/${SAVE_NAME}
OPEN_BROWSER=1

CMD=$(sshpass -f${PASS} rsync -ze "ssh -p ${PORT}" ${FILE} ${USER}@${HOST}:${REMOTE_DIR} 2>&1)

if [ $? -eq 0 ]; then
 echo "${URL}"
 notify-send "Screenshot successfully uploaded to ${URL}"
 if [ ${OPEN_BROWSER} -eq 1 ]; then
   xdg-open ${URL}
 fi
else
 notify-send "Error uploading screenshot. Error: ${CMD}"
 echo "${CMD}"
fi

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

No branches or pull requests

3 participants