tramp.el 297 KB
Newer Older
1
;;; tramp.el --- Transparent Remote Access, Multiple Protocol
Kai Großjohann's avatar
Kai Großjohann committed
2

3
;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4
;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Kai Großjohann's avatar
Kai Großjohann committed
5

6 7
;; (copyright statements below in code to be updated with the above notice)

Stefan Monnier's avatar
Stefan Monnier committed
8
;; Author: Kai Großjohann <kai.grossjohann@gmx.net>
Michael Albinus's avatar
Michael Albinus committed
9
;;         Michael Albinus <michael.albinus@gmx.de>
Kai Großjohann's avatar
Kai Großjohann committed
10 11 12 13
;; Keywords: comm, processes

;; This file is part of GNU Emacs.

14
;; GNU Emacs is free software: you can redistribute it and/or modify
Kai Großjohann's avatar
Kai Großjohann committed
15
;; it under the terms of the GNU General Public License as published by
16 17
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Kai Großjohann's avatar
Kai Großjohann committed
18 19 20 21 22 23 24

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
25
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Kai Großjohann's avatar
Kai Großjohann committed
26 27 28 29 30 31 32 33

;;; Commentary:

;; This package provides remote file editing, similar to ange-ftp.
;; The difference is that ange-ftp uses FTP to transfer files between
;; the local and the remote host, whereas tramp.el uses a combination
;; of rsh and rcp or other work-alike programs, such as ssh/scp.
;;
34
;; For more detailed instructions, please see the info file.
Kai Großjohann's avatar
Kai Großjohann committed
35 36 37
;;
;; Notes:
;; -----
38
;;
39 40 41
;; This package only works for Emacs 21.1 and higher, and for XEmacs 21.4
;; and higher.  For XEmacs 21, you need the package `fsf-compat' for
;; the `with-timeout' macro.)
Kai Großjohann's avatar
Kai Großjohann committed
42 43 44
;;
;; Also see the todo list at the bottom of this file.
;;
45
;; The current version of Tramp can be retrieved from the following URL:
Michael Albinus's avatar
Michael Albinus committed
46
;;            http://ftp.gnu.org/gnu/tramp/
Kai Großjohann's avatar
Kai Großjohann committed
47 48
;;
;; There's a mailing list for this, as well.  Its name is:
Michael Albinus's avatar
Michael Albinus committed
49 50 51
;;            tramp-devel@gnu.org
;; You can use the Web to subscribe, under the following URL:
;;            http://lists.gnu.org/mailman/listinfo/tramp-devel
Kai Großjohann's avatar
Kai Großjohann committed
52 53 54
;;
;; For the adventurous, the current development sources are available
;; via CVS.  You can find instructions about this at the following URL:
55
;;            http://savannah.gnu.org/projects/tramp/
Kai Großjohann's avatar
Kai Großjohann committed
56 57 58 59 60 61
;; Click on "CVS" in the navigation bar near the top.
;;
;; Don't forget to put on your asbestos longjohns, first!

;;; Code:

62 63 64 65 66 67 68
;; Since Emacs 23.1, loading messages have been disabled during
;; autoload.  However, loading Tramp takes a while, and it could
;; happen while typing a filename in the minibuffer.  Therefore, Tramp
;; shall inform about.
(when (and load-in-progress (null (current-message)))
  (message "Loading tramp..."))

69 70
;; The Tramp version number and bug report address, as prepared by configure.
(require 'trampver)
Michael Albinus's avatar
Michael Albinus committed
71 72 73 74 75
(add-hook 'tramp-unload-hook
	  '(lambda ()
	     (when (featurep 'trampver)
	       (unload-feature 'trampver 'force))))

76
(require 'tramp-compat)
77 78 79 80
(add-hook 'tramp-unload-hook
	  '(lambda ()
	     (when (featurep 'tramp-compat)
	       (unload-feature 'tramp-compat 'force))))
Kai Großjohann's avatar
Kai Großjohann committed
81

82
(require 'format-spec)                  ; from Gnus 5.8, also in tar ball
83 84 85 86
;; As long as password.el is not part of (X)Emacs, it shouldn't
;; be mandatory
(if (featurep 'xemacs)
    (load "password" 'noerror)
87 88
  (or (require 'password-cache nil 'noerror)
      (require 'password nil 'noerror))) ; from No Gnus, also in tar ball
89

Kai Großjohann's avatar
Kai Großjohann committed
90 91 92
(require 'shell)
(require 'advice)

93 94 95 96
(eval-and-compile
  (if (featurep 'xemacs)
      (load "auth-source" 'noerror)
    (require 'auth-source nil 'noerror)))
97

98 99 100 101 102 103 104 105 106 107 108 109 110 111
;; Requiring 'tramp-cache results in an endless loop.
(autoload 'tramp-get-file-property "tramp-cache")
(autoload 'tramp-set-file-property "tramp-cache")
(autoload 'tramp-flush-file-property "tramp-cache")
(autoload 'tramp-flush-directory-property "tramp-cache")
(autoload 'tramp-get-connection-property "tramp-cache")
(autoload 'tramp-set-connection-property "tramp-cache")
(autoload 'tramp-flush-connection-property "tramp-cache")
(autoload 'tramp-parse-connection-properties "tramp-cache")
(add-hook 'tramp-unload-hook
	  '(lambda ()
	     (when (featurep 'tramp-cache)
	       (unload-feature 'tramp-cache 'force))))

112 113
(autoload 'tramp-uuencode-region "tramp-uu"
  "Implementation of `uuencode' in Lisp.")
Michael Albinus's avatar
Michael Albinus committed
114 115 116 117
(add-hook 'tramp-unload-hook
	  '(lambda ()
	     (when (featurep 'tramp-uu)
	       (unload-feature 'tramp-uu 'force))))
118

119
(autoload 'uudecode-decode-region "uudecode")
120

121 122
;; The following Tramp packages must be loaded after tramp.el, because
;; they require it as well.
123
(eval-after-load "tramp"
124 125 126 127
  '(dolist
       (feature
	(list

128
	 ;; Tramp interactive commands.
129 130 131 132 133 134 135 136 137 138 139 140 141
	 'tramp-cmds

	 ;; Load foreign FTP method.
	 (if (featurep 'xemacs) 'tramp-efs 'tramp-ftp)

	 ;; tramp-smb uses "smbclient" from Samba.  Not available
	 ;; under Cygwin and Windows, because they don't offer
	 ;; "smbclient".  And even not necessary there, because Emacs
	 ;; supports UNC file names like "//host/share/localname".
	 (unless (memq system-type '(cygwin windows-nt)) 'tramp-smb)

	 ;; Load foreign FISH method.
	 'tramp-fish
142

143 144 145 146
	 ;; Load gateways.  It needs `make-network-process' from Emacs 22.
	 (when (functionp 'make-network-process) 'tramp-gw)))

     (when feature
147
       (require feature)
Michael Albinus's avatar
Michael Albinus committed
148
       (add-hook 'tramp-unload-hook
149
		 `(lambda ()
150 151
		    (when (featurep (quote ,feature))
		      (unload-feature (quote ,feature) 'force)))))))
Kai Großjohann's avatar
Kai Großjohann committed
152 153 154 155 156

;;; User Customizable Internal Variables:

(defgroup tramp nil
  "Edit remote files with a combination of rsh and rcp or similar programs."
157
  :group 'files
158
  :version "22.1")
Kai Großjohann's avatar
Kai Großjohann committed
159

160 161 162 163 164 165 166 167
;; Maybe we need once a real Tramp mode, with key bindings etc.
;;;###autoload
(defcustom tramp-mode t
  "*Whether Tramp is enabled.
If it is set to nil, all remote file names are used literally."
  :group 'tramp
  :type 'boolean)

168
(defcustom tramp-verbose 3
169
  "*Verbosity level for Tramp.
170 171 172 173 174 175 176 177 178 179 180 181
Any level x includes messages for all levels 1 .. x-1.  The levels are

 0  silent (no tramp messages at all)
 1  errors
 2  warnings
 3  connection to remote hosts (default level)
 4  activities
 5  internal
 6  sent and received strings
 7  file caching
 8  connection properties
10  traces (huge)."
Kai Großjohann's avatar
Kai Großjohann committed
182 183 184
  :group 'tramp
  :type 'integer)

185 186 187 188 189 190 191 192
;; Emacs case
(eval-and-compile
  (when (boundp 'backup-directory-alist)
    (defcustom tramp-backup-directory-alist nil
      "Alist of filename patterns and backup directory names.
Each element looks like (REGEXP . DIRECTORY), with the same meaning like
in `backup-directory-alist'.  If a Tramp file is backed up, and DIRECTORY
is a local file name, the backup directory is prepended with Tramp file
193
name prefix \(method, user, host\) of file.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

\(setq tramp-backup-directory-alist backup-directory-alist\)

gives the same backup policy for Tramp files on their hosts like the
policy for local files."
      :group 'tramp
      :type '(repeat (cons (regexp :tag "Regexp matching filename")
			   (directory :tag "Backup directory name"))))))

;; XEmacs case.  We cannot check for `bkup-backup-directory-info', because
;; the package "backup-dir" might not be loaded yet.
(eval-and-compile
  (when (featurep 'xemacs)
    (defcustom tramp-bkup-backup-directory-info nil
      "*Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))
It has the same meaning like `bkup-backup-directory-info' from package
`backup-dir'.  If a Tramp file is backed up, and BACKUP-DIR is a local
file name, the backup directory is prepended with Tramp file name prefix
212
\(method, user, host\) of file.
213 214 215 216 217

\(setq tramp-bkup-backup-directory-info bkup-backup-directory-info\)

gives the same backup policy for Tramp files on their hosts like the
policy for local files."
218
      :type '(repeat
219 220 221 222 223 224 225 226 227
	      (list (regexp :tag "File regexp")
		    (string :tag "Backup Dir")
		    (set :inline t
			 (const ok-create)
			 (const full-path)
			 (const prepend-name)
			 (const search-upward))))
      :group 'tramp)))

Kai Großjohann's avatar
Kai Großjohann committed
228 229 230 231
(defcustom tramp-auto-save-directory nil
  "*Put auto-save files in this directory, if set.
The idea is to use a local directory so that auto-saving is faster."
  :group 'tramp
232
  :type '(choice (const nil) string))
Kai Großjohann's avatar
Kai Großjohann committed
233

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
(defcustom tramp-encoding-shell
  (if (memq system-type '(windows-nt))
      (getenv "COMSPEC")
    "/bin/sh")
  "*Use this program for encoding and decoding commands on the local host.
This shell is used to execute the encoding and decoding command on the
local host, so if you want to use `~' in those commands, you should
choose a shell here which groks tilde expansion.  `/bin/sh' normally
does not understand tilde expansion.

For encoding and deocding, commands like the following are executed:

    /bin/sh -c COMMAND < INPUT > OUTPUT

This variable can be used to change the \"/bin/sh\" part.  See the
249
variable `tramp-encoding-command-switch' for the \"-c\" part.
Kai Großjohann's avatar
Kai Großjohann committed
250 251 252 253 254 255 256

Note that this variable is not used for remote commands.  There are
mechanisms in tramp.el which automatically determine the right shell to
use for the remote host."
  :group 'tramp
  :type '(file :must-match t))

257 258 259 260 261 262 263 264 265
(defcustom tramp-encoding-command-switch
  (if (string-match "cmd\\.exe" tramp-encoding-shell)
      "/c"
    "-c")
  "*Use this switch together with `tramp-encoding-shell' for local commands.
See the variable `tramp-encoding-shell' for more information."
  :group 'tramp
  :type 'string)

266 267
(defcustom tramp-copy-size-limit 10240
  "*The maximum file size where inline copying is preferred over an out-of-the-band copy."
268
  :group 'tramp
269
  :type 'integer)
Kai Großjohann's avatar
Kai Großjohann committed
270

271 272 273 274 275
(defcustom tramp-terminal-type "dumb"
  "*Value of TERM environment variable for logging in to remote host.
Because Tramp wants to parse the output of the remote shell, it is easily
confused by ANSI color escape sequences and suchlike.  Often, shell init
files conditionalize this setup based on the TERM environment variable."
Kai Großjohann's avatar
Kai Großjohann committed
276
  :group 'tramp
277
  :type 'string)
Kai Großjohann's avatar
Kai Großjohann committed
278

279 280 281 282 283 284 285 286 287
(defvar tramp-methods
  `(("rcp"   (tramp-login-program        "rsh")
             (tramp-login-args           (("%h") ("-l" "%u")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "rcp")
	     (tramp-copy-args            (("-p" "%k")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil))
    ("scp"   (tramp-login-program        "ssh")
288
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
289 290 291 292 293 294 295 296 297 298 299 300
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "scp")
	     (tramp-copy-args            (("-P" "%p") ("-p" "%k") ("-q")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("scp1"  (tramp-login-program        "ssh")
301
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
302 303 304 305 306 307 308 309 310 311 312 313 314
					  ("-1" "-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "scp")
	     (tramp-copy-args            (("-1") ("-P" "%p") ("-p" "%k")
					  ("-q")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("scp2"  (tramp-login-program        "ssh")
315
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
					  ("-2" "-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "scp")
	     (tramp-copy-args            (("-2") ("-P" "%p") ("-p" "%k")
					  ("-q")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("scp1_old"
             (tramp-login-program        "ssh1")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p")
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "scp1")
	     (tramp-copy-args            (("-p" "%k")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil))
    ("scp2_old"
             (tramp-login-program        "ssh2")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p")
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "scp2")
	     (tramp-copy-args            (("-p" "%k")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil))
    ("sftp"  (tramp-login-program        "ssh")
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p")
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "sftp")
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("rsync" (tramp-login-program        "ssh")
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p")
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "rsync")
	     (tramp-copy-args            (("-e" "ssh") ("-t" "%k")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil))
    ("remcp" (tramp-login-program        "remsh")
             (tramp-login-args           (("%h") ("-l" "%u")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "rcp")
	     (tramp-copy-args            (("-p" "%k")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil))
    ("rsh"   (tramp-login-program        "rsh")
             (tramp-login-args           (("%h") ("-l" "%u")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("ssh"   (tramp-login-program        "ssh")
377
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
378 379 380 381 382 383 384 385 386 387 388 389
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("ssh1"  (tramp-login-program        "ssh")
390
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
391 392 393 394 395 396 397 398 399 400 401 402
					  ("-1" "-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("ssh2"  (tramp-login-program        "ssh")
403
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
					  ("-2" "-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("ssh1_old"
             (tramp-login-program        "ssh1")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p")
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("ssh2_old"
             (tramp-login-program        "ssh2")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p")
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("remsh" (tramp-login-program        "remsh")
             (tramp-login-args           (("%h") ("-l" "%u")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("telnet"
             (tramp-login-program        "telnet")
	     (tramp-login-args           (("%h") ("%p")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil)
	     (tramp-default-port         23))
    ("su"    (tramp-login-program        "su")
             (tramp-login-args           (("-") ("%u")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("sudo"  (tramp-login-program        "sudo")
             (tramp-login-args           (("-u" "%u")
458
					  ("-s") ("-H") ("-p" "Password:")))
459 460 461 462 463 464
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("scpc"  (tramp-login-program        "ssh")
465
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
					  ("-o" "ControlPath=%t.%%r@%%h:%%p")
					  ("-o" "ControlMaster=yes")
					  ("-e" "none")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "scp")
	     (tramp-copy-args            (("-P" "%p") ("-p" "%k") ("-q")
					  ("-o" "ControlPath=%t.%%r@%%h:%%p")
					  ("-o" "ControlMaster=auto")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("scpx"  (tramp-login-program        "ssh")
482
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
483 484 485 486 487 488 489 490 491 492 493 494
					  ("-e" "none" "-t" "-t" "/bin/sh")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "scp")
	     (tramp-copy-args            (("-p" "%k")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("sshx"  (tramp-login-program        "ssh")
495
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
					  ("-e" "none" "-t" "-t" "/bin/sh")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil)
	     (tramp-gw-args              (("-o"
					   "GlobalKnownHostsFile=/dev/null")
					  ("-o" "UserKnownHostsFile=/dev/null")
					  ("-o" "StrictHostKeyChecking=no")))
	     (tramp-default-port         22))
    ("krlogin"
	     (tramp-login-program        "krlogin")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-x")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("plink" (tramp-login-program        "plink")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-P" "%p")
					  ("-ssh")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line "xy") ;see docstring for "xy"
	     (tramp-default-port         22))
    ("plink1"
	     (tramp-login-program        "plink")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-P" "%p")
					  ("-1" "-ssh")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line "xy") ;see docstring for "xy"
	     (tramp-default-port         22))
    ("plinkx"
             (tramp-login-program        "plink")
536 537 538
	     ;; ("%h") must be a single element, see
	     ;; `tramp-compute-multi-hops'.
	     (tramp-login-args           (("-load") ("%h") ("-t")
539 540 541
					  (,(format
					     "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=$ '"
					     tramp-terminal-type))
542 543 544 545 546 547 548 549 550 551 552
					  ("/bin/sh")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         nil)
	     (tramp-copy-args            nil)
	     (tramp-copy-keep-date       nil)
	     (tramp-password-end-of-line nil))
    ("pscp"  (tramp-login-program        "plink")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-P" "%p")
					  ("-ssh")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "pscp")
553
	     (tramp-copy-args            (("-P" "%p") ("-scp") ("-p" "%k")))
554 555 556 557 558 559 560 561
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line "xy") ;see docstring for "xy"
	     (tramp-default-port         22))
    ("psftp" (tramp-login-program        "plink")
	     (tramp-login-args           (("%h") ("-l" "%u") ("-P" "%p")
					  ("-ssh")))
	     (tramp-remote-sh            "/bin/sh")
	     (tramp-copy-program         "pscp")
562
	     (tramp-copy-args            (("-P" "%p") ("-sftp") ("-p" "%k")))
563 564 565 566 567 568 569 570 571
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line "xy")) ;see docstring for "xy"
    ("fcp"   (tramp-login-program        "fsh")
             (tramp-login-args           (("%h") ("-l" "%u") ("sh" "-i")))
	     (tramp-remote-sh            "/bin/sh -i")
	     (tramp-copy-program         "fcp")
	     (tramp-copy-args            (("-p" "%k")))
	     (tramp-copy-keep-date       t)
	     (tramp-password-end-of-line nil)))
Kai Großjohann's avatar
Kai Großjohann committed
572 573 574 575 576 577 578
  "*Alist of methods for remote files.
This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
Each NAME stands for a remote access method.  Each PARAM is a
pair of the form (KEY VALUE).  The following KEYs are defined:
  * `tramp-remote-sh'
    This specifies the Bourne shell to use on the remote host.  This
    MUST be a Bourne-like shell.  It is normally not necessary to set
579
    this to any value other than \"/bin/sh\": Tramp wants to use a shell
Kai Großjohann's avatar
Kai Großjohann committed
580 581 582
    which groks tilde expansion, but it can search for it.  Also note
    that \"/bin/sh\" exists on all Unixen, this might not be true for
    the value that you decide to use.  You Have Been Warned.
583 584
  * `tramp-login-program'
    This specifies the name of the program to use for logging in to the
585 586
    remote host.  This may be the name of rsh or a workalike program,
    or the name of telnet or a workalike, or the name of su or a workalike.
587
  * `tramp-login-args'
Kai Großjohann's avatar
Kai Großjohann committed
588
    This specifies the list of arguments to pass to the above
589
    mentioned program.  Please note that this is a list of list of arguments,
Kai Großjohann's avatar
Kai Großjohann committed
590
    that is, normally you don't want to put \"-a -b\" or \"-f foo\"
591 592 593 594 595 596 597 598 599 600
    here.  Instead, you want a list (\"-a\" \"-b\"), or (\"-f\" \"foo\").
    There are some patterns: \"%h\" in this list is replaced by the host
    name, \"%u\" is replaced by the user name, \"%p\" is replaced by the
    port number, and \"%%\" can be used to obtain a literal percent character.
    If a list containing \"%h\", \"%u\" or \"%p\" is unchanged during
    expansion (i.e. no host or no user specified), this list is not used as
    argument.  By this, arguments like (\"-l\" \"%u\") are optional.
    \"%t\" is replaced by the temporary file name produced with
    `tramp-make-tramp-temp-file'.  \"%k\" indicates the keep-date
    parameter of a program, if exists.
601 602 603 604 605
  * `tramp-copy-program'
    This specifies the name of the program to use for remotely copying
    the file; this might be the absolute filename of rcp or the name of
    a workalike program.
  * `tramp-copy-args'
Kai Großjohann's avatar
Kai Großjohann committed
606
    This specifies the list of parameters to pass to the above mentioned
607
    program, the hints for `tramp-login-args' also apply here.
608 609 610 611 612 613 614 615 616 617
  * `tramp-copy-keep-date'
    This specifies whether the copying program when the preserves the
    timestamp of the original file.
  * `tramp-default-port'
    The default port of a method is needed in case of gateway connections.
    Additionally, it is used as indication which method is prepared for
    passing gateways.
  * `tramp-gw-args'
    As the attribute name says, additional arguments are specified here
    when a method is applied via a gateway.
Kai Großjohann's avatar
Kai Großjohann committed
618 619 620 621 622 623 624 625 626
  * `tramp-password-end-of-line'
    This specifies the string to use for terminating the line after
    submitting the password.  If this method parameter is nil, then the
    value of the normal variable `tramp-default-password-end-of-line'
    is used.  This parameter is necessary because the \"plink\" program
    requires any two characters after sending the password.  These do
    not have to be newline or carriage return characters.  Other login
    programs are happy with just one character, the newline character.
    We use \"xy\" as the value for methods using \"plink\".
627 628 629 630 631 632

What does all this mean?  Well, you should specify `tramp-login-program'
for all methods; this program is used to log in to the remote site.  Then,
there are two ways to actually transfer the files between the local and the
remote side.  One way is using an additional rcp-like program.  If you want
to do this, set `tramp-copy-program' in the method.
Kai Großjohann's avatar
Kai Großjohann committed
633 634

Another possibility for file transfer is inline transfer, i.e. the
635
file is passed through the same buffer used by `tramp-login-program'.  In
Kai Großjohann's avatar
Kai Großjohann committed
636
this case, the file contents need to be protected since the
637
`tramp-login-program' might use escape codes or the connection might not
Kai Großjohann's avatar
Kai Großjohann committed
638
be eight-bit clean.  Therefore, file contents are encoded for transit.
639 640
See the variables `tramp-local-coding-commands' and
`tramp-remote-coding-commands' for details.
Kai Großjohann's avatar
Kai Großjohann committed
641

642
So, to summarize: if the method is an out-of-band method, then you
643
must specify `tramp-copy-program' and `tramp-copy-args'.  If it is an
644 645
inline method, then these two parameters should be nil.  Methods which
are fit for gateways must have `tramp-default-port' at least.
Kai Großjohann's avatar
Kai Großjohann committed
646 647 648

Notes:

649 650 651 652 653 654
When using `su' or `sudo' the phrase `open connection to a remote
host' sounds strange, but it is used nevertheless, for consistency.
No connection is opened to a remote host, but `su' or `sudo' is
started on the local host.  You should specify a remote host
`localhost' or the name of the local host.  Another host name is
useful only in combination with `tramp-default-proxies-alist'.")
Kai Großjohann's avatar
Kai Großjohann committed
655

656
(defcustom tramp-default-method
657 658 659 660 661 662 663 664 665
  ;; An external copy method seems to be preferred, because it is much
  ;; more performant for large files, and it hasn't too serious delays
  ;; for small files.  But it must be ensured that there aren't
  ;; permanent password queries.  Either a password agent like
  ;; "ssh-agent" or "Pageant" shall run, or the optional password.el
  ;; package shall be active for password caching.  "scpc" would be
  ;; another good choice because of the "ControlMaster" option, but
  ;; this is a more modern alternative in OpenSSH 4, which cannot be
  ;; taken as default.
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
  (cond
   ;; PuTTY is installed.
   ((executable-find "pscp")
    (if	(or (fboundp 'password-read)
	    ;; Pageant is running.
	    (and (fboundp 'w32-window-exists-p)
		 (funcall (symbol-function 'w32-window-exists-p)
			  "Pageant" "Pageant")))
	"pscp"
      "plink"))
   ;; There is an ssh installation.
   ((executable-find "scp")
    (if	(or (fboundp 'password-read)
	    ;; ssh-agent is running.
	    (getenv "SSH_AUTH_SOCK")
	    (getenv "SSH_AGENT_PID"))
	"scp"
      "ssh"))
   ;; Fallback.
   (t "ftp"))
Kai Großjohann's avatar
Kai Großjohann committed
686
  "*Default method to use for transferring files.
687
See `tramp-methods' for possibilities.
688
Also see `tramp-default-method-alist'."
689 690 691
  :group 'tramp
  :type 'string)

692
(defcustom tramp-default-method-alist
693
  '(("\\`localhost\\'" "\\`root\\'" "su"))
694
  "*Default method to use for specific host/user pairs.
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
This is an alist of items (HOST USER METHOD).  The first matching item
specifies the method to use for a file name which does not specify a
method.  HOST and USER are regular expressions or nil, which is
interpreted as a regular expression which always matches.  If no entry
matches, the variable `tramp-default-method' takes effect.

If the file name does not specify the user, lookup is done using the
empty string for the user name.

See `tramp-methods' for a list of possibilities for METHOD."
  :group 'tramp
  :type '(repeat (list (regexp :tag "Host regexp")
		       (regexp :tag "User regexp")
		       (string :tag "Method"))))

710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
(defcustom tramp-default-user
  nil
  "*Default user to use for transferring files.
It is nil by default; otherwise settings in configuration files like
\"~/.ssh/config\" would be overwritten.  Also see `tramp-default-user-alist'.

This variable is regarded as obsolete, and will be removed soon."
  :group 'tramp
  :type '(choice (const nil) string))

(defcustom tramp-default-user-alist
  `(("\\`su\\(do\\)?\\'" nil "root")
    ("\\`r\\(em\\)?\\(cp\\|sh\\)\\|telnet\\|plink1?\\'"
     nil ,(user-login-name)))
  "*Default user to use for specific method/host pairs.
This is an alist of items (METHOD HOST USER).  The first matching item
specifies the user to use for a file name which does not specify a
user.  METHOD and USER are regular expressions or nil, which is
interpreted as a regular expression which always matches.  If no entry
matches, the variable `tramp-default-user' takes effect.

If the file name does not specify the method, lookup is done using the
empty string for the method name."
  :group 'tramp
  :type '(repeat (list (regexp :tag "Method regexp")
		       (regexp :tag "Host regexp")
		       (string :tag "User"))))

(defcustom tramp-default-host
  (system-name)
  "*Default host to use for transferring files.
Useful for su and sudo methods mostly."
  :group 'tramp
  :type 'string)

(defcustom tramp-default-proxies-alist nil
  "*Route to be followed for specific host/user pairs.
This is an alist of items (HOST USER PROXY).  The first matching
item specifies the proxy to be passed for a file name located on
a remote target matching USER@HOST.  HOST and USER are regular
expressions or nil, which is interpreted as a regular expression
which always matches.  PROXY must be a Tramp filename without a
localname part.  Method and user name on PROXY are optional,
which is interpreted with the default values.  PROXY can contain
the patterns %h and %u, which are replaced by the strings
matching HOST or USER, respectively."
  :group 'tramp
  :type '(repeat (list (regexp :tag "Host regexp")
		       (regexp :tag "User regexp")
		       (string :tag "Proxy remote name"))))

761 762 763 764 765
(defconst tramp-local-host-regexp
  (concat
   "^" (regexp-opt (list "localhost" (system-name) "127\.0\.0\.1" "::1") t) "$")
  "*Host names which are regarded as local host.")

766
(defconst tramp-completion-function-alist-rsh
767 768
  '((tramp-parse-rhosts "/etc/hosts.equiv")
    (tramp-parse-rhosts "~/.rhosts"))
769
  "Default list of (FUNCTION FILE) pairs to be examined for rsh methods.")
770 771

(defconst tramp-completion-function-alist-ssh
772 773 774 775 776 777 778 779 780 781 782 783
  '((tramp-parse-rhosts      "/etc/hosts.equiv")
    (tramp-parse-rhosts      "/etc/shosts.equiv")
    (tramp-parse-shosts      "/etc/ssh_known_hosts")
    (tramp-parse-sconfig     "/etc/ssh_config")
    (tramp-parse-shostkeys   "/etc/ssh2/hostkeys")
    (tramp-parse-sknownhosts "/etc/ssh2/knownhosts")
    (tramp-parse-rhosts      "~/.rhosts")
    (tramp-parse-rhosts      "~/.shosts")
    (tramp-parse-shosts      "~/.ssh/known_hosts")
    (tramp-parse-sconfig     "~/.ssh/config")
    (tramp-parse-shostkeys   "~/.ssh2/hostkeys")
    (tramp-parse-sknownhosts "~/.ssh2/knownhosts"))
784
  "Default list of (FUNCTION FILE) pairs to be examined for ssh methods.")
785 786

(defconst tramp-completion-function-alist-telnet
787
  '((tramp-parse-hosts "/etc/hosts"))
788
  "Default list of (FUNCTION FILE) pairs to be examined for telnet methods.")
789 790

(defconst tramp-completion-function-alist-su
791
  '((tramp-parse-passwd "/etc/passwd"))
792
  "Default list of (FUNCTION FILE) pairs to be examined for su methods.")
Kai Großjohann's avatar
Kai Großjohann committed
793

794 795 796 797 798
(defconst tramp-completion-function-alist-putty
  '((tramp-parse-putty
     "HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions"))
  "Default list of (FUNCTION REGISTRY) pairs to be examined for putty methods.")

799
(defvar tramp-completion-function-alist nil
800 801 802 803 804 805
  "*Alist of methods for remote files.
This is a list of entries of the form (NAME PAIR1 PAIR2 ...).
Each NAME stands for a remote access method.  Each PAIR is of the form
\(FUNCTION FILE).  FUNCTION is responsible to extract user names and host
names from FILE for completion.  The following predefined FUNCTIONs exists:

806 807 808 809 810 811 812 813
 * `tramp-parse-rhosts'      for \"~/.rhosts\" like files,
 * `tramp-parse-shosts'      for \"~/.ssh/known_hosts\" like files,
 * `tramp-parse-sconfig'     for \"~/.ssh/config\" like files,
 * `tramp-parse-shostkeys'   for \"~/.ssh2/hostkeys/*\" like files,
 * `tramp-parse-sknownhosts' for \"~/.ssh2/knownhosts/*\" like files,
 * `tramp-parse-hosts'       for \"/etc/hosts\" like files,
 * `tramp-parse-passwd'      for \"/etc/passwd\" like files.
 * `tramp-parse-netrc'       for \"~/.netrc\" like files.
814
 * `tramp-parse-putty'       for PuTTY registry keys.
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856

FUNCTION can also be a customer defined function.  For more details see
the info pages.")

(eval-after-load "tramp"
  '(progn
     (tramp-set-completion-function
      "rcp" tramp-completion-function-alist-rsh)
     (tramp-set-completion-function
      "scp" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "scp1" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "scp2" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "scp1_old" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "scp2_old" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "rsync" tramp-completion-function-alist-rsh)
     (tramp-set-completion-function
      "remcp" tramp-completion-function-alist-rsh)
     (tramp-set-completion-function
      "rsh" tramp-completion-function-alist-rsh)
     (tramp-set-completion-function
      "ssh" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "ssh1" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "ssh2" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "ssh1_old" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "ssh2_old" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "remsh" tramp-completion-function-alist-rsh)
     (tramp-set-completion-function
      "telnet" tramp-completion-function-alist-telnet)
     (tramp-set-completion-function
      "su" tramp-completion-function-alist-su)
     (tramp-set-completion-function
      "sudo" tramp-completion-function-alist-su)
857
     (tramp-set-completion-function
858 859 860 861 862 863 864 865 866
      "scpx" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "sshx" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "krlogin" tramp-completion-function-alist-rsh)
     (tramp-set-completion-function
      "plink" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "plink1" tramp-completion-function-alist-ssh)
867 868
     (tramp-set-completion-function
      "plinkx" tramp-completion-function-alist-putty)
869 870 871 872
     (tramp-set-completion-function
      "pscp" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "fcp" tramp-completion-function-alist-ssh)))
873

874 875 876
(defconst tramp-echo-mark-marker "_echo"
  "String marker to surround echoed commands.")

877 878 879 880 881 882
(defconst tramp-echo-mark "_echo\b\b\b\b\b"
  "String mark to be transmitted around shell commands.
Used to separate their echo from the output they produce.  This
will only be used if we cannot disable remote echo via stty.
This string must have no effect on the remote shell except for
producing some echo which can later be detected by
883 884 885
`tramp-echoed-echo-mark-regexp'.  Using `tramp-echo-mark-marker',
followed by an equal number of backspaces to erase them will
usually suffice.")
886 887 888 889 890

(defconst tramp-echoed-echo-mark-regexp "_echo\\(\b\\( \b\\)?\\)\\{5\\}"
  "Regexp which matches `tramp-echo-mark' as it gets echoed by
the remote shell.")

Kai Großjohann's avatar
Kai Großjohann committed
891 892 893
(defcustom tramp-rsh-end-of-line "\n"
  "*String used for end of line in rsh connections.
I don't think this ever needs to be changed, so please tell me about it
894
if you need to change this.
Kai Großjohann's avatar
Kai Großjohann committed
895 896
Also see the method parameter `tramp-password-end-of-line' and the normal
variable `tramp-default-password-end-of-line'."
897 898 899
  :group 'tramp
  :type 'string)

Kai Großjohann's avatar
Kai Großjohann committed
900 901
(defcustom tramp-default-password-end-of-line
  tramp-rsh-end-of-line
902
  "*String used for end of line after sending a password.
Kai Großjohann's avatar
Kai Großjohann committed
903 904 905
This variable provides the default value for the method parameter
`tramp-password-end-of-line', see `tramp-methods' for more details.

906 907 908 909 910 911
It seems that people using plink under Windows need to send
\"\\r\\n\" (carriage-return, then newline) after a password, but just
\"\\n\" after all other lines.  This variable can be used for the
password, see `tramp-rsh-end-of-line' for the other cases.

The default value is to use the same value as `tramp-rsh-end-of-line'."
Kai Großjohann's avatar
Kai Großjohann committed
912 913 914
  :group 'tramp
  :type 'string)

915 916 917
;; "getconf PATH" yields:
;; HP-UX: /usr/bin:/usr/ccs/bin:/opt/ansic/bin:/opt/langtools/bin:/opt/fortran/bin
;; Solaris: /usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin
918
;; GNU/Linux (Debian, Suse): /bin:/usr/bin
919
;; FreeBSD: /usr/bin:/bin:/usr/sbin:/sbin: - beware trailing ":"!
Kai Großjohann's avatar
Kai Großjohann committed
920
(defcustom tramp-remote-path
921 922
  '(tramp-default-remote-path "/usr/sbin" "/usr/local/bin"
    "/local/bin" "/local/freeware/bin" "/local/gnu/bin"
Kai Großjohann's avatar
Kai Großjohann committed
923 924
    "/usr/freeware/bin" "/usr/pkg/bin" "/usr/contrib/bin")
  "*List of directories to search for executables on remote host.
925 926
For every remote host, this variable will be set buffer local,
keeping the list of existing directories on that host.
Kai Großjohann's avatar
Kai Großjohann committed
927 928

You can use `~' in this list, but when searching for a shell which groks
929 930 931 932 933 934 935 936 937 938 939 940
tilde expansion, all directory names starting with `~' will be ignored.

`Default Directories' represent the list of directories given by
the command \"getconf PATH\".  It is recommended to use this
entry on top of this list, because these are the default
directories for POSIX compatible commands."
  :group 'tramp
  :type '(repeat (choice
		  (const :tag "Default Directories" tramp-default-remote-path)
		  (string :tag "Directory"))))

(defcustom tramp-remote-process-environment
941
  `("HISTFILE=$HOME/.tramp_history" "HISTSIZE=1" "LC_ALL=C"
942
    ,(concat "TERM=" tramp-terminal-type)
943 944
    "EMACS=t" ;; Deprecated.
    ,(format "INSIDE_EMACS=%s,tramp:%s" emacs-version tramp-version)
945 946 947 948 949 950 951 952 953 954 955
    "CDPATH=" "HISTORY=" "MAIL=" "MAILCHECK=" "MAILPATH="
    "autocorrect=" "correct=")

  "*List of environment variables to be set on the remote host.

Each element should be a string of the form ENVVARNAME=VALUE.  An
entry ENVVARNAME= diables the corresponding environment variable,
which might have been set in the init files like ~/.profile.

Special handling is applied to the PATH environment, which should
not be set here. Instead of, it should be set via `tramp-remote-path'."
Kai Großjohann's avatar
Kai Großjohann committed
956 957 958 959
  :group 'tramp
  :type '(repeat string))

(defcustom tramp-login-prompt-regexp
960
  ".*ogin\\( .*\\)?: *"
Kai Großjohann's avatar
Kai Großjohann committed
961
  "*Regexp matching login-like prompts.
962 963 964
The regexp should match at end of buffer.

Sometimes the prompt is reported to look like \"login as:\"."
Kai Großjohann's avatar
Kai Großjohann committed
965 966 967
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
968
(defcustom tramp-shell-prompt-pattern
969
  "^[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*"
Kai Großjohann's avatar
Kai Großjohann committed
970 971 972 973 974 975
  "Regexp to match prompts from remote shell.
Normally, Tramp expects you to configure `shell-prompt-pattern'
correctly, but sometimes it happens that you are connecting to a
remote host which sends a different kind of shell prompt.  Therefore,
Tramp recognizes things matched by `shell-prompt-pattern' as prompt,
and also things matched by this variable.  The default value of this
976
variable is similar to the default value of `shell-prompt-pattern',
Kai Großjohann's avatar
Kai Großjohann committed
977 978 979 980
which should work well in many cases."
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
981
(defcustom tramp-password-prompt-regexp
982
  "^.*\\([pP]assword\\|[pP]assphrase\\).*:\^@? *"
Kai Großjohann's avatar
Kai Großjohann committed
983
  "*Regexp matching password-like prompts.
Kai Großjohann's avatar
Kai Großjohann committed
984
The regexp should match at end of buffer.
Kai Großjohann's avatar
Kai Großjohann committed
985 986 987 988 989 990

The `sudo' program appears to insert a `^@' character into the prompt."
  :group 'tramp
  :type 'regexp)

(defcustom tramp-wrong-passwd-regexp
Kai Großjohann's avatar
Kai Großjohann committed
991 992
  (concat "^.*"
	  ;; These strings should be on the last line
993
	  (regexp-opt '("Permission denied"
Kai Großjohann's avatar
Kai Großjohann committed
994 995 996
			"Login incorrect"
			"Login Incorrect"
			"Connection refused"
997
			"Connection closed"
Kai Großjohann's avatar
Kai Großjohann committed
998 999
			"Sorry, try again."
			"Name or service not known"
1000 1001 1002
			"Host key verification failed."
			"No supported authentication methods left to try!"
			"Tramp connection closed") t)
Kai Großjohann's avatar
Kai Großjohann committed
1003 1004 1005 1006 1007 1008
	  ".*"
	  "\\|"
	  "^.*\\("
	  ;; Here comes a list of regexes, separated by \\|
	  "Received signal [0-9]+"
	  "\\).*")
Kai Großjohann's avatar
Kai Großjohann committed
1009
  "*Regexp matching a `login failed' message.
Kai Großjohann's avatar
Kai Großjohann committed
1010 1011 1012 1013 1014
The regexp should match at end of buffer."
  :group 'tramp
  :type 'regexp)

(defcustom tramp-yesno-prompt-regexp
Kai Großjohann's avatar
Kai Großjohann committed
1015 1016 1017 1018
  (concat
   (regexp-opt '("Are you sure you want to continue connecting (yes/no)?") t)
   "\\s-*")
  "Regular expression matching all yes/no queries which need to be confirmed.
Kai Großjohann's avatar
Kai Großjohann committed
1019
The confirmation should be done with yes or no.
Kai Großjohann's avatar
Kai Großjohann committed
1020 1021
The regexp should match at end of buffer.
See also `tramp-yn-prompt-regexp'."
Kai Großjohann's avatar
Kai Großjohann committed
1022 1023 1024
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
1025
(defcustom tramp-yn-prompt-regexp
Michael Albinus's avatar
Michael Albinus committed
1026 1027 1028 1029
  (concat
   (regexp-opt '("Store key in cache? (y/n)"
		 "Update cached key? (y/n, Return cancels connection)") t)
   "\\s-*")
Kai Großjohann's avatar
Kai Großjohann committed
1030 1031 1032 1033 1034 1035
  "Regular expression matching all y/n queries which need to be confirmed.
The confirmation should be done with y or n.
The regexp should match at end of buffer.
See also `tramp-yesno-prompt-regexp'."
  :group 'tramp
  :type 'regexp)
Kai Großjohann's avatar
Kai Großjohann committed
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047

(defcustom tramp-terminal-prompt-regexp
  (concat "\\("
	  "TERM = (.*)"
	  "\\|"
	  "Terminal type\\? \\[.*\\]"
	  "\\)\\s-*")
  "Regular expression matching all terminal setting prompts.
The regexp should match at end of buffer.
The answer will be provided by `tramp-action-terminal', which see."
  :group 'tramp
  :type 'regexp)
Kai Großjohann's avatar
Kai Großjohann committed
1048

Michael Albinus's avatar
Michael Albinus committed
1049 1050 1051 1052 1053 1054 1055 1056 1057
(defcustom tramp-operation-not-permitted-regexp
  (concat "\\(" "preserving times.*" "\\|" "set mode" "\\)" ":\\s-*"
	  (regexp-opt '("Operation not permitted") t))
  "Regular expression matching keep-date problems in (s)cp operations.
Copying has been performed successfully already, so this message can
be ignored safely."
  :group 'tramp
  :type 'regexp)

1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
(defcustom tramp-copy-failed-regexp
  (concat "\\(.+: "
          (regexp-opt '("Permission denied"
                        "not a regular file"
                        "is a directory"
                        "No such file or directory") t)
          "\\)\\s-*")
  "Regular expression matching copy problems in (s)cp operations."
  :group 'tramp
  :type 'regexp)

1069
(defcustom tramp-process-alive-regexp
1070
  ""
1071
  "Regular expression indicating a process has finished.
1072 1073
In fact this expression is empty by intention, it will be used only to
check regularly the status of the associated process.
Kai Großjohann's avatar
Kai Großjohann committed
1074
The answer will be provided by `tramp-action-process-alive',
1075
`tramp-action-out-of-band', which see."
1076 1077 1078
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
1079 1080 1081 1082
(defcustom tramp-temp-name-prefix "tramp."
  "*Prefix to use for temporary files.
If this is a relative file name (such as \"tramp.\"), it is considered
relative to the directory name returned by the function
1083
`tramp-compat-temporary-file-directory' (which see).  It may also be an
Kai Großjohann's avatar
Kai Großjohann committed
1084 1085 1086 1087 1088
absolute file name; don't forget to include a prefix for the filename
part, though."
  :group 'tramp
  :type 'string)

1089 1090 1091 1092
(defconst tramp-temp-buffer-name " *tramp temp*"
  "Buffer name for a temporary buffer.
It shall be used in combination with `generate-new-buffer-name'.")

1093
(defcustom tramp-sh-extra-args '(("/bash\\'" . "-norc -noprofile"))
1094 1095 1096 1097 1098 1099 1100 1101 1102
  "*Alist specifying extra arguments to pass to the remote shell.
Entries are (REGEXP . ARGS) where REGEXP is a regular expression
matching the shell file name and ARGS is a string specifying the
arguments.

This variable is only used when Tramp needs to start up another shell
for tilde expansion.  The extra arguments should typically prevent the
shell from reading its init file."
  :group 'tramp
Kai Großjohann's avatar
Kai Großjohann committed
1103 1104 1105 1106 1107
  ;; This might be the wrong way to test whether the widget type
  ;; `alist' is available.  Who knows the right way to test it?
  :type (if (get 'alist 'widget-type)
	    '(alist :key-type string :value-type string)
	  '(repeat (cons string string))))
1108

1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
;; XEmacs is distributed with few Lisp packages.  Further packages are
;; installed using EFS.  If we use a unified filename format, then
;; Tramp is required in addition to EFS.  (But why can't Tramp just
;; disable EFS when Tramp is loaded?  Then XEmacs can ship with EFS
;; just like before.)  Another reason for using a separate filename
;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
;; Tramp only knows how to deal with `file-name-handler-alist', not
;; the other places.

;; Currently, we have the choice between 'ftp, 'sep, and 'url.
;;;###autoload
(defcustom tramp-syntax
  (if (featurep 'xemacs) 'sep 'ftp)
  "Tramp filename syntax to be used.

It can have the following values:

  'ftp -- Ange-FTP respective EFS like syntax (GNU Emacs default)
  'sep -- Syntax as defined for XEmacs (not available yet for GNU Emacs)
  'url -- URL-like syntax."
1129
  :group 'tramp
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
  :type (if (featurep 'xemacs)
	    '(choice (const :tag "EFS"    ftp)
		     (const :tag "XEmacs" sep)
		     (const :tag "URL"    url))
	  '(choice (const :tag "Ange-FTP" ftp)
		   (const :tag "URL"      url))))

(defconst tramp-prefix-format
  (cond ((equal tramp-syntax 'ftp) "/")
	((equal tramp-syntax 'sep) "/[")
	((equal tramp-syntax 'url) "/")
	(t (error "Wrong `tramp-syntax' defined")))
1142
  "*String matching the very beginning of Tramp file names.
1143
Used in `tramp-make-tramp-file-name'.")
1144

1145
(defconst tramp-prefix-regexp
1146
  (concat "^" (regexp-quote tramp-prefix-format))
1147
  "*Regexp matching the very beginning of Tramp file names.
1148
Should always start with \"^\". Derived from `tramp-prefix-format'.")
1149

1150
(defconst tramp-method-regexp
1151
  "[a-zA-Z_0-9-]+"
1152
  "*Regexp matching methods identifiers.")
1153

1154 1155 1156 1157 1158
(defconst tramp-postfix-method-format
  (cond ((equal tramp-syntax 'ftp) ":")
	((equal tramp-syntax 'sep) "/")
	((equal tramp-syntax 'url) "://")
	(t (error "Wrong `tramp-syntax' defined")))
1159
  "*String matching delimeter between method and user or host names.
1160
Used in `tramp-make-tramp-file-name'.")
1161

1162 1163
(defconst tramp-postfix-method-regexp
  (regexp-quote tramp-postfix-method-format)
1164
  "*Regexp matching delimeter between method and user or host names.
1165
Derived from `tramp-postfix-method-format'.")
1166

1167 1168 1169
(defconst tramp-user-regexp
  "[^:/ \t]+"
  "*Regexp matching user names.")
1170

1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
(defconst tramp-prefix-domain-format "%"
  "*String matching delimeter between user and domain names.")

(defconst tramp-prefix-domain-regexp
  (regexp-quote tramp-prefix-domain-format)
  "*Regexp matching delimeter between user and domain names.
Derived from `tramp-prefix-domain-format'.")

(defconst tramp-domain-regexp
  "[a-zA-Z0-9]+"
  "*Regexp matching domain names.")

(defconst tramp-user-with-domain-regexp
  (concat "\\(" tramp-user-regexp "\\)"
	        tramp-prefix-domain-regexp
	  "\\(" tramp-domain-regexp "\\)")
  "*Regexp matching user names with domain names.")

1189
(defconst tramp-postfix-user-format
1190 1191
  "@"
  "*String matching delimeter between user and host names.
1192
Used in `tramp-make-tramp-file-name'.")
1193

1194
(defconst tramp-postfix-user-regexp
1195 1196
  (regexp-quote tramp-postfix-user-format)
  "*Regexp matching delimeter between user and host names.
1197 1198 1199 1200 1201 1202
Derived from `tramp-postfix-user-format'.")

(defconst tramp-host-regexp
  "[a-zA-Z0-9_.-]+"
  "*Regexp matching host names.")

1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
(defconst tramp-prefix-ipv6-format
  (cond ((equal tramp-syntax 'ftp) "[")
	((equal tramp-syntax 'sep) "")
	((equal tramp-syntax 'url) "[")
	(t (error "Wrong `tramp-syntax' defined")))
  "*String matching left hand side of IPv6 addresses.
Used in `tramp-make-tramp-file-name'.")

(defconst tramp-prefix-ipv6-regexp
  (regexp-quote tramp-prefix-ipv6-format)
  "*Regexp matching left hand side of IPv6 addresses.
Derived from `tramp-prefix-ipv6-format'.")

;; The following regexp is a bit sloppy.  But it shall serve our purposes.
(defconst tramp-ipv6-regexp
  "\\(?:\\(?:[a-zA-Z0-9]+\\)?:\\)+[a-zA-Z0-9]+"
  "*Regexp matching IPv6 addresses.")

(defconst tramp-postfix-ipv6-format
  (cond ((equal tramp-syntax 'ftp) "]")
	((equal tramp-syntax 'sep) "")
	((equal tramp-syntax 'url) "]")
	(t (error "Wrong `tramp-syntax' defined")))
  "*String matching right hand side of IPv6 addresses.
Used in `tramp-make-tramp-file-name'.")

(defconst tramp-postfix-ipv6-regexp
  (regexp-quote tramp-postfix-ipv6-format)
  "*Regexp matching right hand side of IPv6 addresses.
Derived from `tramp-postfix-ipv6-format'.")

1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
(defconst tramp-prefix-port-format
  (cond ((equal tramp-syntax 'ftp) "#")
	((equal tramp-syntax 'sep) "#")
	((equal tramp-syntax 'url) ":")
	(t (error "Wrong `tramp-syntax' defined")))
  "*String matching delimeter between host names and port numbers.")

(defconst tramp-prefix-port-regexp
  (regexp-quote tramp-prefix-port-format)
  "*Regexp matching delimeter between host names and port numbers.
Derived from `tramp-prefix-port-format'.")

(defconst tramp-port-regexp
  "[0-9]+"
  "*Regexp matching port numbers.")

(defconst tramp-host-with-port-regexp
  (concat "\\(" tramp-host-regexp "\\)"
	        tramp-prefix-port-regexp
	  "\\(" tramp-port-regexp "\\)")
  "*Regexp matching host names with port numbers.")

(defconst tramp-postfix-host-format
  (cond ((equal tramp-syntax 'ftp) ":")
	((equal tramp-syntax 'sep) "]")
	((equal tramp-syntax 'url) "")
	(t (error "Wrong `tramp-syntax' defined")))
Kai Großjohann's avatar
Kai Großjohann committed
1261
  "*String matching delimeter between host names and localnames.
1262
Used in `tramp-make-tramp-file-name'.")
1263

1264
(defconst tramp-postfix-host-regexp
1265
  (regexp-quote tramp-postfix-host-format)
Kai Großjohann's avatar
Kai Großjohann committed
1266
  "*Regexp matching delimeter between host names and localnames.
1267
Derived from `tramp-postfix-host-format'.")
1268

1269
(defconst tramp-localname-regexp
1270
  ".*$"
1271
  "*Regexp matching localnames.")
1272 1273

;; File name format.
1274

1275
(defconst tramp-file-name-structure
1276 1277 1278
  (list
   (concat
    tramp-prefix-regexp
1279 1280
    "\\(" "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp "\\)?"
    "\\(" "\\(" tramp-user-regexp "\\)"   tramp-postfix-user-regexp   "\\)?"
1281 1282 1283 1284 1285
    "\\(" "\\(" tramp-host-regexp
		"\\|"
		tramp-prefix-ipv6-regexp  tramp-ipv6-regexp
					  tramp-postfix-ipv6-regexp "\\)"
	  "\\(" tramp-prefix-port-regexp  tramp-port-regexp "\\)?" "\\)?"
1286 1287
    tramp-postfix-host-regexp
    "\\(" tramp-localname-regexp "\\)")
1288
   2 4 5 8)
1289

Kai Großjohann's avatar
Kai Großjohann committed
1290
  "*List of five elements (REGEXP METHOD USER HOST FILE), detailing \
1291
the Tramp file name structure.
Kai Großjohann's avatar
Kai Großjohann committed
1292

1293
The first element REGEXP is a regular expression matching a Tramp file
Kai Großjohann's avatar
Kai Großjohann committed
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
name.  The regex should contain parentheses around the method name,
the user name, the host name, and the file name parts.

The second element METHOD is a number, saying which pair of
parentheses matches the method name.  The third element USER is
similar, but for the user name.  The fourth element HOST is similar,
but for the host name.  The fifth element FILE is for the file name.
These numbers are passed directly to `match-string', which see.  That
means the opening parentheses are counted to identify the pair.

1304
See also `tramp-file-name-regexp'.")
Kai Großjohann's avatar
Kai Großjohann committed
1305 1306

;;;###autoload
1307
(defconst tramp-file-name-regexp-unified
1308
  "\\`/\\([^[/:]+\\|[^/]+]\\):"
1309 1310
  "Value for `tramp-file-name-regexp' for unified remoting.
Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
1311
Tramp.  See `tramp-file-name-structure' for more explanations.")
1312 1313 1314 1315 1316 1317

;;;###autoload
(defconst tramp-file-name-regexp-separate
  "\\`/\\[.*\\]"
  "Value for `tramp-file-name-regexp' for separate remoting.
XEmacs uses a separate filename syntax for Tramp and EFS.
1318
See `tramp-file-name-structure' for more explanations.")
1319 1320

;;;###autoload
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330