I am often connecting to a remote server via ssh, and having to transfer some files between this remote host and my local pc. I do not have the admin rights on that server, and I am not the only one using it. The full paths for the host files may vary significantly from file to file and are usually quite long. However, I usually transfer the files to the same local folder at first. I have a passwordless ssh connection setup from my local device to the remote host. My current "workflow" for this little operation uses scp and feels very inefficient:
- I am usually already ssh'ed in the location of the relevant file on the remote host: I use
readlink -f
to get the full path of the file - I copy the path (leaving the keyboard to click)
- I switch to another terminal on my local computer and start typing
scp hostname:
- I paste the filepath (another click)
- I finish the
scp
command with the local directory name and execute
When I have to do that multiple times for many files that are not necessarily easy to include all together in one single command, it really doesn't feel efficient. Too many steps, too much repetitive typing and clicking around.
Ideally, I would like a magic command scp2local filename
that I can use from the remote host to directly do all of those steps in one and send it to a predefined localfolder. But I'm not sure how to set it up. Anything involving a full ssh passwordless connection setup from the remote to my local PC feels like a really bad idea since everyone else using the server could connect to my personal device. (But maybe there is a way to do that by exploiting the fact that I am just "sending back" files to the device I am specifically connecting from?)
In short: What is the most efficient way (in terms of human effort) to regularly transfer a few files from a remote host to a specific folder of the local computer I am connecting from ?
NB: I am using WSL on my local device, which might be relevant to the whole "clicking and copying" thing
You can use
sftp
, the classical file transfter protocol in one terminal window and stay logged in (if there is a logout after some minutes of inactivity, you can do some simple task likels
to keep the connection open).You can search for files via
sftp
, but maybe you must perform operations that are only available viassh
, so you can have two terminal windows open. If you already know the file names and paths, maybe via wildcards, you can also usersync
to fetch those files more or less automatically.