scp remote-to-remote implementation

Luis M lemsx1 at
Wed May 25 02:30:08 EST 2005

(Please when replying include my email since i'm not subscribe to this list)

Hello all,

I always wanted to be able to copy from one remote location to another
from a master server/workstation using something like:
 scp [-r] server1:/path/to/dir server2:/path/to/dir2
And have scp "know" that i mean to copy from server1 to localhost and
from localhost to server2 or something of that sort. For as long as it
is transparent to the end user.
I know that I could simply write a wrapper for scp and get the job
done quickly, however, I wanted to get down and dirty and make the
whole thing part of scp itself. Before i do, however, i wanted to make
sure that this has not been attempted before (or no one is already
working on this).
I also know that there is a better way of having this done (having a
pipe created locally that automatically pipes things through from
server1->localhost->server2 or something). But i just want something
quick and dirty that gets the job done.
The limitations i see so far are:
1. the server from which stuff is copying from must be the first one
in the argument list
2. there might be no way to check if there is space available to copy
the files from server1 to localhost and then to server2, so the user
must know this before hand. for now, the whole thing should fail as
usual when there is not enough disk space on any of the computers

And i know other things might pop up as I go through the code...

Can anybody give me pointers, perhaps to people who have implemented
this before. I did a quick google check and couldn't find anything. I
also looked in the mailing list archives (perhaps not hard enough
since the word: remote to remote is very ambiguous).

Here is an excerpt of my layout (pseudo code) in scp.c:

        if ( (targ = colon(argv[argc - 1])) && colon(argv[argc - 2]) )
                /* both Dest are remote, copy locally from first host
                 * then push from local to second host 
                /* FIXME
                 * get 1stRemoteHostName
                 * get 2ndRemoteHostName
                 * create _tmp_local = mktemp($ENV{TMP}/1stRemoteHostName.$$)
                /* FIXME modify argv to have _tmp_local 
                 * as destination
                tolocal(argc, argv);	/* TODO make dest local host from
server1 (argc-2 ?) */
                verifydir( _tmp_local );
                /* FIXME modify argv to have _tmp_local as the copying
from source
                 * and the 2ndRemoteHostName as the destination
                toremote(targ, argc, argv); /* TODO make dest remote server2 */
        } else if ((targ = colon(argv[argc - 1])))	/* Dest is remote host. */
		toremote(targ, argc, argv);
	else {
		tolocal(argc, argv);	/* Dest is local host. */
		if (targetshouldbedirectory)
			verifydir(argv[argc - 1]);

Luis M
System Administrator 

"We think basically you watch television to turn your brain off, and
you work on your computer when you want to turn your brain on" --
Steve Jobs in an interview for MacWorld Magazine 2004-Feb

No .doc:

More information about the openssh-unix-dev mailing list