10

I am getting an error when I try to copy a file from my local computer to a remote server with ssh. I get the same error whether I use cp or scp.

Here is my input at the resulting error:

[root@xxx.xx.xxx.xx /]# cp /home/username/some.xml root@xxx.xx.xxx.xx:/path/to/directory/  
cp: cannot stat ‘/home/username/some.xml’: No such file or directory

I have checked, and there is definitely a file at the path /home/username/some.xml on my local machine.

Both the local computer and the remote server are running CentOS 7. How can I resolve this error and copy successfully?

  • 1
    Can you paste the output of (as root) ls -l /home/username/some.xml ? – Mark Plotnick Dec 9 '14 at 20:37
  • You need to get the correct path for the filename to start with, if you can find the file in the file browser you should be able to find it in the terminal by navigating directories with cd and using ls to view further files & directories. – Chris Davidson Dec 9 '14 at 20:45
  • @MarkPlotnick Your suggestions caused me to solve the problem. As root@remote.server.ip, I typed exit, then typed the scp command above and it worked. The problem was that I was logged in as root@remote.web.server, so it was only seeing the directory structure of remote.web.server, which is different than the directory structure of my local machine. Since you caused me to find this, I would be happy to accept an answer that you might submit. Thank you. – CodeMed Dec 9 '14 at 21:13
6

If you are logged into the local machine, you would use scp like this:

scp /home/username/some.xml root@remote.machine.ip.address:/path/to/directory/

If you are logged into the remote machine (as in the OP), use scp like this:

scp username@local.machine.ip.address:/home/username/some.xml /path/to/directory

Substitute the IP addresses as directed in the commands.

  • After trying different solutions whole day this one works for me. – Hobby Dev Jun 3 '18 at 14:01
2

Firstly you will have to use SCP, there is no way to just use cp to copy files over the network.

The scp command should look like the following from your example, note that the directory structure will need to exist on the server receiving the files side;

scp /home/username/some.xml root@xxx.xxx.xxx.xxx:/path/to/directory/

If you haven't already then you will need to logon to the server you're copying the file to and create the directory you wish to copy the file to, i.e;

mkdir /path/to/directory

An alternative would be to use rsync.

  • That does not work. I just tried it again now, checking that I did exactly as you wrote, which is the same thing I referred to in my OP above when I stated that this generates the same error whether I use scp or cp. – CodeMed Dec 9 '14 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.