Skip to content
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

Add a scp command #120

Closed
mietek opened this issue Oct 3, 2014 · 8 comments
Closed

Add a scp command #120

mietek opened this issue Oct 3, 2014 · 8 comments

Comments

@mietek
Copy link

mietek commented Oct 3, 2014

It would be great to be easily able to scp files to droplets.

@petems
Copy link
Owner

petems commented Oct 3, 2014

Good idea, or even rsync! 👍

@mietek
Copy link
Author

mietek commented Oct 3, 2014

FWIW, here's my current workaround:

function tug () {
    local info
    info=`tugboat info "$1"` || return 1
    awk '/IP:/ { print $2 }' <<<"${info}"
}

function tugpath () {
    case "$1" in
    *:*)
        local ip
        ip=`tug "${1%:*}"` || return 1
        echo "root@${ip}:${1#*:}"
        ;;
    *)
        echo "$1"
    esac
}

function tugscp () {
    local from to
    from=`tugpath "$1"` || return 1
    to=`tugpath "$2"` || return 1
    scp "${from}" "${to}"
}

Goes well with a somewhat lenient ssh config, shown here with what is presumably the London data centre IP range:

Host 178.62.*
  LogLevel quiet
  StrictHostKeyChecking no
  UserKnownHostsFile=/dev/null

Works both for uploads and downloads:

$ touch baz
$ tugscp baz foobar:
baz                                           100%    0     0.0KB/s   00:00 
$ rm baz
$ tugscp foobar:baz .
baz                                           100%    0     0.0KB/s   00:00 

@mietek
Copy link
Author

mietek commented Oct 3, 2014

@petems: You may find e.g. Ubuntu 10.04 LTS doesn't ship with rsync:

$ rsync baz `tugpath oldbar:baz`
bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [sender=2.6.9]

Nevertheless, a native rsync command would be great, too:

$ rsync -v baz `tugpath foobar:baz`
baz

sent 80 bytes  received 42 bytes  81.33 bytes/sec
total size is 0  speedup is 0.00
``

@mxdpeep
Copy link

mxdpeep commented Nov 3, 2014

BTW I would opt for not using Ubuntu 10.04 LTS anymore ...

@niko
Copy link

niko commented Aug 19, 2015

My wrapper looks like this:

#!/bin/bash

function tug-remove-ssh-config(){
  local NAME=$1
  if test -z "$NAME"; then echo "no name given"; return 1; fi

  sed "\|# ${NAME}|,+3 d" ~/.ssh/config-digitalocean
}

function tug-add-ssh-config(){
  local NAME=$1
  local IP=$2

  if test -z "$NAME"; then echo "no name given"; return 1; fi
  if test -z "$IP";   then echo "no ip given";   return 1; fi

  # if you add lines here, remember to remove them in tug-tug-remove-ssh-config()
cat <<EOF > ~/.ssh/config-digitalocean
# $NAME $(date)
Host $NAME
  HostName $IP
  User root

EOF
}

function tug-create(){
  local NAME=$1
  if test -z "$NAME"; then echo "no name given"; return 1; fi

  tugboat create $NAME -i SOMEID -r 10 -k SOMESSHKEY
  tugboat wait $NAME

  local IP=$(tugboat info $NAME | awk '/IP:/ { print $2  }')

  tug-remove-ssh-config $NAME
  tug-add-ssh-config $NAME $IP
}

alias tug-ssh="ssh -F ~/.ssh/config-digitalocean"
alias tug-scp="scp -F ~/.ssh/config-digitalocean"

The benefit of aliasing ssh instead of using tugboat ssh is that I can open tunnels etc. just as with the native ssh command… because it is the native ssh command. ;)

The drawback is it only works for droplets created by the script a.t.m..

@suin
Copy link

suin commented Nov 25, 2015

+1

@petems
Copy link
Owner

petems commented Nov 29, 2015

This probably the next big feature I want to work on, I might have some free time over the christmas period so hopefully I'll be able to give it some time over December! 👍

petems added a commit that referenced this issue Nov 22, 2017
petems added a commit that referenced this issue Nov 22, 2017
@petems
Copy link
Owner

petems commented Nov 22, 2017

Only took over 3 years but initial minimal version of the feature has been added here! #291

petems added a commit that referenced this issue Nov 22, 2017
petems added a commit that referenced this issue Nov 22, 2017
petems added a commit that referenced this issue Nov 22, 2017
petems added a commit that referenced this issue Nov 22, 2017
petems added a commit that referenced this issue Dec 3, 2017
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

5 participants