cp: cannot stat : No such file or directory
Solution 1
If you are logged into the local machine, you would use scp
like this:
scp /home/username/some.xml [email protected]:/path/to/directory/
If you are logged into the remote machine (as in the OP), use scp
like this:
scp [email protected]:/home/username/some.xml /path/to/directory
Substitute the IP addresses as directed in the commands.
Solution 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 [email protected]:/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.
Related videos on Youtube
RabT
Updated on September 18, 2022Comments
-
RabT almost 2 years
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 usecp
orscp
.Here is my input at the resulting error:
[[email protected] /]# cp /home/username/some.xml [email protected]:/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?-
Mark Plotnick over 9 yearsCan you paste the output of (as root)
ls -l /home/username/some.xml
? -
Chris Davidson over 9 yearsYou 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.
-
RabT over 9 years@MarkPlotnick Your suggestions caused me to solve the problem. As
[email protected]
, I typedexit
, then typed thescp
command above and it worked. The problem was that I was logged in as[email protected]
, so it was only seeing the directory structure ofremote.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.
-
-
RabT over 9 yearsThat 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
orcp
. -
Paramjit about 6 yearsAfter trying different solutions whole day this one works for me.