Question

Attempting to scp from one droplet to another only copied to local droplet

I had to instantiate a droplet from a snapshot of another droplet to recover some files I managed to delete. I logged into the new Droplet (lz2), created an ssh key pair, and copied and pasted the id_rsa.pub key contents to the authorized_keys file on the orignal Droplet. I was able to ssh to it after that without issue.

But try as I might, I could not get scp or rsync to work. They would just copy to the local host. I tried invoking it several different ways:

rmann@lz2:~$ scp nginx.tgz lz1:
rmann@lz2:~$ scp nginx.tgz lz1:ng.tgz
rmann@lz2:~$ scp nginx.tgz rmann@lz1:ng.tgz
rmann@lz2:~$ scp nginx.tgz <lz1’s IP address>:ng.tgz

All of them resulted in ng.tgz being created in ~rmann on lz2. For the life of me I can’t figure out what was happening.

I ended up copying the file down to my laptop from lz2 and back up to lz1.

Any idea why it wouldn’t copy from one Droplet to the other, but also not give me an error, isntead copying to the local machine?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
March 6, 2024

Hey!

When you’re using scp to copy files from one host to another, the syntax should specify the source and destination clearly. If you’re executing the command from lz2 and want to copy a file to lz1, you should specify the user and host for the destination along with the full path. If rmann is your username on both droplets and lz1 is the hostname or IP address of the destination droplet, the command should look like this:

scp nginx.tgz rmann@lz1:/home/your-user/ng.tgz

Or, if you want to use the IP address of lz1, it would be:

scp nginx.tgz rmann@<lz1's IP address>:/home/your-user/ng.tgz

This command tells scp to copy nginx.tgz to the /home/your-user/ directory on lz1, saving it as ng.tgz.

If these commands still result in the file being copied to the local machine (lz2), it’s highly unusual behavior for scp. Ensure that the hostname or IP address for lz1 is correct and reachable. If there’s any confusion about the hostnames, using the IP address can eliminate any potential DNS or host file misconfigurations.

Also, using the -v flag for verbose output can help diagnose the issue, as it will provide detailed information about the scp process and where it might be going wrong.

Let me know how it goes!

Best,

Bobby

KFSys
Site Moderator
Site Moderator badge
March 6, 2024

Heya @jetforme,

Okay, if you can SSH from one droplet to the other then you have access between them. From where did you run SCP? You’ll need to enter one of the Droplets(it doesn’t matter which, it would matter only to the command) and SCP the files to or from the other.

Now, let’s assume you have SSHed to Droplet 1 and you need to copy files from Droplet 2 to Droplet 1.

Here is how it should work

scp username@droplet2_ip:/path/to/remote/file /local/droplet1/path
  • Replace username with your username on Droplet 2, droplet2_ip with Droplet 2’s IP address, /path/to/remote/file with the file’s path on Droplet 2, and /local/droplet1/path with the path on Droplet 1 where you want the file to be copied to. That should do the trick.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.