Function: tramp-scp-direct-remote-copying

tramp-scp-direct-remote-copying is a byte-compiled function defined in tramp-sh.el.gz.

Signature

(tramp-scp-direct-remote-copying VEC1 VEC2)

Documentation

Return the direct remote copying argument of the local scp.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-scp-direct-remote-copying (vec1 vec2)
  "Return the direct remote copying argument of the local scp."
  (cond
   ((or (not tramp-use-scp-direct-remote-copying) (null vec1) (null vec2)
	(not (tramp-get-process vec1))
	(not (equal (tramp-file-name-port vec1) (tramp-file-name-port vec2)))
	(null (assoc "%z" (tramp-get-method-parameter vec1 'tramp-copy-args)))
	(null (assoc "%z" (tramp-get-method-parameter vec2 'tramp-copy-args))))
    "")

   ((let ((case-fold-search t))
      (and
       ;; Check, whether "scp" supports "-R" option.
       (with-tramp-connection-property nil "scp-R"
	 (when (executable-find "scp")
	   (with-temp-buffer
	     (tramp-call-process vec1 "scp" nil t nil "-R")
	     (goto-char (point-min))
	     (not (search-forward-regexp
		   (rx (| "illegal" "unknown") " option -- R") nil 'noerror)))))

       ;; Check, that RemoteCommand is not used.
       (with-tramp-connection-property
	   (tramp-get-process vec1) "ssh-remote-command"
	 (let ((command `("ssh" "-G" ,(tramp-file-name-host vec1))))
	   (with-temp-buffer
	     (tramp-call-process
	      vec1 tramp-encoding-shell nil t nil
	      tramp-encoding-command-switch
	      (mapconcat #'identity command " "))
	     (goto-char (point-min))
	     (not (search-forward "remotecommand" nil 'noerror)))))

       ;; Check hostkeys.
       (with-tramp-connection-property
	   (tramp-get-process vec1)
	   (concat "direct-remote-copying-"
		   (tramp-make-tramp-file-name vec2 'noloc))
	 (let ((command
		(append
		 `("ssh" "-G" ,(tramp-file-name-host vec2) "|"
		   "grep" "-i" "^hostname" "|" "cut" "-d\" \"" "-f2" "|"
		   "ssh-keyscan" "-f" "-")
		 (when (tramp-file-name-port vec2)
		   `("-p" ,(tramp-file-name-port vec2)))))
	       found string)
	   (with-temp-buffer
	     ;; Check hostkey of VEC2, seen from VEC1.
	     (tramp-send-command vec1 (mapconcat #'identity command " "))
	     ;; Check hostkey of VEC2, seen locally.
	     (tramp-call-process
	      vec1 tramp-encoding-shell nil t nil tramp-encoding-command-switch
	      (mapconcat #'identity command " "))
	     (goto-char (point-min))
	     (while (and (not found) (not (eobp)))
	       (setq string
		     (buffer-substring
		      (line-beginning-position) (line-end-position))
		     string
		     (and
		      (string-match
		       (rx bol (+ (not (any blank "#"))) blank
			   (+ (not blank)) blank
			   (group (+ (not blank))) eol)
		       string)
		      (match-string 1 string))
		     found
		     (and string
			  (with-current-buffer (tramp-get-buffer vec1)
			    (goto-char (point-min))
			    (search-forward string nil 'noerror))))
	       (forward-line))
	     found)))))
    "-R")

   (t "-3")))