Problem with scp syntax

I am trying to copy a .tar archive from remote server to my pc.

Directory of the archive that I want to copy:

canserhan@embserv:~/tar_files/rtl_archive.tar

Destination:

serhan@serhan-Lenovo-B560:~/Documents$ 

I connect to remote server and use the command:

canserhan@embserv:~/tar_files$ scp canserhan@embserv:~/tar_files/rtl_archive.tar serhan@serhan-Lenovo-B560:~Documents$
Password:
ssh: serhan-Lenovo-B560: Name or service not known
lost connection
canserhan@embserv:~/tar_files$ 

There must be something wrong with the scp syntax I am using. However I could not figure it out. Could you please help me?

Thanks.

4

4 Answers

As a rule if you wanna send something to the remote server via scp:

scp some_files.tar user@remoteHost:
scp some_files.tar user@remoteHost:Documents/newname.tar

But if you wanna download something:

scp user@remoteHost:Documents/foo.tar ~/Desktop
scp user@remoteHost:/any/other/dir/foo.tar .

From the scp man page:

 -3 Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. Note that this option disables the progress meter.

I'd suggest that the problem is that your machine embserv cannot "see" your other machine serhan-Lenovo-B560, or, if it can, it can't resolve the name.

When you invoke scp with two remote machines, what it actually tries to do is something like this:

ssh canserhan@embserv "scp ~/tar_files/rtl_archive.tar serhan@serhan-Lenovo-B560:~Documents$"

That's a Good Thing as it means the copy will be more efficient, but it requires that scp from machine A to machine B works, which it won't always.

If that is the problem, you can solve it by using -3, or by passing the numeric IP address of serhan-Lenovo-B560 (if the name is the problem), or by fixing your ssh setup on embserv so that it can reach serhan-Lenovo-B560.

EDIT:

So, try this:

scp canserhan@embserv:~/tar_files/rtl_archive.tar :~Documents$

where xxx.xxx.xxx.xx is your server's IP address.

or, if that fails, this should definitely work, but will run more slowly:

scp -3 canserhan@embserv:~/tar_files/rtl_archive.tar serhan@serhan-Lenovo-B560:~Documents$

By the way, ~Documents$ also looks wrong. Are you sure it shouldn't be ~/Documents ?

3

Try the command:

scp ~/tar_files/rtl_archive.tar serhan@serhan-Lenovo-B560:~/Documents/

embserv is your local machine. If you write scp server1:/path/to/file server2:/path/to/second/file this instructs scp to copy a file from one server to a second server. If you want to copy a local file to a server or the other way round just skip the colons : and the machine name. In additon ~ has to be followed by a slash in your case. ~ translates to /home/username/.

1

I believe that you don't have a DNS at your network.. It looks as if though it cannot resolve your name serhan-Lenovo-B560

You can try one thing, just type the IP of remote end.

$ scp canserhan@embserv:~/tar_files/rtl_archive.tar serhan@<remote-ip>:~Documents

Moreover, try giving full/absolute path instead of ~.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like