21

I'd like to copy my config.yml file from my local django app directory to my heroku server, but I'm not sure how to get the user@host.com format for heroku.

I've tried running 'heroku run bash'

scp  /home/user/app/config.yml

I'm not sure how I can get it in the

scp user@myhost.com:/home/user/dir1/file.txt user@myhost.com:/home/user/dir2' 

format

user2738206
  • 388
  • 2
  • 4
  • 14

7 Answers7

33

As @tamas7 said it's firewalled, but your local machine is probably also firewalled. So unless you have a private server with SSH accessible from the Internet, you won't be able to scp.

I'm personally using transfer.sh free and open source service.

Upload your config.yml to it:

$ curl --upload-file ./config.yml https://transfer.sh/
https://transfer.sh/66nb8/config.yml

Then download it back from wherever you want:

$ wget https://transfer.sh/66nb8/config.yml
Andre Miras
  • 3,580
  • 44
  • 47
  • Really upload config files unencrypted? – Michael Jun 17 '17 at 07:27
  • 2
    @Michael, yes you can use gpg if you want, but that was not the OP question and I tried to keep it straightforward. Feel free to add a complement answer to this one if you think it's useful. – Andre Miras Jun 17 '17 at 10:20
  • Neat trick, really useful for what I was looking for. Thanks. – Gunnar Jun 30 '17 at 17:55
  • 1
    If you want to encrypt it you can upload it using: `cat | gpg -ac -o- | curl -X PUT -T "-" https://transfer.sh/.gpg` And download it using: `curl https://transfer.sh//.gpg | gpg -o- > ` – niklasae Feb 26 '18 at 13:08
  • Is this safe I upload my .env file to transfer.sh ..? – Tri Nov 07 '19 at 14:08
  • 1
    Depends what you mean by safe @GofyandKitty, but you can always encrypt it – Andre Miras Nov 08 '19 at 12:04
  • transfer.sh does not seem to work right now. https://file.io seems to be an alternative – Zuabi Jun 19 '20 at 13:18
7

According to http://www.evans.io/posts/heroku-survival-guide/ incoming connections are firewalled off. In this case you need to approach your local machine from the Heroku server.

heroku run bash
scp user@mylocalmachine:/home/user/dir/file.txt .
tamas7
  • 116
  • 4
3

This is a bit late to answer this question, but I use services like localtunnel - https://localtunnel.github.io/www/ to copy files from local machine to heroku.

First, run a python HTTP server in the directory where the file is located.

cd /path/to/file
python3 -m http.server

This starts a server in port 8000. Configure localtunnel to connect to that port.

lt -s mylocal -p 8000

Now from your heroku machine, you can fetch the file via curl.

curl -XGET http://mylocal.localtunnel.me/myfile.txt > myfile.txt
Aswin Murugesh
  • 10,831
  • 10
  • 40
  • 69
2

You could also use a service like https://ngrok.com/ to open up a TCP tunnel into your local machine.

You will need to enable Remote Login as in simlmx answer.

On your local machine open the TCP tunnel just like this:

$ ngrok tcp 22

And then, on the Heroku console, just use SCP with the PORT and HOST that Ngrok provided.

$ scp -P [PORT] username@[HOST]:~/path/to/file.ext .
0

If you need to download your entire repo, for example to recover an app that you no longer have locally, use heroku git:clone -a myapp. Docs.

s2t2
  • 2,462
  • 5
  • 37
  • 47
0

Expanding on tamas7's answer:

You can connect to your computer from the heroku server.

If your computer is behind a router, you'll also need to forward the connection to your computer.

1. You computer must accept ssh connections

On my mac it was as simple as enabling it in the Preferences / Sharing panel. enter image description here

2. Your router needs to forward the connection to your computer.

Go to your router's settings page in your browser (typically 192.168.0.1 but varies depending on the router). Find the port forwarding section and forward some port to your computer on port 22.

This is how it looked on my tp-link: enter image description here

Here I am making sure that port 22000 is forwarded to my computer (192.168.0.110) on port 22.

3. Find your external IP

Simply google "what is my IP".

4. Scp your file from heroku

heroku run bash
scp -P 22000 your_user@your_external_IP:/path/to/your/file .

5. Undo everything!

Once you're done it's probably good practice to disable the port forwarding and remote login.

simlmx
  • 999
  • 12
  • 17
0

It appears that heroku is not designed for files to be uploaded manually like this, at least persistently. See https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted-from-the-application

jason
  • 1
  • 1
  • 1