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?

  • 11
    scp paper.pdf karnivaurus@server.uni.ac.uk/foo/ cp is a local copy operation. scp is for performing a cp over ssh. – user4556274 Aug 5 '16 at 14:35
  • 8
    @user4556274 You forgot the : in the command. It would be scp paper.pdf karnivaurus@server.uni.ac.uk:/foo/ – Terrance Aug 5 '16 at 14:39
  • 1
    Aye. I copy-pasted the destination from the question without looking closely enough. Thanks. – user4556274 Aug 5 '16 at 14:42
  • 1
    Related unix.stackexchange.com/a/188289/68757 – heemayl Aug 5 '16 at 16:25
  • 1
    Possible duplicate of copy files over ssh – David Foerster Aug 5 '16 at 23:13

Use scp

     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/


scp paper.pdf karnivaurus@server.uni.ac.uk:~/foo/
| improve this answer | |

Some other ways to transfer files when you have ssh access:

  • rsync:

    rsync -av paper.pdf karnivaurus@server.uni.ac.uk:/where/to/put/

    replace /where/to/put/ with your desired directory name, it can be a filename too if you want to rename the file on the remote host given the intermediate directories exist.

    rsync has a big advantage over scp that it uses the delta transfer algorithm, so if for some reason the transfer halted in the middle, you can resume the transfer from that place again using rsync.

  • Direct ssh:

    ssh karnivaurus@server.uni.ac.uk 'cat >/where/to/put/paper.pdf' <paper.pdf

    Here transferring the file with direct ssh, sending the input file on STDIN of ssh, which is forwarded to the remote command and running the command cat >/where/to/put/paper.pdf on the remote host. After operation the file will be available as /where/to/put/paper.pdf on server.uni.ac.uk, change the path to meet your need.

| improve this answer | |

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.