How can I copy files with SSH?

12

4

I am trying to copy a file from my other computer, to another computer. (both running Ubuntu 9.10)

So, I've ssh'ed into the other computer; I cd to the directory; and I entered cp File.zip /home/me/Desktop as file.zip is located in the directory I just used cd with.

Now, it gives me the following error message:

cannot create regular file '/home/me/Desktop': no such file or directory

What do I have to do?

Deniz Zoeteman

Posted 2010-01-06T17:45:45.390

Reputation: 1 001

Answers

27

This isn't really programming related, but you can use scp to do this.

scp file.zip remote-box-name:/path/to/destination/file.zip

If your username is different on the remote box, you will need to prefix it:

scp file.zip yourusername@remotebox:/path/to/destination/file.zip

And to retrieve a file you could do this:

scp remotebox:/path/to/destination/file.zip file.zip

Scott Anderson

Posted 2010-01-06T17:45:45.390

Reputation: 654

can we retrieve multiple files? – ZhaoGang – 2018-08-01T02:50:14.367

how does that work when i am sshed into the other computer on the computer where i want to copy the file to? Because when i try like scp file.zip me@xxx.xxx.xx.xxx:/home/me/Desktop, it says 'connection refused', probably because it is the computer im on. How to? – Deniz Zoeteman – 2010-01-06T18:15:32.783

The syntax is src_file dest_file, where either can be just a filename on a local computer (file.zip), or a remote file (me@xxx.xxx.xx.xxx:/home/me/Desktop). So if you want to pull a files from a remote machine to the local machine, you would do scp xxx.xxx.xx.xxx:/home/me/Desktop/file.zip file.zip.

Note that local and remote are relative to the machine you are running the scp. So if you are on machine A, ssh to machine B and do an scp, B is local and A is remote. – KeithB – 2010-01-06T18:23:10.520

It still gives the same error as i shown in the question – Deniz Zoeteman – 2010-01-06T18:34:41.213

when i try to do it from local machine, it says 'no route to host' or something like that... probably because it is protected with a password. – Deniz Zoeteman – 2010-01-06T18:38:38.290

sftp is another good option if you're comfortable with ftp and are doing this manually. – Brian Knoblauch – 2010-01-06T20:08:23.133

@TutorialPoint: 'no route to host' indicates you have a general networking problem, not an scp problem. Try http://www.cyberciti.biz/tips/no-route-to-host-error-and-solution.html

– DaveParillo – 2010-01-06T20:09:34.550

8

  1. On machine A, open two terminal windows

  2. On machine A, ssh to machine B. Look around, find the path on machine B to the file you wish to copy

  3. On machine A, the second terminal window type:

scp yourusername@remotebox:/path/to/destination/file.zip /home/me/Desktop

The file should be copied from machine B to machine A, in to the /home/me/Desktop folder (if the folder exists on Machine A

You can't copy over the existing ssh session. You need to create a second session. As others have noted:

  • yourusername is for Machine B, and is only needed if the username for Machine B is different than on Machine A

  • remotebox can be a resolvable name or an IP address

Alternatives:

  • Places -> Connect to Server, and then select Service Type of SSH from the pulldown menu of the Connect to Server dialog box

pcapademic

Posted 2010-01-06T17:45:45.390

Reputation: 3 283

if i want to copy a folder ? how – shareef – 2015-07-06T08:32:56.820

0

Mount remote machine locally with sshfs and copy files with your favorite tool- cp, nautilus, konqueror, dolphin, mc etc.

or use fish://username@servername in konqueror or dolphi top open the remote location

jet

Posted 2010-01-06T17:45:45.390

Reputation: 2 675

0

try the following command:

scp File.zip username@AnotherComputer:~/

CodeRain

Posted 2010-01-06T17:45:45.390

Reputation: 101

0

you need to use scp to either pull or push the file. From one machine to the other, you'd do something like

scp File.zip username@ipaddress:/home/me/Desktop/file.zip

Michael Doornbos

Posted 2010-01-06T17:45:45.390

Reputation: