Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have two terminal windows with bash. One is local on the client computer, another one has an SSH-session on the server. On the server, I am in a directory and seeing a file I would like to copy to my client using scp from the client.

On the server I see:

user@server:/path$ ls filename
filename

I can now type scp in the client shell, select and copy the user@server:/path from the server shell and paste to the client shell, then type slash and copy and paste the filename and append a dot to get:

user@client:~$ scp user@server:/path/filename .

to scp a file from the server to the client.

Now I am searching for a command on the server, that would work like this:

user@server:/path$ special_ls filename
user@server:/path/filename

which would give me the complete scp-ready string to copy&paste to the client shell.

Something in the form

echo $USER@$HOSTNAME:${pwd}/$filename

working with relative/absolute paths.

Is there any such command/switch combination or do I have to hack it myself?

Thank you very much.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

A quick snippet to print such output for pasting:

#!/bin/sh
SCPUSER="myuser"
SERVER="myserver"
while [ $# -ne 0 ]; do
    printf '%s@%s:%s\n' "${SCPUSER}" "${SERVER}" "$(readlink -f "${1}")"
    shift
done

The while; shift construction enables you to give multiple arguments which will be printed, separated by newlines.

This is straightforward; the "trick" above that you are probably looking for is probably just readlink.

You could also e.g. set up either ssh-agent or passwordless login via keys (if it is a local server and security is not too strict for this) to wrap scp server side to avoid the pasting step and directly scp files from the server.

share|improve this answer
    
Thank you, readlink is a very good hint, although the rest is hacking. If nobody comes with some already-built-in solution (without need of copying this script to any server), I will accept this answer. –  eumiro Jun 11 '12 at 8:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.