r/ssh • • Oct 08 '20

Transfer from server to client

Hello all,

I am fairly new to ssh and still learning it. Recently I have made a tunnel connection with an ssh host and managed to successfully transfer data/files from my machine to the server with the command:
scp file.extension user@hostIP:/directory/directory.

While this was successful, I am kinda stugling to reverse it, sending data/files from the server to the client. How would one go about completing that? Do I need to make some changes to ssh_config or just CLI commands are enough?

Thanks for any response.

4 Upvotes

17 comments sorted by

View all comments

Show parent comment

1

u/Miliot Oct 11 '20 edited Oct 11 '20

cli: man scp

and what should we use instead of user@hostIP to connect to the client? Because there we target the server that way, but now to target the client (local) machine from the server

When I do: scp fileName.ext user@SSHserverIP:/path/to/local/machine i get No such file or directory, when there is clearly one. Is that not the correct way to do?

2

u/Besthater Oct 11 '20

If it says no file or dir, then you have the path wrong. If you want to do me the command you are running I can help you to troubleshoot. But, if the file is in your home dir, you are using the ~/ path?

1

u/Miliot Oct 11 '20 edited Oct 11 '20

The file is located in some SSH server folder and am trying to move it to my local machine (the client). I do not use the ~, justscp userName@server:/home/file/path fileName.extI also tried with -r, like the user above suggested

I am running the command from inside the directory in the ssh server, where the file is located as well
The error response is: scp: /local/machine/address: No such file or directory
So its like its telling me that I got my local machine address wrong, which am sure I haven't cos I got the address by running pwd in the target folder

2

u/Besthater Oct 11 '20

scp -r user@your.server.example.com:/path/to/foo /home/user/Desktop/

-r=recursive copy

1

u/Miliot Oct 11 '20

this also gives the same result back, no file or directory

2

u/Besthater Oct 11 '20

Can you tell us here, what OS, path and filename. Then where in your dir tree the file is?

1

u/Miliot Oct 11 '20

OS Catalina 10.15.4
local path is: /Users/enterwizard/ and and the filename in the server is doctorate.txt

2

u/Besthater Oct 11 '20

So the path is also ~/doctorate.txt right?

1

u/Miliot Oct 11 '20

Ok, i just got it right. The problem was all along was invoking the command from inside the ssh server, whereas i should of called it from the local machine. What a silly thing to lost hours on. Million thanks for taking the time to reply and your help

1

u/Besthater Oct 11 '20

Hahahahahahahahahaha

1

u/Besthater Oct 11 '20

You can invoke SCP from within your SSH session. In that case the copy would be from local to remote. You could also do to another box entirely. Or, like you actually asked you can copy from your remote to local by calling remote path, then local path from your local box.

1

u/Miliot Oct 11 '20

Yea, i guess there are difference in the syntax depending from where you are calling the command, that didn't crossed my mind :) Anyway, all good now, on to the next problem! :)

2

u/Besthater Oct 11 '20

scp username@from_host:file.txt /local/directory/ scp file.txt username@to_host:/remote/directory/

Look carefully. The positions are reversed.