Ubuntu – “cp: failed to access ‘user@remote/home/file’: Not a directory” when copying a file over ssh, using cp file user@remove syntax

ssh

I am trying to copy a file over from my machine to my personal space on a university server. On my machine, the file is located at /home/karnivaurus/file.pdf.

If I connect to the server with ssh karnivaurus@server.uni.ac.uk, and then run pwd, it prints /homes/karnivaurus. If I run ls, it just displays one directory, foo. What I want to do then, is to copy this file over to the directory /homes/karnivaurus/foo.

So, after exiting the ssh, I enter the local home directory /home/karnivaurus. I then run the command cp paper.pdf karnivaurus@server.uni.ac.uk/foo/paper.pdf, but this returns the error message cp: failed to access ‘karnivaurus@shell1.doc.ic.ac.uk/homes/karnivaurus/paper.pdf’: Not a directory. I have also tried running cp paper.pdf karnivaurus@server.uni.ac.uk/homes/karnivaurus/foo/paper.pdf, but this gives me the same error message.

What am I doing wrong?

Best Answer

Use scp

DESCRIPTION
     scp copies files between hosts on a network.  It uses ssh(1) for data
     transfer, and uses the same authentication and provides the same security
     as ssh(1).

The basic syntax is essentially the same as that of cp

scp paper.pdf karnivaurus@server.uni.ac.uk:/homes/karnivaurus/foo/

or

scp paper.pdf karnivaurus@server.uni.ac.uk:~/foo/
Related Question