I pretty often need some file from some server when I'm on my laptop. But if I don't know where that file is, I have to ssh
into the server, look around, exit
, and then scp server:file .
. If I'm working with my desktop and my server, both of which have static IPs, I can just SCP the file in reverse (scp desktop:~ file
), but I can't do that for my laptop. Is there any nice way to SCP a file backwards over an SSH connection? So that the computer I connect to with SSH sends a file backwards to the client?
Reverse SCP over SSH connection
scpssh
Best Answer
This would be a lot easier with SFTP, which is an extension to SSH that supports more complex file operations than SCP. Virtually all modern Unix and Linux distributions support it. To use it, just run this command to connect to the server:
Then you can use the
ls
andcd
commands to browse around and find the file you're looking for. Once you've found it, use theget
command to download it. For instance, to downloadfile.txt
in your current working directory on the server to your current working directory on your local machine, just run:To download
/home/pavpanchekha/textfiles/file.txt
on the server to~/textfiles/
on your local machine, instead run:Conversely, you can also upload files in this manner. To upload
file.txt
from your local current working directory to the current working directory of the server, type:You can also use full paths for each like you can with
get
:For a full list of available SFTP commands, just run
help
at thesftp>
prompt.