-1

I read series of instructions and answers about scp

Example syntax for Secure Copy (scp)

scp - How to copy a file from a remote server to a local machine? - Unix & Linux Stack Exchange

but I cannot apply it correclty

$ pwd
#the local path on local machine
pwd
/Users/me/PubRepo/bash

When I tried to scp a file from remote to the local

[root@iz2ze9wve43n2nyuvmsfx5z ~]# echo "scp test message" > a_test_file.md
[root@iz2ze9wve43n2nyuvmsfx5z ~]# cat a_test_file.md
scp test message
[root@iz2ze9wve43n2nyuvmsfx5z ~]# pwd
/root
[root@iz2ze9wve43n2nyuvmsfx5z ~]# scp root@icodehero.com:a_test_file.md  .
root@icodehero.com's password: 
a_test_file.md                                                                  100%   17     3.6KB/s   00:00    
[root@iz2ze9wve43n2nyuvmsfx5z ~]# 

it indicate success to transfer, but I did not find it locally

ls | grep "a_test_file.md"
#does not return 

additionally it does not exist anywhere locally

find / -name "a_test_file.md" 2>/dev/null                                                              
## no match

What's the problem with my usage?

Wizard
  • 2,503
  • Are you intentionally prefixing your ls and find commands with a history recall mark, ! ? – Jeff Schaller Nov 05 '18 at 11:54
  • I removed them, it's a shortcut to apply commands within IPython console. @JeffSchaller – Wizard Nov 05 '18 at 11:58
  • 1
    You created a file a_test_file.md on iz2ze9wve43n2nyuvmsfx5z then copied a file with identical name from icodehero.com to iz2ze9wve43n2nyuvmsfx5z and after this operation a_test_file.md doesn't exist on iz2ze9wve43n2nyuvmsfx5z??? – jimmij Nov 05 '18 at 12:11
  • No, I scp it to the local scp your_username@remotehost.edu:foobar.txt /some/local/directory – Wizard Nov 05 '18 at 12:19
  • Oh, I got your idea, I should do it on local machine @jimmij – Wizard Nov 05 '18 at 13:19
  • “does not return” or “returns nothing”? – ctrl-alt-delor Nov 05 '18 at 13:35
  • It is hard to follow what you are doing (Which machine is which). But on iz2ze9wve43n2nyuvmsfx5z you create a file, then copy a file with the same name, from icodehero.com, over the top of the file that you just created. – ctrl-alt-delor Nov 05 '18 at 13:38

1 Answers1

1

From your console log it looks like you call scp on the remote host where a_test_file.md is created, but you use . as the second parameter, which is the destination. The call always has the source first and the destination after. Like @jimmij mentioned in the comments, this would copy another file with identical name from another remote.

So you have two possibilities:

  1. Call scp from the machine where the file should end up (your local machine). Assuming icodehero.com is your remote machine, the scp call you used is correct, just on the wrong machine.

  2. Change the scp call to scp a_test_file.md user@your_local_machine:., which is only possible if the remote can also access your local machine via ssh.


If you are wondering, why the copying was displayed as successful, I assume icodehero.com is the machine, on which you created the file, in which case your remote copied the file from itself (which overwrites the file with itself, effectively doing nothing).

crater2150
  • 3,946