tramp.el 290 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 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 45 46 47 48
;;
;; This version might not work with pre-Emacs 21 VC unless VC is
;; loaded before tramp.el.  Could you please test this and tell me about
;; the result?  Thanks.
;;
;; Also see the todo list at the bottom of this file.
;;
49
;; The current version of Tramp can be retrieved from the following URL:
Michael Albinus's avatar
Michael Albinus committed
50
;;            http://ftp.gnu.org/gnu/tramp/
Kai Großjohann's avatar
Kai Großjohann committed
51 52
;;
;; There's a mailing list for this, as well.  Its name is:
Michael Albinus's avatar
Michael Albinus committed
53 54 55
;;            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
56 57 58
;;
;; For the adventurous, the current development sources are available
;; via CVS.  You can find instructions about this at the following URL:
59
;;            http://savannah.gnu.org/projects/tramp/
Kai Großjohann's avatar
Kai Großjohann committed
60 61 62 63 64 65
;; Click on "CVS" in the navigation bar near the top.
;;
;; Don't forget to put on your asbestos longjohns, first!

;;; Code:

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

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

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

Kai Großjohann's avatar
Kai Großjohann committed
87 88 89
(require 'shell)
(require 'advice)

90 91 92 93
(eval-and-compile
  (if (featurep 'xemacs)
      (load "auth-source" 'noerror)
    (require 'auth-source nil 'noerror)))
94

95 96 97 98 99 100 101 102 103 104 105 106 107 108
;; 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))))

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

116
(autoload 'uudecode-decode-region "uudecode")
117

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

125
	 ;; Tramp interactive commands.
126 127 128 129 130 131 132 133 134 135 136 137 138
	 '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
139

140 141 142 143
	 ;; Load gateways.  It needs `make-network-process' from Emacs 22.
	 (when (functionp 'make-network-process) 'tramp-gw)))

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

;;; User Customizable Internal Variables:

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

157 158 159 160 161 162 163 164
;; 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)

165
(defcustom tramp-verbose 3
166
  "*Verbosity level for Tramp.
167 168 169 170 171 172 173 174 175 176 177 178
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
179 180 181
  :group 'tramp
  :type 'integer)

182 183 184 185 186 187 188 189
;; 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
190
name prefix \(method, user, host\) of file.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

\(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
209
\(method, user, host\) of file.
210 211 212 213 214

\(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."
215
      :type '(repeat
216 217 218 219 220 221 222 223 224
	      (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
225 226 227 228
(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
229
  :type '(choice (const nil) string))
Kai Großjohann's avatar
Kai Großjohann committed
230

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
(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
246
variable `tramp-encoding-command-switch' for the \"-c\" part.
Kai Großjohann's avatar
Kai Großjohann committed
247 248 249 250 251 252 253

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))

254 255 256 257 258 259 260 261 262
(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)

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

268 269 270 271 272
(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
273
  :group 'tramp
274
  :type 'string)
Kai Großjohann's avatar
Kai Großjohann committed
275

276 277 278 279 280 281 282 283 284
(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")
285
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
286 287 288 289 290 291 292 293 294 295 296 297
					  ("-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")
298
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
299 300 301 302 303 304 305 306 307 308 309 310 311
					  ("-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")
312
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
313 314 315 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
					  ("-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")
374
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
375 376 377 378 379 380 381 382 383 384 385 386
					  ("-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")
387
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
388 389 390 391 392 393 394 395 396 397 398 399
					  ("-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")
400
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
401 402 403 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
					  ("-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")
455
					  ("-s") ("-H") ("-p" "Password:")))
456 457 458 459 460 461
	     (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")
462
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
					  ("-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")
479
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
480 481 482 483 484 485 486 487 488 489 490 491
					  ("-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")
492
             (tramp-login-args           (("%h") ("-l" "%u") ("-p" "%p") ("-q")
493 494 495 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
					  ("-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")
533 534 535
	     ;; ("%h") must be a single element, see
	     ;; `tramp-compute-multi-hops'.
	     (tramp-login-args           (("-load") ("%h") ("-t")
536 537 538
					  (,(format
					     "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=$ '"
					     tramp-terminal-type))
539 540 541 542 543 544 545 546 547 548 549
					  ("/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")
550
	     (tramp-copy-args            (("-P" "%p") ("-scp") ("-p" "%k")))
551 552 553 554 555 556 557 558
	     (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")
559
	     (tramp-copy-args            (("-P" "%p") ("-sftp") ("-p" "%k")))
560 561 562 563 564 565 566 567 568
	     (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
569 570 571 572 573 574 575
  "*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
576
    this to any value other than \"/bin/sh\": Tramp wants to use a shell
Kai Großjohann's avatar
Kai Großjohann committed
577 578 579
    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.
580 581
  * `tramp-login-program'
    This specifies the name of the program to use for logging in to the
582 583
    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.
584
  * `tramp-login-args'
Kai Großjohann's avatar
Kai Großjohann committed
585
    This specifies the list of arguments to pass to the above
586
    mentioned program.  Please note that this is a list of list of arguments,
Kai Großjohann's avatar
Kai Großjohann committed
587
    that is, normally you don't want to put \"-a -b\" or \"-f foo\"
588 589 590 591 592 593 594 595 596 597
    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.
598 599 600 601 602
  * `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
603
    This specifies the list of parameters to pass to the above mentioned
604
    program, the hints for `tramp-login-args' also apply here.
605 606 607 608 609 610 611 612 613 614
  * `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
615 616 617 618 619 620 621 622 623
  * `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\".
624 625 626 627 628 629

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
630 631

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

639
So, to summarize: if the method is an out-of-band method, then you
640
must specify `tramp-copy-program' and `tramp-copy-args'.  If it is an
641 642
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
643 644 645

Notes:

646 647 648 649 650 651
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
652

653
(defcustom tramp-default-method
654 655 656 657 658 659 660 661 662
  ;; 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.
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
  (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
683
  "*Default method to use for transferring files.
684
See `tramp-methods' for possibilities.
685
Also see `tramp-default-method-alist'."
686 687 688
  :group 'tramp
  :type 'string)

689
(defcustom tramp-default-method-alist
690
  '(("\\`localhost\\'" "\\`root\\'" "su"))
691
  "*Default method to use for specific host/user pairs.
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
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"))))

707 708 709 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
(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"))))

758
(defconst tramp-completion-function-alist-rsh
759 760
  '((tramp-parse-rhosts "/etc/hosts.equiv")
    (tramp-parse-rhosts "~/.rhosts"))
761
  "Default list of (FUNCTION FILE) pairs to be examined for rsh methods.")
762 763

(defconst tramp-completion-function-alist-ssh
764 765 766 767 768 769 770 771 772 773 774 775
  '((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"))
776
  "Default list of (FUNCTION FILE) pairs to be examined for ssh methods.")
777 778

(defconst tramp-completion-function-alist-telnet
779
  '((tramp-parse-hosts "/etc/hosts"))
780
  "Default list of (FUNCTION FILE) pairs to be examined for telnet methods.")
781 782

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

786 787 788 789 790
(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.")

791
(defvar tramp-completion-function-alist nil
792 793 794 795 796 797
  "*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:

798 799 800 801 802 803 804 805
 * `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.
806
 * `tramp-parse-putty'       for PuTTY registry keys.
807 808 809 810 811 812 813 814 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

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)
849
     (tramp-set-completion-function
850 851 852 853 854 855 856 857 858
      "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)
859 860
     (tramp-set-completion-function
      "plinkx" tramp-completion-function-alist-putty)
861 862 863 864
     (tramp-set-completion-function
      "pscp" tramp-completion-function-alist-ssh)
     (tramp-set-completion-function
      "fcp" tramp-completion-function-alist-ssh)))
865

866 867 868
(defconst tramp-echo-mark-marker "_echo"
  "String marker to surround echoed commands.")

869 870 871 872 873 874
(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
875 876 877
`tramp-echoed-echo-mark-regexp'.  Using `tramp-echo-mark-marker',
followed by an equal number of backspaces to erase them will
usually suffice.")
878 879 880 881 882

(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
883 884 885
(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
886
if you need to change this.
Kai Großjohann's avatar
Kai Großjohann committed
887 888
Also see the method parameter `tramp-password-end-of-line' and the normal
variable `tramp-default-password-end-of-line'."
889 890 891
  :group 'tramp
  :type 'string)

Kai Großjohann's avatar
Kai Großjohann committed
892 893
(defcustom tramp-default-password-end-of-line
  tramp-rsh-end-of-line
894
  "*String used for end of line after sending a password.
Kai Großjohann's avatar
Kai Großjohann committed
895 896 897
This variable provides the default value for the method parameter
`tramp-password-end-of-line', see `tramp-methods' for more details.

898 899 900 901 902 903
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
904 905 906
  :group 'tramp
  :type 'string)

907 908 909
;; "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
910
;; GNU/Linux (Debian, Suse): /bin:/usr/bin
911
;; FreeBSD: /usr/bin:/bin:/usr/sbin:/sbin: - beware trailing ":"!
Kai Großjohann's avatar
Kai Großjohann committed
912
(defcustom tramp-remote-path
913 914
  '(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
915 916
    "/usr/freeware/bin" "/usr/pkg/bin" "/usr/contrib/bin")
  "*List of directories to search for executables on remote host.
917 918
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
919 920

You can use `~' in this list, but when searching for a shell which groks
921 922 923 924 925 926 927 928 929 930 931 932
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
933
  `("HISTFILE=$HOME/.tramp_history" "HISTSIZE=1" "LC_ALL=C"
934 935 936 937 938 939 940 941 942 943 944 945
    ,(concat "TERM=" tramp-terminal-type)
    "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
946 947 948 949
  :group 'tramp
  :type '(repeat string))

(defcustom tramp-login-prompt-regexp
950
  ".*ogin\\( .*\\)?: *"
Kai Großjohann's avatar
Kai Großjohann committed
951
  "*Regexp matching login-like prompts.
952 953 954
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
955 956 957
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
958
(defcustom tramp-shell-prompt-pattern
959
  "^[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*"
Kai Großjohann's avatar
Kai Großjohann committed
960 961 962 963 964 965
  "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
966
variable is similar to the default value of `shell-prompt-pattern',
Kai Großjohann's avatar
Kai Großjohann committed
967 968 969 970
which should work well in many cases."
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
971
(defcustom tramp-password-prompt-regexp
972
  "^.*\\([pP]assword\\|[pP]assphrase\\).*:\^@? *"
Kai Großjohann's avatar
Kai Großjohann committed
973
  "*Regexp matching password-like prompts.
Kai Großjohann's avatar
Kai Großjohann committed
974
The regexp should match at end of buffer.
Kai Großjohann's avatar
Kai Großjohann committed
975 976 977 978 979 980

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

Kai Großjohann's avatar
Kai Großjohann committed
1015
(defcustom tramp-yn-prompt-regexp
Michael Albinus's avatar
Michael Albinus committed
1016 1017 1018 1019
  (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
1020 1021 1022 1023 1024 1025
  "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
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037

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

Michael Albinus's avatar
Michael Albinus committed
1039 1040 1041 1042 1043 1044 1045 1046 1047
(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)

1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
(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)

1059
(defcustom tramp-process-alive-regexp
1060
  ""
1061
  "Regular expression indicating a process has finished.
1062 1063
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
1064
The answer will be provided by `tramp-action-process-alive',
1065
`tramp-action-out-of-band', which see."
1066 1067 1068
  :group 'tramp
  :type 'regexp)

Kai Großjohann's avatar
Kai Großjohann committed
1069 1070 1071 1072
(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
1073
`tramp-compat-temporary-file-directory' (which see).  It may also be an
Kai Großjohann's avatar
Kai Großjohann committed
1074 1075 1076 1077 1078
absolute file name; don't forget to include a prefix for the filename
part, though."
  :group 'tramp
  :type 'string)

1079 1080 1081 1082
(defconst tramp-temp-buffer-name " *tramp temp*"
  "Buffer name for a temporary buffer.
It shall be used in combination with `generate-new-buffer-name'.")

1083
(defcustom tramp-sh-extra-args '(("/bash\\'" . "-norc -noprofile"))
1084 1085 1086 1087 1088 1089 1090 1091 1092
  "*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
1093 1094 1095 1096 1097
  ;; 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))))
1098

1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
;; 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."
1119
  :group 'tramp
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
  :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")))
1132
  "*String matching the very beginning of Tramp file names.
1133
Used in `tramp-make-tramp-file-name'.")
1134

1135
(defconst tramp-prefix-regexp
1136
  (concat "^" (regexp-quote tramp-prefix-format))
1137
  "*Regexp matching the very beginning of Tramp file names.
1138
Should always start with \"^\". Derived from `tramp-prefix-format'.")
1139

1140
(defconst tramp-method-regexp
1141
  "[a-zA-Z_0-9-]+"
1142
  "*Regexp matching methods identifiers.")
1143

1144 1145 1146 1147 1148
(defconst tramp-postfix-method-format
  (cond ((equal tramp-syntax 'ftp) ":")
	((equal tramp-syntax 'sep) "/")
	((equal tramp-syntax 'url) "://")
	(t (error "Wrong `tramp-syntax' defined")))
1149
  "*String matching delimeter between method and user or host names.
1150
Used in `tramp-make-tramp-file-name'.")
1151

1152 1153
(defconst tramp-postfix-method-regexp
  (regexp-quote tramp-postfix-method-format)
1154
  "*Regexp matching delimeter between method and user or host names.
1155
Derived from `tramp-postfix-method-format'.")
1156

1157 1158 1159
(defconst tramp-user-regexp
  "[^:/ \t]+"
  "*Regexp matching user names.")
1160

1161
(defconst tramp-postfix-user-format
1162 1163
  "@"
  "*String matching delimeter between user and host names.
1164
Used in `tramp-make-tramp-file-name'.")
1165

1166
(defconst tramp-postfix-user-regexp
1167 1168
  (regexp-quote tramp-postfix-user-format)
  "*Regexp matching delimeter between user and host names.
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
Derived from `tramp-postfix-user-format'.")

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

(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
1202
  "*String matching delimeter between host names and localnames.
1203
Used in `tramp-make-tramp-file-name'.")
1204

1205
(defconst tramp-postfix-host-regexp
1206
  (regexp-quote tramp-postfix-host-format)
Kai Großjohann's avatar
Kai Großjohann committed
1207
  "*Regexp matching delimeter between host names and localnames.
1208
Derived from `tramp-postfix-host-format'.")
1209

1210
(defconst tramp-localname-regexp
1211
  ".*$"
1212
  "*Regexp matching localnames.")
1213 1214

;; File name format.
1215

1216
(defconst tramp-file-name-structure
1217 1218 1219
  (list
   (concat
    tramp-prefix-regexp
1220 1221 1222 1223 1224 1225 1226
    "\\(" "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp "\\)?"
    "\\(" "\\(" tramp-user-regexp "\\)"   tramp-postfix-user-regexp   "\\)?"
    "\\(" tramp-host-regexp
          "\\(" tramp-prefix-port-regexp  tramp-port-regexp "\\)?" "\\)?"
    tramp-postfix-host-regexp
    "\\(" tramp-localname-regexp "\\)")
   2 4 5 7)
1227

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

1231
The first element REGEXP is a regular expression matching a Tramp file
Kai Großjohann's avatar
Kai Großjohann committed
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
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.

1242
See also `tramp-file-name-regexp'.")
Kai Großjohann's avatar
Kai Großjohann committed
1243 1244

;;;###autoload
1245 1246 1247 1248
(defconst tramp-file-name-regexp-unified
  "\\`/[^/:]+:"
  "Value for `tramp-file-name-regexp' for unified remoting.
Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
1249
Tramp.  See `tramp-file-name-structure' for more explanations.")
1250 1251 1252 1253 1254 1255

;;;###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.
1256
See `tramp-file-name-structure' for more explanations.")
1257 1258

;;;###autoload
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
(defconst tramp-file-name-regexp-url
  "\\`/[^/:]+://"
  "Value for `tramp-file-name-regexp' for URL-like remoting.
See `tramp-file-name-structure' for more explanations.")

;;;###autoload
(defconst tramp-file-name-regexp
  (cond ((equal tramp-syntax 'ftp) tramp-file-name-regexp-unified)
	((equal tramp-syntax 'sep) tramp-file-name-regexp-separate)
	((equal tramp-syntax 'url) tramp-file-name-regexp-url)
	(t (error "Wrong `tramp-syntax' defined")))
1270
  "*Regular expression matching file names handled by Tramp.
1271
This regexp should match Tramp file names but no other file names.
Kai Großjohann's avatar
Kai Großjohann committed
1272 1273
\(When tramp.el is loaded, this regular expression is prepended to
`file-name-handler-alist', and that is searched sequentially.  Thus,
1274 1275
if the Tramp entry appears rather early in the `file-name-handler-alist'
and is a bit too general, then some files might be considered Tramp
1276
files which are not really Tramp files.
Kai Großjohann's avatar
Kai Großjohann committed
1277 1278 1279 1280 1281 1282

Please note that the entry in `file-name-handler-alist' is made when
this file (tramp.el) is loaded.  This means that this variable must be set
before loading tramp.el.  Alternatively, `file-name-handler-alist' can be
updated after changing this variable.

1283
Also see `tramp-file-name-structure'.")
Kai Großjohann's avatar
Kai Großjohann committed
1284

1285
;;;###autoload
1286
(defconst tramp-root-regexp
1287
  (if (memq system-type '(cygwin windows-nt))
1288 1289
      "^\\([a-zA-Z]:\\)?/"
    "^/")
1290 1291
  "Beginning of an incomplete Tramp file name.
Usually, it is just \"^/\".  On W32 systems, there might be a
1292
volume letter, which will be removed by `tramp-drop-volume-letter'.")
1293 1294 1295 1296

;;;###autoload
(defconst tramp-completion-file-name-regexp-unified
  (concat tramp-root-regexp "[^/]*$")
1297
  "Value for `tramp-completion-file-name-regexp' for unified remoting.
1298 1299
GNU Emacs uses a unified filename syntax for Tramp and Ange-FTP.
See `tramp-file-name-structure' for more explanations.")
Kai Großjohann's avatar
Kai Großjohann committed
1300