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

Paul Eggert's avatar
Paul Eggert committed
3
;; Copyright (C) 1998-2015 Free Software Foundation, Inc.
Kai Großjohann's avatar
Kai Großjohann committed
4

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

;; This file is part of GNU Emacs.

12
;; GNU Emacs is free software: you can redistribute it and/or modify
Kai Großjohann's avatar
Kai Großjohann committed
13
;; it under the terms of the GNU General Public License as published by
14 15
;; 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
16 17 18 19 20 21 22

;; 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
23
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Kai Großjohann's avatar
Kai Großjohann committed
24 25 26 27 28 29 30 31

;;; 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.
;;
32
;; For more detailed instructions, please see the info file.
Kai Großjohann's avatar
Kai Großjohann committed
33 34 35
;;
;; Notes:
;; -----
36
;;
37
;; This package only works for Emacs 22.1 and higher, and for XEmacs 21.4
38
;; and higher.  For XEmacs 21, you need the package `fsf-compat' for
39
;; the `with-timeout' macro.
Kai Großjohann's avatar
Kai Großjohann committed
40 41 42
;;
;; Also see the todo list at the bottom of this file.
;;
43
;; The current version of Tramp can be retrieved from the following URL:
Michael Albinus's avatar
Michael Albinus committed
44
;;            http://ftp.gnu.org/gnu/tramp/
Kai Großjohann's avatar
Kai Großjohann committed
45 46
;;
;; There's a mailing list for this, as well.  Its name is:
Michael Albinus's avatar
Michael Albinus committed
47 48 49
;;            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
50 51
;;
;; For the adventurous, the current development sources are available
52
;; via Git.  You can find instructions about this at the following URL:
53
;;            http://savannah.gnu.org/projects/tramp/
Kai Großjohann's avatar
Kai Großjohann committed
54 55 56 57 58
;;
;; Don't forget to put on your asbestos longjohns, first!

;;; Code:

59
(require 'tramp-compat)
Kai Großjohann's avatar
Kai Großjohann committed
60

Michael Albinus's avatar
Michael Albinus committed
61 62
;; Pacify byte-compiler.
(eval-when-compile
Michael Albinus's avatar
Michael Albinus committed
63 64 65 66
  (require 'cl))
(defvar bkup-backup-directory-info)
(defvar directory-sep-char)
(defvar eshell-path-env)
67
(defvar ls-lisp-use-insert-directory-program)
Michael Albinus's avatar
Michael Albinus committed
68
(defvar outline-regexp)
Michael Albinus's avatar
Michael Albinus committed
69

Kai Großjohann's avatar
Kai Großjohann committed
70 71 72
;;; User Customizable Internal Variables:

(defgroup tramp nil
73
  "Edit remote files with a combination of ssh, scp, etc."
74
  :group 'files
75
  :group 'comm
76
  :version "22.1")
Kai Großjohann's avatar
Kai Großjohann committed
77

78 79 80
;; Maybe we need once a real Tramp mode, with key bindings etc.
;;;###autoload
(defcustom tramp-mode t
81
  "Whether Tramp is enabled.
82 83 84 85
If it is set to nil, all remote file names are used literally."
  :group 'tramp
  :type 'boolean)

86
(defcustom tramp-verbose 3
87
  "Verbosity level for Tramp messages.
88 89 90 91 92 93 94 95 96 97 98
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
99
 9  test commands
100
10  traces (huge)."
Kai Großjohann's avatar
Kai Großjohann committed
101 102 103
  :group 'tramp
  :type 'integer)

104
;; Emacs case.
105 106 107 108 109 110 111
(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
112
name prefix \(method, user, host\) of file.
113 114 115 116 117 118 119 120 121 122 123 124 125 126

\(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
Michael Albinus's avatar
Michael Albinus committed
127
      "Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))
128 129 130
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
131
\(method, user, host\) of file.
132 133 134 135 136

\(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."
137
      :type '(repeat
138 139 140 141 142 143 144 145 146
	      (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
147
(defcustom tramp-auto-save-directory nil
148
  "Put auto-save files in this directory, if set.
Kai Großjohann's avatar
Kai Großjohann committed
149 150
The idea is to use a local directory so that auto-saving is faster."
  :group 'tramp
151
  :type '(choice (const nil) string))
Kai Großjohann's avatar
Kai Großjohann committed
152

153 154 155 156
(defcustom tramp-encoding-shell
  (if (memq system-type '(windows-nt))
      (getenv "COMSPEC")
    "/bin/sh")
157
  "Use this program for encoding and decoding commands on the local host.
158 159 160 161 162
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.

Paul Eggert's avatar
Paul Eggert committed
163
For encoding and decoding, commands like the following are executed:
164 165 166 167

    /bin/sh -c COMMAND < INPUT > OUTPUT

This variable can be used to change the \"/bin/sh\" part.  See the
168
variable `tramp-encoding-command-switch' for the \"-c\" part.
Kai Großjohann's avatar
Kai Großjohann committed
169

170 171 172
If the shell must be forced to be interactive, see
`tramp-encoding-command-interactive'.

Kai Großjohann's avatar
Kai Großjohann committed
173 174 175 176 177 178
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))

179 180 181 182
(defcustom tramp-encoding-command-switch
  (if (string-match "cmd\\.exe" tramp-encoding-shell)
      "/c"
    "-c")
183
  "Use this switch together with `tramp-encoding-shell' for local commands.
184 185 186 187
See the variable `tramp-encoding-shell' for more information."
  :group 'tramp
  :type 'string)

188 189
(defcustom tramp-encoding-command-interactive
  (unless (string-match "cmd\\.exe" tramp-encoding-shell) "-i")
190
  "Use this switch together with `tramp-encoding-shell' for interactive shells.
191
See the variable `tramp-encoding-shell' for more information."
192
  :version "24.1"
193 194 195
  :group 'tramp
  :type '(choice (const nil) string))

196
;;;###tramp-autoload
197
(defvar tramp-methods nil
198
  "Alist of methods for remote files.
Kai Großjohann's avatar
Kai Großjohann committed
199 200 201
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:
202
  * `tramp-remote-shell'
203 204 205 206 207 208 209
    This specifies the shell to use on the remote host.  This
    MUST be a Bourne-like shell.  It is normally not necessary to
    set this to any value other than \"/bin/sh\": Tramp wants to
    use a shell 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.
210 211
  * `tramp-remote-shell-args'
    For implementation of `shell-command', this specifies the
212
    arguments to let `tramp-remote-shell' run a single command.
213 214
  * `tramp-login-program'
    This specifies the name of the program to use for logging in to the
215 216
    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.
217
  * `tramp-login-args'
Kai Großjohann's avatar
Kai Großjohann committed
218
    This specifies the list of arguments to pass to the above
219
    mentioned program.  Please note that this is a list of list of arguments,
Kai Großjohann's avatar
Kai Großjohann committed
220
    that is, normally you don't want to put \"-a -b\" or \"-f foo\"
221 222 223 224 225 226 227 228 229
    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
230 231
    parameter of a program, if exists.  \"%c\" adds additional
    `tramp-ssh-controlmaster-options' options for the first hop.
232 233 234
  * `tramp-login-env'
     A list of environment variables and their values, which will
     be set when calling `tramp-login-program'.
235 236 237 238 239
  * `tramp-async-args'
    When an asynchronous process is started, we know already that
    the connection works.  Therefore, we can pass additional
    parameters to suppress diagnostic messages, in order not to
    tamper the process output.
240 241
  * `tramp-copy-program'
    This specifies the name of the program to use for remotely copying
242
    the file; this might be the absolute filename of scp or the name of
243
    a workalike program.  It is always applied on the local host.
244
  * `tramp-copy-args'
Kai Großjohann's avatar
Kai Großjohann committed
245
    This specifies the list of parameters to pass to the above mentioned
246
    program, the hints for `tramp-login-args' also apply here.
247 248 249
  * `tramp-copy-env'
     A list of environment variables and their values, which will
     be set when calling `tramp-copy-program'.
250 251 252 253 254 255 256
  * `tramp-remote-copy-program'
    The listener program to be applied on remote side, if needed.
  * `tramp-remote-copy-args'
    The list of parameters to pass to the listener program, the hints
    for `tramp-login-args' also apply here.  Additionally, \"%r\" could
    be used here and in `tramp-copy-args'.  It denotes a randomly
    chosen port for the remote listener.
257 258 259
  * `tramp-copy-keep-date'
    This specifies whether the copying program when the preserves the
    timestamp of the original file.
260 261 262 263 264
  * `tramp-copy-keep-tmpfile'
    This specifies whether a temporary local file shall be kept
    for optimization reasons (useful for \"rsync\" methods).
  * `tramp-copy-recursive'
    Whether the operation copies directories recursively.
265 266 267 268 269 270 271
  * `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.
272 273 274
  * `tramp-tmpdir'
    A directory on the remote host for temporary files.  If not
    specified, \"/tmp\" is taken as default.
275 276 277 278 279
  * `tramp-connection-timeout'
    This is the maximum time to be spent for establishing a connection.
    In general, the global default value shall be used, but for
    some methods, like \"su\" or \"sudo\", a shorter timeout
    might be desirable.
280 281 282 283

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
284
remote side.  One way is using an additional scp-like program.  If you want
285
to do this, set `tramp-copy-program' in the method.
Kai Großjohann's avatar
Kai Großjohann committed
286 287

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

295
So, to summarize: if the method is an out-of-band method, then you
296
must specify `tramp-copy-program' and `tramp-copy-args'.  If it is an
297 298
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
299 300 301

Notes:

302 303 304 305 306 307
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
308

309
;;;###tramp-autoload
310
(defcustom tramp-ssh-controlmaster-options
Michael Albinus's avatar
Michael Albinus committed
311 312
  (let ((result "")
	(case-fold-search t))
313
    (ignore-errors
314
      (when (executable-find "ssh")
315
	(with-temp-buffer
316
	  (call-process "ssh" nil t nil "-o" "ControlMaster")
317
	  (goto-char (point-min))
Michael Albinus's avatar
Michael Albinus committed
318
	  (when (search-forward-regexp "missing.+argument" nil t)
319 320 321 322 323 324 325
	    (setq result "-o ControlMaster=auto")))
	(unless (zerop (length result))
	  (with-temp-buffer
	    (call-process
	     "ssh" nil t nil "-o" "ControlPath=%C" "host.does.not.exist")
	    (goto-char (point-min))
	    (if (search-forward-regexp "unknown.+key" nil t)
326
		(setq result
Michael Albinus's avatar
Michael Albinus committed
327 328
		      (concat result " -o ControlPath='tramp.%%r@%%h:%%p'"))
	      (setq result (concat result " -o ControlPath='tramp.%%C'"))))
329 330 331 332 333
	  (with-temp-buffer
	    (call-process "ssh" nil t nil "-o" "ControlPersist")
	    (goto-char (point-min))
	    (when (search-forward-regexp "missing.+argument" nil t)
	      (setq result (concat result " -o ControlPersist=no")))))))
334 335
    result)
    "Call ssh to detect whether it supports the Control* arguments.
336 337 338 339
Return a string to be used in `tramp-methods'."
    :group 'tramp
    :version "24.5"
    :type 'string)
340

341 342 343 344 345 346 347 348
;;;###tramp-autoload
(defcustom tramp-use-ssh-controlmaster-options
  (not (zerop (length tramp-ssh-controlmaster-options)))
  "Whether to use `tramp-ssh-controlmaster-options'."
  :group 'tramp
  :version "24.4"
  :type 'boolean)

349
(defcustom tramp-default-method
Paul Eggert's avatar
Paul Eggert committed
350 351
  ;; An external copy method seems to be preferred, because it performs
  ;; much better for large files, and it hasn't too serious delays
352 353
  ;; for small files.  But it must be ensured that there aren't
  ;; permanent password queries.  Either a password agent like
354 355
  ;; "ssh-agent" or "Pageant" shall run, or the optional
  ;; password-cache.el or auth-sources.el packages shall be active for
356 357 358
  ;; password caching.  If we detect that the user is running OpenSSH
  ;; 4.0 or newer, we could reuse the connection, which calls also for
  ;; an external method.
359
  (cond
Glenn Morris's avatar
Glenn Morris committed
360 361 362 363 364
   ;; PuTTY is installed.  We don't take it, if it is installed on a
   ;; non-windows system, or pscp from the pssh (parallel ssh) package
   ;; is found.
   ((and (eq system-type 'windows-nt)
	 (executable-find "pscp"))
365
    (if	(or (fboundp 'password-read)
366
	    (fboundp 'auth-source-user-or-password)
367
	    (fboundp 'auth-source-search)
368
	    ;; Pageant is running.
369
	    (tramp-compat-process-running-p "Pageant"))
370 371 372 373
	"pscp"
      "plink"))
   ;; There is an ssh installation.
   ((executable-find "scp")
374 375 376 377 378 379 380
    (if	(or (fboundp 'password-read)
	    (fboundp 'auth-source-user-or-password)
	    (fboundp 'auth-source-search)
	    ;; ssh-agent is running.
	    (getenv "SSH_AUTH_SOCK")
	    (getenv "SSH_AGENT_PID")
	    ;; We could reuse the connection.
381
	    (> (length tramp-ssh-controlmaster-options) 0))
382 383
	"scp"
      "ssh"))
384 385
   ;; Fallback.
   (t "ftp"))
386
  "Default method to use for transferring files.
387
See `tramp-methods' for possibilities.
388
Also see `tramp-default-method-alist'."
389 390 391
  :group 'tramp
  :type 'string)

392
;;;###tramp-autoload
393
(defcustom tramp-default-method-alist nil
394
  "Default method to use for specific host/user pairs.
395 396 397 398 399 400 401 402 403 404 405
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
406 407 408
  :type '(repeat (list (choice :tag "Host regexp" regexp sexp)
		       (choice :tag "User regexp" regexp sexp)
		       (choice :tag "Method name" string (const nil)))))
409

410
(defcustom tramp-default-user nil
411
  "Default user to use for transferring files.
412 413 414 415 416 417 418
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))

419
;;;###tramp-autoload
420
(defcustom tramp-default-user-alist nil
421
  "Default user to use for specific method/host pairs.
422 423 424 425 426 427 428 429 430
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
431 432 433
  :type '(repeat (list (choice :tag "Method regexp" regexp sexp)
		       (choice :tag "  Host regexp" regexp sexp)
		       (choice :tag "    User name" string (const nil)))))
434

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

441 442 443 444 445 446 447 448 449 450 451 452
;;;###tramp-autoload
(defcustom tramp-default-host-alist nil
  "Default host to use for specific method/user pairs.
This is an alist of items (METHOD USER HOST).  The first matching item
specifies the host to use for a file name which does not specify a
host.  METHOD and HOST are regular expressions or nil, which is
interpreted as a regular expression which always matches.  If no entry
matches, the variable `tramp-default-host' takes effect.

If the file name does not specify the method, lookup is done using the
empty string for the method name."
  :group 'tramp
Glenn Morris's avatar
Glenn Morris committed
453
  :version "24.4"
454 455 456 457
  :type '(repeat (list (choice :tag "Method regexp" regexp sexp)
		       (choice :tag "  User regexp" regexp sexp)
		       (choice :tag "    Host name" string (const nil)))))

458
(defcustom tramp-default-proxies-alist nil
459
  "Route to be followed for specific host/user pairs.
460 461 462
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
463 464 465 466 467 468 469 470 471
expressions.  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.

HOST, USER or PROXY could also be Lisp forms, which will be
evaluated.  The result must be a string or nil, which is
interpreted as a regular expression which always matches."
472
  :group 'tramp
473 474
  :type '(repeat (list (choice :tag "Host regexp" regexp sexp)
		       (choice :tag "User regexp" regexp sexp)
475
		       (choice :tag " Proxy name" string (const nil)))))
476

Michael Albinus's avatar
Michael Albinus committed
477 478 479
(defcustom tramp-save-ad-hoc-proxies nil
  "Whether to save ad-hoc proxies persistently."
  :group 'tramp
Glenn Morris's avatar
Glenn Morris committed
480
  :version "24.3"
Michael Albinus's avatar
Michael Albinus committed
481 482
  :type 'boolean)

483 484 485 486 487 488 489 490
(defcustom tramp-restricted-shell-hosts-alist
  (when (memq system-type '(windows-nt))
    (list (concat "\\`" (regexp-quote (system-name)) "\\'")))
  "List of hosts, which run a restricted shell.
This is a list of regular expressions, which denote hosts running
a registered shell like \"rbash\".  Those hosts can be used as
proxies only, see `tramp-default-proxies-alist'.  If the local
host runs a registered shell, it shall be added to this list, too."
491
  :version "24.3"
492 493 494
  :group 'tramp
  :type '(repeat (regexp :tag "Host regexp")))

495
;;;###tramp-autoload
496 497
(defconst tramp-local-host-regexp
  (concat
498 499 500 501
   "\\`"
   (regexp-opt
    (list "localhost" "localhost6" (system-name) "127\.0\.0\.1" "::1") t)
   "\\'")
502
  "Host names which are regarded as local host.")
503

504
(defvar tramp-completion-function-alist nil
505
  "Alist of methods for remote files.
506
This is a list of entries of the form \(NAME PAIR1 PAIR2 ...\).
507
Each NAME stands for a remote access method.  Each PAIR is of the form
508
\(FUNCTION FILE\).  FUNCTION is responsible to extract user names and host
509 510
names from FILE for completion.  The following predefined FUNCTIONs exists:

511 512 513 514 515 516 517 518
 * `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.
Michael Albinus's avatar
Michael Albinus committed
519
 * `tramp-parse-putty'       for PuTTY registered sessions.
520 521 522 523

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

524 525 526
(defconst tramp-echo-mark-marker "_echo"
  "String marker to surround echoed commands.")

527 528 529 530 531 532
(defconst tramp-echo-mark-marker-length (length tramp-echo-mark-marker)
  "String length of `tramp-echo-mark-marker'.")

(defconst tramp-echo-mark
  (concat tramp-echo-mark-marker
	  (make-string tramp-echo-mark-marker-length ?\b))
533 534 535 536 537
  "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
538 539 540
`tramp-echoed-echo-mark-regexp'.  Using `tramp-echo-mark-marker',
followed by an equal number of backspaces to erase them will
usually suffice.")
541

542 543 544
(defconst tramp-echoed-echo-mark-regexp
  (format "%s\\(\b\\( \b\\)?\\)\\{%d\\}"
	  tramp-echo-mark-marker tramp-echo-mark-marker-length)
545 546 547
  "Regexp which matches `tramp-echo-mark' as it gets echoed by
the remote shell.")

548 549
(defcustom tramp-local-end-of-line
  (if (memq system-type '(windows-nt)) "\r\n" "\n")
550
  "String used for end of line in local processes."
551
  :version "24.1"
552 553 554
  :group 'tramp
  :type 'string)

Kai Großjohann's avatar
Kai Großjohann committed
555
(defcustom tramp-rsh-end-of-line "\n"
556
  "String used for end of line in rsh connections.
Kai Großjohann's avatar
Kai Großjohann committed
557
I don't think this ever needs to be changed, so please tell me about it
Michael Albinus's avatar
Michael Albinus committed
558
if you need to change this."
Kai Großjohann's avatar
Kai Großjohann committed
559 560 561 562
  :group 'tramp
  :type 'string)

(defcustom tramp-login-prompt-regexp
563
  ".*ogin\\( .*\\)?: *"
564
  "Regexp matching login-like prompts.
565 566 567
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
568 569 570
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
571
(defcustom tramp-shell-prompt-pattern
572
  ;; Allow a prompt to start right after a ^M since it indeed would be
573 574
  ;; displayed at the beginning of the line (and Zsh uses it).  This
  ;; regexp works only for GNU Emacs.
Michael Albinus's avatar
Michael Albinus committed
575 576
  ;; Allow also [] style prompts.  They can appear only during
  ;; connection initialization; Tramp redefines the prompt afterwards.
577
  (concat (if (featurep 'xemacs) "" "\\(?:^\\|\r\\)")
Michael Albinus's avatar
Michael Albinus committed
578
	  "[^]#$%>\n]*#?[]#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*")
Kai Großjohann's avatar
Kai Großjohann committed
579 580 581 582 583 584
  "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
585
variable is similar to the default value of `shell-prompt-pattern',
586 587 588 589
which should work well in many cases.

This regexp must match both `tramp-initial-end-of-output' and
`tramp-end-of-output'."
Kai Großjohann's avatar
Kai Großjohann committed
590 591 592
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
593
(defcustom tramp-password-prompt-regexp
Michael Albinus's avatar
Michael Albinus committed
594 595 596 597
  (format "^.*\\(%s\\).*:\^@? *"
	  (if (boundp 'password-word-equivalents)
	      (regexp-opt (symbol-value 'password-word-equivalents))
	    "password\\|passphrase"))
598
  "Regexp matching password-like prompts.
Kai Großjohann's avatar
Kai Großjohann committed
599
The regexp should match at end of buffer.
Kai Großjohann's avatar
Kai Großjohann committed
600 601

The `sudo' program appears to insert a `^@' character into the prompt."
602
  :version "24.4"
Kai Großjohann's avatar
Kai Großjohann committed
603 604 605 606
  :group 'tramp
  :type 'regexp)

(defcustom tramp-wrong-passwd-regexp
Kai Großjohann's avatar
Kai Großjohann committed
607 608
  (concat "^.*"
	  ;; These strings should be on the last line
609
	  (regexp-opt '("Permission denied"
Kai Großjohann's avatar
Kai Großjohann committed
610 611 612
			"Login incorrect"
			"Login Incorrect"
			"Connection refused"
613
			"Connection closed"
Michael Albinus's avatar
Michael Albinus committed
614
			"Timeout, server not responding."
Kai Großjohann's avatar
Kai Großjohann committed
615 616
			"Sorry, try again."
			"Name or service not known"
617
			"Host key verification failed."
618
			"No supported authentication methods left to try!") t)
Kai Großjohann's avatar
Kai Großjohann committed
619 620 621 622 623 624
	  ".*"
	  "\\|"
	  "^.*\\("
	  ;; Here comes a list of regexes, separated by \\|
	  "Received signal [0-9]+"
	  "\\).*")
625
  "Regexp matching a `login failed' message.
Kai Großjohann's avatar
Kai Großjohann committed
626 627 628 629 630
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
631 632 633 634
  (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
635
The confirmation should be done with yes or no.
Kai Großjohann's avatar
Kai Großjohann committed
636 637
The regexp should match at end of buffer.
See also `tramp-yn-prompt-regexp'."
Kai Großjohann's avatar
Kai Großjohann committed
638 639 640
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
641
(defcustom tramp-yn-prompt-regexp
Michael Albinus's avatar
Michael Albinus committed
642 643 644 645
  (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
646 647 648 649 650 651
  "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
652 653 654 655 656 657 658 659 660 661 662 663

(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
664

Michael Albinus's avatar
Michael Albinus committed
665 666 667 668 669 670 671 672 673
(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)

674 675 676 677 678 679 680 681 682 683 684
(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)

685
(defcustom tramp-process-alive-regexp
686
  ""
687
  "Regular expression indicating a process has finished.
688 689
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
690
The answer will be provided by `tramp-action-process-alive',
691
`tramp-action-out-of-band', which see."
692 693 694
  :group 'tramp
  :type 'regexp)

695
(defconst tramp-temp-name-prefix "tramp."
696
  "Prefix to use for temporary files.
Kai Großjohann's avatar
Kai Großjohann committed
697 698
If this is a relative file name (such as \"tramp.\"), it is considered
relative to the directory name returned by the function
699
`tramp-compat-temporary-file-directory' (which see).  It may also be an
Kai Großjohann's avatar
Kai Großjohann committed
700
absolute file name; don't forget to include a prefix for the filename
701
part, though.")
Kai Großjohann's avatar
Kai Großjohann committed
702

703 704 705 706
(defconst tramp-temp-buffer-name " *tramp temp*"
  "Buffer name for a temporary buffer.
It shall be used in combination with `generate-new-buffer-name'.")

707 708 709 710
(defvar tramp-temp-buffer-file-name nil
  "File name of a persistent local temporary file.
Useful for \"rsync\" like methods.")
(make-variable-buffer-local 'tramp-temp-buffer-file-name)
711
(put 'tramp-temp-buffer-file-name 'permanent-local t)
712

713 714 715 716 717 718 719 720 721
;; 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.

Michael Albinus's avatar
Michael Albinus committed
722
;; Currently, we have the choice between 'ftp and 'sep.
723 724 725 726 727 728 729 730
;;;###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)
Michael Albinus's avatar
Michael Albinus committed
731
  'sep -- Syntax as defined for XEmacs."
732
  :group 'tramp
Michael Albinus's avatar
Michael Albinus committed
733 734 735
  :version "24.4"
  :type `(choice (const :tag  ,(if (featurep 'xemacs) "EFS" "Ange-FTP") ftp)
		 (const :tag "XEmacs" sep)))
736 737 738 739 740

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

744
(defconst tramp-prefix-regexp
745
  (concat "^" (regexp-quote tramp-prefix-format))
746
  "Regexp matching the very beginning of Tramp file names.
747
Should always start with \"^\". Derived from `tramp-prefix-format'.")
748

749
(defconst tramp-method-regexp
750
  "[a-zA-Z_0-9-]+"
751
  "Regexp matching methods identifiers.")
752

753 754 755 756
(defconst tramp-postfix-method-format
  (cond ((equal tramp-syntax 'ftp) ":")
	((equal tramp-syntax 'sep) "/")
	(t (error "Wrong `tramp-syntax' defined")))
757
  "String matching delimiter between method and user or host names.
758
Used in `tramp-make-tramp-file-name'.")
759

760 761
(defconst tramp-postfix-method-regexp
  (regexp-quote tramp-postfix-method-format)
762
  "Regexp matching delimiter between method and user or host names.
763
Derived from `tramp-postfix-method-format'.")
764

Michael Albinus's avatar
Michael Albinus committed
765
(defconst tramp-user-regexp "[^/|: \t]+"
766
  "Regexp matching user names.")
767

768
;;;###tramp-autoload
769
(defconst tramp-prefix-domain-format "%"
770
  "String matching delimiter between user and domain names.")
771

772
;;;###tramp-autoload
773 774
(defconst tramp-prefix-domain-regexp
  (regexp-quote tramp-prefix-domain-format)
775
  "Regexp matching delimiter between user and domain names.
776 777
Derived from `tramp-prefix-domain-format'.")

778
(defconst tramp-domain-regexp "[-a-zA-Z0-9_.]+"
779
  "Regexp matching domain names.")
780 781 782 783 784

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

787
(defconst tramp-postfix-user-format "@"
788
  "String matching delimiter between user and host names.
789
Used in `tramp-make-tramp-file-name'.")
790

791
(defconst tramp-postfix-user-regexp
792
  (regexp-quote tramp-postfix-user-format)
793
  "Regexp matching delimiter between user and host names.
794 795
Derived from `tramp-postfix-user-format'.")

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

799 800 801 802
(defconst tramp-prefix-ipv6-format
  (cond ((equal tramp-syntax 'ftp) "[")
	((equal tramp-syntax 'sep) "")
	(t (error "Wrong `tramp-syntax' defined")))
803
  "String matching left hand side of IPv6 addresses.
804 805 806 807
Used in `tramp-make-tramp-file-name'.")

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

811 812 813
;; The following regexp is a bit sloppy.  But it shall serve our
;; purposes.  It covers also IPv4 mapped IPv6 addresses, like in
;; "::ffff:192.168.0.1".
814
(defconst tramp-ipv6-regexp
815
  "\\(?:\\(?:[a-zA-Z0-9]+\\)?:\\)+[a-zA-Z0-9.]+"
816
  "Regexp matching IPv6 addresses.")
817 818 819 820 821

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

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

830 831 832 833
(defconst tramp-prefix-port-format
  (cond ((equal tramp-syntax 'ftp) "#")
	((equal tramp-syntax 'sep) "#")
	(t (error "Wrong `tramp-syntax' defined")))
834
  "String matching delimiter between host names and port numbers.")
835 836 837

(defconst tramp-prefix-port-regexp
  (regexp-quote tramp-prefix-port-format)
838
  "Regexp matching delimiter between host names and port numbers.
839 840
Derived from `tramp-prefix-port-format'.")

841
(defconst tramp-port-regexp "[0-9]+"
842
  "Regexp matching port numbers.")
843 844 845 846 847

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

Michael Albinus's avatar
Michael Albinus committed
850 851 852 853 854 855 856 857
(defconst tramp-postfix-hop-format "|"
  "String matching delimiter after ad-hoc hop definitions.")

(defconst tramp-postfix-hop-regexp
  (regexp-quote tramp-postfix-hop-format)
  "Regexp matching delimiter after ad-hoc hop definitions.
Derived from `tramp-postfix-hop-format'.")

858 859 860 861
(defconst tramp-postfix-host-format
  (cond ((equal tramp-syntax 'ftp) ":")
	((equal tramp-syntax 'sep) "]")
	(t (error "Wrong `tramp-syntax' defined")))
862
  "String matching delimiter between host names and localnames.
863
Used in `tramp-make-tramp-file-name'.")
864

865
(defconst tramp-postfix-host-regexp
866
  (regexp-quote tramp-postfix-host-format)
867
  "Regexp matching delimiter between host names and localnames.
868
Derived from `tramp-postfix-host-format'.")
869

870
(defconst tramp-localname-regexp ".*$"
871
  "Regexp matching localnames.")
872

873
;;; File name format:
874

Michael Albinus's avatar
Michael Albinus committed
875 876 877 878 879
(defconst tramp-remote-file-name-spec-regexp
  (concat
   "\\(?:" "\\("   tramp-method-regexp "\\)" tramp-postfix-method-regexp "\\)?"
   "\\(?:" "\\("   tramp-user-regexp   "\\)" tramp-postfix-user-regexp   "\\)?"
   "\\("   "\\(?:" tramp-host-regexp   "\\|"
880
	           tramp-prefix-ipv6-regexp  "\\(?:" tramp-ipv6-regexp "\\)?"
Michael Albinus's avatar
Michael Albinus committed
881 882 883 884
		 			     tramp-postfix-ipv6-regexp "\\)"
	   "\\(?:" tramp-prefix-port-regexp  tramp-port-regexp "\\)?" "\\)?")
"Regular expression matching a Tramp file name between prefix and postfix.")

885
(defconst tramp-file-name-structure
886 887 888
  (list
   (concat
    tramp-prefix-regexp
Michael Albinus's avatar
Michael Albinus committed
889 890 891
    "\\(" "\\(?:" tramp-remote-file-name-spec-regexp
                  tramp-postfix-hop-regexp "\\)+" "\\)?"
    tramp-remote-file-name-spec-regexp tramp-postfix-host-regexp
892
    "\\(" tramp-localname-regexp "\\)")
Michael Albinus's avatar
Michael Albinus committed
893 894
   5 6 7 8 1)
  "List of six elements (REGEXP METHOD USER HOST FILE HOP), detailing \
895
the Tramp file name structure.
Kai Großjohann's avatar
Kai Großjohann committed
896

897
The first element REGEXP is a regular expression matching a Tramp file
Kai Großjohann's avatar
Kai Großjohann committed
898 899