Easiest way to copy a single file from host to Vagrant guest?

前端 未结 19 1800
暖寄归人
暖寄归人 2020-12-22 15:15

I have a use case where I occasionally want to copy a single file from my host machine to the Vagrant guest.

I don\'t want to do so via traditional provisioners (Pup

19条回答
  •  余生分开走
    2020-12-22 15:32

    An alternative way to do this without installing anything (vagrant-scp etc.) Note that the name default needs to be used as is, since vagrant ssh-config emits that.

    vg_scp() {
      tmpfile=$(mktemp /tmp/vagrant-ssh-config.XXXX)
      vagrant ssh-config > $tmpfile
      scp -F $tmpfile "$@"
      rm $tmpfile
    }
    
    # Copy from local to remote
    vg_scp somefile default:/tmp
    
    # Copy from remote to local
    vg_scp default:/tmp/somefile ./
    
    # Copy a directory from remote to local
    vg_scp -r default:/tmp ./tmp
    

    The function would not be necessary if scp -F =(vagrant ssh-config) ... would have worked across shells. But since this is not supported by Bash, we have to resort to this workaround.

提交回复
热议问题