[PATCH] Re: scp remote path specification
Jan IVEN
Jan.Iven at cern.ch
Wed Dec 20 00:57:12 EST 2000
>>>>> "MF" == Markus Friedl <Markus.Friedl at informatik.uni-erlangen.de> writes:
MF> On Mon, Dec 18, 2000 at 06:04:03PM -0600, Frank Tobin wrote:
>> Markus Friedl, at 16:41 +0100 on Mon, 18 Dec 2000, wrote:
>>
>> you cannot assume that the path for the remote scp is the
>> same as for the local scp. it's better to add an option
>> to scp, e.g.:
>> $ scp -X /remote/path/to/scp /etc/passwd otherhost:/etc
>>
>> This is not a good solution if you ever expect there to be multiple remote
>> hosts in scp's arguments (e.g., scp file at remote1 file2 at remote2). You need
>> to tie the path to each remote file-location specification.
MF> more than 99% of the uses involve only a single remote host.
MF> if you have more specific uses is much better to use ssh+tar
MF> instead of scp.
MF> many people have already problems with
MF> scp hosta:/file1 hostb:/file2
MF> expanding to
MF> ssh hosta 'scp /file1 hostb:/file2'
Ok, here is a patch for a new option -X to scp (includes my first
"find local ssh in scp path" patch). Works for me. If the remote
command does not exist or does not understand the options, scp will
report an error after a short timeout.
Best regards
Jan
--- openssh-SNAP-20001213.orig/scp.0 Tue Dec 12 18:30:23 2000
+++ openssh/scp.0 Tue Dec 19 12:04:04 2000
@@ -54,7 +54,14 @@
-S program
Name of program to use for the encrypted connection. The program
- must understand ssh(1) options.
+ must understand ssh(1) options. The default is "/usr/bin/ssh" (set
+ at compilation time). If you run /path/to/scp instead of scp,
+ the default will be "/path/to/ssh".
+
+ -X program
+ Name of program invoke on the remote host. The program must
+ understand scp(1) options. The same program will be used on all
+ remote hosts.
-o option
The given option is directly passed to ssh(1).
--- openssh-SNAP-20001213.orig/scp.1 Mon Nov 6 02:39:34 2000
+++ openssh/scp.1 Tue Dec 19 12:03:04 2000
@@ -106,7 +106,16 @@
to use for the encrypted connection.
The program must understand
.Xr ssh 1
-options.
+options. The default is "/usr/bin/ssh" (set at compilation time). If you run
+/path/to/scp instead of scp, the
+default will be "/path/to/ssh".
+.It Fl X Ar program
+Name of
+.Ar program
+to invoke on the remote host.
+The program must understand
+.Xr scp 1
+options. The same program will be used on all remote hosts.
.It Fl o Ar option
The given option is directly passed to
.Xr ssh 1 .
--- openssh-SNAP-20001213.orig/scp.c Fri Nov 17 04:47:20 2000
+++ openssh/scp.c Tue Dec 19 11:50:55 2000
@@ -135,6 +135,9 @@
/* This is the program to execute for the secured connection. ("ssh" or -S) */
char *ssh_program = SSH_PROGRAM;
+/* This is the remote program that does the other side of the transfer ("scp" or -X) */
+char *scp_program = "scp";
+
/* This is the list of arguments that scp passes to ssh */
struct {
char **list;
@@ -251,7 +254,7 @@
char *argv[];
{
int ch, fflag, tflag;
- char *targ;
+ char *targ, *pathsep;
extern char *optarg;
extern int optind;
@@ -262,8 +265,21 @@
addargs("-x");
addargs("-oFallBackToRsh no");
+ /* check explicit path for ssh binary, default is SSH_PROGRAM */
+ if ((argc > 0) &&
+ (argv[0] != NULL)) {
+ pathsep = strrchr(argv[0], '/');
+ if (pathsep != NULL) {
+ pathsep++;
+ *pathsep = 0;
+ ssh_program = xmalloc(strlen(argv[0]) + 4); /* "../path" + "ssh\0" */
+ strcpy(ssh_program, argv[0]);
+ strcat(ssh_program, "ssh");
+ }
+ }
+
fflag = tflag = 0;
- while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != EOF)
+ while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:X:o:")) != EOF)
switch (ch) {
/* User-visible flags. */
case '4':
@@ -291,6 +307,9 @@
case 'S':
ssh_program = xstrdup(optarg);
break;
+ case 'X':
+ scp_program = xstrdup(optarg);
+ break;
case 'v':
verbose_mode = 1;
break;
@@ -344,7 +363,7 @@
remin = remout = -1;
/* Command to be executed on remote system using "ssh". */
- (void) sprintf(cmd, "scp%s%s%s%s", verbose_mode ? " -v" : "",
+ (void) sprintf(cmd, "%s%s%s%s%s", scp_program, verbose_mode ? " -v" : "",
iamrecursive ? " -r" : "", pflag ? " -p" : "",
targetshouldbedirectory ? " -d" : "");
@@ -969,7 +988,7 @@
usage()
{
(void) fprintf(stderr, "usage: scp "
- "[-pqrvC46] [-S ssh] [-P port] [-c cipher] [-i identity] f1 f2; or:\n"
+ "[-pqrvC46] [-S ssh] [-X /remote/scp] [-P port] [-c cipher] [-i identity] f1 f2; or:\n"
" scp [options] f1 ... fn directory\n");
exit(1);
}
More information about the openssh-unix-dev
mailing list