"-v" handling in scp (was Re: add scp path to _PATH_STDPATH)

Ishikawa ishikawa at yk.rim.or.jp
Mon Mar 5 06:01:25 EST 2001


Hi, while trying to figure out what scp does locally and remotely,
I found that the "-v" option to scp doesn't do what
it is supposed to do. (Or rather it doesn't do
what it can possibly do more.)

Currently, if I give "-v", only the remote invocation of
scp is given a single "-v".
Whereas, the local "ssh" invocation is not given "-v" and so
if my intention is to debug or analyze the ssh connection problem, actually
this "-v" is not quite useful.
(Currently all it does is print the invoked command line.)

Also, giving "-v" more than once doesn't change the
number of "-v"'s passed scp, either.
If we wanted to debug (or analyze) the connection in detail, being able to
give
"-v" multiple times (to the underlying ssh) is also useful.

So I modified scp.c so that

 - "-v" is passed to the remote invocation of "scp"
   multiple times up to three times if the user specifies
   "-v" multiple times on the command line.

 - "-v" is now passed to the local invocation of "ssh" as well.
   In this case, "-v" is given as many times as the user specified.

With this change,
the low-level ssh is invoked with "-v" automatically if we specify
"-v" to scp, and thus the tracking of connection problems might be
easier.

Someone might this useful.

Happy Hacking,

Chiaki Ishikawa

Eg. Using "-v" three times with the modification.

    ishikawa at duron$ !./scp
    ./scp  -v -v -v /tmp/t.bug ishikawa at host.example.com:/tmp/t.bug
    Executing: program /usr/local/bin/ssh host host.example.com, user
ishikawa, command scp -v -v -v -t /tmp/t.bug
    OpenSSH_2.5.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090581f
    debug: Reading configuration data /usr/local/etc/ssh_config
    debug: Applying options for *
    debug: ssh_connect: getuid 1001 geteuid 0 anon 0
    debug: Connecting to host.example.com [123.123.123.123] port 22.
    debug: Seeding random number generator
    debug: Allocated local port 700.
    debug: Connection established.
    debug: identity file /home/ishikawa/.ssh/identity type 0
    debug: identity file /home/ishikawa/.ssh/id_dsa type 3
    debug: Remote protocol version 1.5, remote software version 1.2.22
    debug: match: 1.2.22 pat ^1\.2\.2[012]
    (* Ouch, rather old ssh. *)
    debug: Local version string SSH-1.5-OpenSSH_2.5.1p2
    debug: Waiting for server public key.
    ...
    ...
    ...
    debug: Sent encrypted session key.
    debug: Installing crc compensation attack detector.
    debug: Received encrypted confirmation.
    debug: Remote: Server does not permit empty password login.
    debug: Trying RSA authentication with key 'ishikawa at standard'
    debug: Server refused our key.
    debug: Doing password authentication.
    ishikawa at host.example.com: ****************

    debug: Sending command: scp -v -v -v -t /tmp/t.bug
    debug: Entering interactive session.
    Sending file modes: C0644 226 t.bug
    ...
    ...
    ...
    ishikawa at duron$ debug: Transferred: stdin 243, stdout 3, stderr 0 bytes in
0.9 seconds
    debug: Bytes per second: stdin 266.9, stdout 3.3, stderr 0.0
    debug: Exit status 0


ishikawa at duron$ rcsdiff -c scp.c
===================================================================
RCS file: RCS/scp.c,v
retrieving revision 1.1
diff -c -r1.1 scp.c
*** scp.c       2001/03/04 18:35:17     1.1
--- scp.c       2001/03/04 18:46:21
***************
*** 277,283 ****
                        ssh_program = xstrdup(optarg);
                        break;
                case 'v':
!                       verbose_mode = 1;
                        break;
                case 'q':
                        showprogress = 0;
--- 277,284 ----
                        ssh_program = xstrdup(optarg);
                        break;
                case 'v':
!                       verbose_mode ++; /* for remote  */
!                       addargs("-v"); /* for local ssh */
                        break;
                case 'q':
                        showprogress = 0;
***************
*** 330,336 ****
        remin = remout = -1;
        /* Command to be executed on remote system using "ssh". */
        (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",
!           verbose_mode ? " -v" : "",
            iamrecursive ? " -r" : "", pflag ? " -p" : "",
            targetshouldbedirectory ? " -d" : "");

--- 331,341 ----
        remin = remout = -1;
        /* Command to be executed on remote system using "ssh". */
        (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",
!                       /** try to handle up to three '-v's. */
!                       verbose_mode <=0  ? ""
!                       : ( verbose_mode == 1 ? " -v"
!                           : ( verbose_mode == 2 ? " -v -v"
!                               : " -v -v -v" )),
            iamrecursive ? " -r" : "", pflag ? " -p" : "",
            targetshouldbedirectory ? " -d" : "");

***************
*** 404,410 ****
                                snprintf(bp, len,
                                    "%s%s -x -o'FallBackToRsh no' -n "
                                    "-l %s %s %s %s '%s%s%s:%s'",
!                                   ssh_program, verbose_mode ? " -v" : "",
                                    suser, host, cmd, src,
                                    tuser ? tuser : "", tuser ? "@" : "",
                                    thost, targ);
--- 409,421 ----
                                snprintf(bp, len,
                                    "%s%s -x -o'FallBackToRsh no' -n "
                                    "-l %s %s %s %s '%s%s%s:%s'",
!                                   ssh_program,
!                                        /** try to handle up to three '-v's.
*/
!                                        verbose_mode <=0  ? ""
!                                        : ( verbose_mode == 1 ? " -v"
!                                            : ( verbose_mode == 2 ? " -v -v"
!                                                : " -v -v -v" )),
!
                                    suser, host, cmd, src,
                                    tuser ? tuser : "", tuser ? "@" : "",
                                    thost, targ);
***************
*** 413,419 ****
                                snprintf(bp, len,
                                    "exec %s%s -x -o'FallBackToRsh no' -n %s "

                                    "%s %s '%s%s%s:%s'",
!                                   ssh_program, verbose_mode ? " -v" : "",
                                    host, cmd, src,
                                    tuser ? tuser : "", tuser ? "@" : "",
                                    thost, targ);
--- 424,435 ----
                                snprintf(bp, len,
                                    "exec %s%s -x -o'FallBackToRsh no' -n %s "

                                    "%s %s '%s%s%s:%s'",
!                                   ssh_program,
!                                /** try to handle up to three '-v's. */
!                                        verbose_mode <=0  ? ""
!                                        : ( verbose_mode == 1 ? " -v"
!                                            : ( verbose_mode == 2 ? " -v -v"
!                                                : " -v -v -v" )),
                                    host, cmd, src,
                                    tuser ? tuser : "", tuser ? "@" : "",
                                    thost, targ);
ishikawa at duron$







More information about the openssh-unix-dev mailing list