Tag Archives: SSH

Send files via SSH/SCP with Nautilus

I wanted a quick and easy way to share files, images, scripts etc. I searched for this about two years ago, but couldn’t find it. So I wrote my own, and wrote about it on my norwegian blog.

Recently Omg! Ubuntu! wrote about a Nautilus Imgur-uploading script, and I wrote a small comment saying that I’ve used the same for some time, only to my own servers and using SCP. I said it also supported FTP, but I don’t know where I took that from, it doesn’t and I have no need for FTP :-)

Anyway, this is how it works:

  1. Right click file (or files!) in Nautilus
  2. Choose script -> Send to Thor (where Thor is the name of a server)
  3. Wait a bit, and you will get a small notification saying that the file is uploaded
  4. To make it easy to share, the script sets your selection clipboard to the url, so that you can just paste away

I use this directory structure, mostly:


You may download the send_via_scp script here.

I’m also pasting in this version of the script, just so that it doesn’t disappear.

[code lang=”bash”] #!/bin/bash # Send your files to another machine using SCP # REQUIRED # – Nautilus (doh!) # – scp # – notify-send (from package notify-bin, libnotify – for messages) # – xclip (to automaticaly set your clipboard to the URL of the file) # To use (for single server): # 1. Copy to ${HOME}/.gnome2/nautilus-scripts # 2. Rename to "Send to MYSERVER" and make executable (chmod a+x) # 3. Change the options below # # To use (for multiple servers): # 1. Copy to your ${HOME}/.gnome2/nautilus-scripts directory # 2. Make a file named "Send to MYSERVER" in the same directory # 3. Put this into it: # ————— # #!/bin/bash # # SCP_URL="odin@odin.s0.no:public_html/rot/`hostname`/" # HTTP_URL="http://odin.s0.no/rot/`hostname`/" # PROGNAME=`basename "$0"` # dir=`dirname "$0"` # # export SCP_URL HTTP_URL PROGNAME # source $dir/send_via_scp # ————— # # 4. Make it executable (you don’t have to make send_via_scp executable) # Author: Odin Hørthe Omdal < odin.omdal at gmail [dot] com > # Version: 1.1 # Based upon the script to make symbolic links by # Author: Jon Green < g-scripts [at] green-lines [dot] com > # Version: 1.0 if [ "x$SCP_URL" == "x" ]; then # OPTIONS, edit these SCP_URL="user@domain:public_html/folder/" HTTP_URL="http://domain/folder/" # This is the name it will use for notifications PROGNAME=`basename "$0"` fi #### You don’t have to edit below here ### warning() { notify-send -i gtk-dialog-error "$PROGNAME" "$*" } message() { notify-send -i gtk-dialog-info "$PROGNAME" "$*" } declare -a NAUTFILES export IX=0 while read FILE; do if [ "x${FILE}" != "x" -a "x${FILE}" != ‘x"’ ]; then NAUTFILES[${IX}]="${FILE}" IX=$[ ${IX} + 1 ] fi done <<EOF ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[@]} EOF if [ 0 -eq ${IX} ]; then URI="${NAUTILUS_SCRIPT_CURRENT_URI}" METHOD="${URI:0:7}" if [ "file://" == "${METHOD}" ]; then NAUTFILES[0]="${URI:7}" IX=1 fi fi if [ 0 == "${#NAUTFILES[@]}" ]; then warning "Nothing to do" exit fi for FILE in "${NAUTFILES[@]}"; do FILE_NAME=`basename "${FILE}"`; if ! scp "${FILE}" "$SCP_URL"; then warning "Couldn’t send ${FILE_NAME}" else message "Uploaded to <a href=’${HTTP_URL}${FILE_NAME}’>${HTTP_URL}${FILE_NAME}</a>" fi # Save the URL to the clip board echo "${HTTP_URL}${FILE_NAME}" | xclip done [/code]