annotate lisp/=ftp.el @ 29958:7507f083dcc5

(describe-variable): Don't insert a second `'s' in front of the string `value is shown below'. Since the syntax-table to emacs-lisp-mode-syntax-table makes forward-sexp skip over an existing `'s', so that this won't be deleted.
author Gerd Moellmann <gerd@gnu.org>
date Tue, 27 Jun 2000 10:54:26 +0000
parents 213978acbc1e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
660
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 633
diff changeset
1 ;;; ftp.el --- file input and output over Internet using FTP
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 633
diff changeset
2
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
3 ;; Copyright (C) 1987 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
4
793
6fb68a1460a6 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 660
diff changeset
5 ;; Author: Richard Mlynarik <mly@prep.ai.mit.edu>
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 ;; any later version.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
23 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
24
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
25 ;; Prevent changes in major modes from altering these variables.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
26 (put 'ftp-temp-file-name 'permanent-local t)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
27 (put 'ftp-file 'permanent-local t)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
28 (put 'ftp-host 'permanent-local t)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
29
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
30 ;; you can turn this off by doing
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31 ;; (setq ftp-password-alist 'compulsory-urinalysis)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32 (defvar ftp-password-alist () "Security sucks")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
33
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
34 (defun read-ftp-user-password (host user new)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
35 (let (tem)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
36 (if (and (not new)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37 (listp ftp-password-alist)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
38 (setq tem (cdr (assoc host ftp-password-alist)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39 (or (null user)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 (string= user (car tem))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 tem
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
42 (or user
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43 (progn
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 (setq tem (or (and (listp ftp-password-alist)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 (car (cdr (assoc host ftp-password-alist))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 (user-login-name)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47 (setq user (read-string (format
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 "User-name for %s (default \"%s\"): "
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49 host tem)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
50 (if (equal user "") (setq user tem))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
51 (setq tem (cons user
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
52 ;; If you want to use some non-echoing string-reader,
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
53 ;; feel free to write it yourself. I don't care enough.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 (read-string (format "Password for %s@%s: " user host)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 (if (not (listp ftp-password-alist))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 ""
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57 (or (cdr (cdr (assoc host ftp-password-alist)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 (let ((l ftp-password-alist))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59 (catch 'foo
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60 (while l
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
61 (if (string= (car (cdr (car l))) user)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
62 (throw 'foo (cdr (cdr (car l))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63 (setq l (cdr l))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64 nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 "")))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 (message "")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 (if (and (listp ftp-password-alist)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 (not (string= (cdr tem) "")))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 (setq ftp-password-alist (cons (cons host tem)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
70 ftp-password-alist)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
71 tem)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
72
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 (defun ftp-read-file-name (prompt)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74 (let ((s ""))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75 (while (not (string-match "\\`[ \t]*\\([^ \t:]+\\)[ \t]*:\\(.+\\)\\'" s))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
76 (setq s (read-string prompt s)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
77 (list (substring s (match-beginning 1) (match-end 1))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
78 (substring s (match-beginning 2) (match-end 2)))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80
318
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
81 ;;;###autoload
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
82 (defun ftp-find-file (host file &optional user password)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 "FTP to HOST to get FILE, logging in as USER with password PASSWORD.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 Interactively, HOST and FILE are specified by reading a string with
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
85 a colon character separating the host from the filename.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86 USER and PASSWORD are defaulted from the values used when
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 last ftping from HOST (unless password-remembering is disabled).
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88 Supply a password of the symbol `t' to override this default
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 (interactively, this is done by giving a prefix arg)"
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 (interactive
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 (append (ftp-read-file-name "FTP get host:file: ")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 (list nil (not (null current-prefix-arg)))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 (ftp-find-file-or-directory host file t user password))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94
318
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
95 ;;;###autoload
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 (defun ftp-list-directory (host file &optional user password)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 "FTP to HOST to list DIRECTORY, logging in as USER with password PASSWORD.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98 Interactively, HOST and FILE are specified by reading a string with
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 a colon character separating the host from the filename.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 USER and PASSWORD are defaulted from the values used when
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 last ftping from HOST (unless password-remembering is disabled).
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 Supply a password of the symbol `t' to override this default
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103 (interactively, this is done by giving a prefix arg)"
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 (interactive
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105 (append (ftp-read-file-name "FTP get host:directory: ")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
106 (list nil (not (null current-prefix-arg)))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 (ftp-find-file-or-directory host file nil user password))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
109 (defun ftp-find-file-or-directory (host file filep &optional user password)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
110 "FTP to HOST to get FILE. Third arg is t for file, nil for directory.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
111 Log in as USER with PASSWORD. If USER is nil or PASSWORD is nil or t,
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112 we prompt for the user name and password."
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
113 (or (and user password (not (eq password t)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114 (progn (setq user (read-ftp-user-password host user (eq password t))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 password (cdr user)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 user (car user))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 (let ((buffer (get-buffer-create (format "*ftp%s %s:%s*"
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 (if filep "" "-directory")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 host file))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120 (set-buffer buffer)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 (let ((process nil)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
122 (case-fold-search nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
123 (let ((win nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124 (unwind-protect
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 (progn
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
126 (setq process (ftp-setup-buffer host file))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
127 (if (setq win (ftp-login process host user password))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
128 (message "Logged in")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
129 (error "Ftp login failed")))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 (or win (and process (delete-process process)))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131 (message "Opening %s %s:%s..." (if filep "file" "directory")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
132 host file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 (if (ftp-command process
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
134 (format "%s \"%s\" -\nquit\n" (if filep "get" "dir")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
135 file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136 "\\(150\\|125\\).*\n"
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
137 "200.*\n")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
138 (progn (forward-line 1)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
139 (let ((buffer-read-only nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
140 (delete-region (point-min) (point)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
141 (message "Retrieving %s:%s in background. Bye!" host file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
142 (set-process-sentinel process
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
143 'ftp-asynchronous-input-sentinel)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
144 process)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
145 (switch-to-buffer buffer)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
146 (let ((buffer-read-only nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
147 (insert-before-markers "<<<Ftp lost>>>"))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
148 (delete-process process)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
149 (error "Ftp %s:%s lost" host file)))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
151
318
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
152 ;;;###autoload
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
153 (defun ftp-write-file (host file &optional user password)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
154 "FTP to HOST to write FILE, logging in as USER with password PASSWORD.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
155 Interactively, HOST and FILE are specified by reading a string with colon
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
156 separating the host from the filename.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
157 USER and PASSWORD are defaulted from the values used when
318
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
158 last ftping from HOST (unless `password-remembering' is disabled).
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
159 Supply a password of the symbol `t' to override this default
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
160 (interactively, this is done by giving a prefix arg)"
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
161 (interactive
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
162 (append (ftp-read-file-name "FTP write host:file: ")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
163 (list nil (not (null current-prefix-arg)))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
164 (or (and user password (not (eq password t)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
165 (progn (setq user (read-ftp-user-password host user (eq password t))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
166 password (cdr user)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
167 user (car user))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
168 (let ((buffer (get-buffer-create (format "*ftp %s:%s*" host file)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
169 (tmp (make-temp-name "/tmp/emacsftp")))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
170 (write-region (point-min) (point-max) tmp)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
171 (save-excursion
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
172 (set-buffer buffer)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
173 (make-local-variable 'ftp-temp-file-name)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
174 (setq ftp-temp-file-name tmp)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
175 (let ((process (ftp-setup-buffer host file))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
176 (case-fold-search nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
177 (let ((win nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
178 (unwind-protect
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
179 (if (setq win (ftp-login process host user password))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
180 (message "Logged in")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
181 (error "Ftp login lost"))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
182 (or win (delete-process process))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
183 (message "Opening file %s:%s..." host file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
184 (if (ftp-command process
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
185 (format "send \"%s\" \"%s\"\nquit\n" tmp file)
318
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
186 "\\(150\\|125\\).*\n"
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
187 "200.*\n")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
188 (progn (forward-line 1)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
189 (setq foo1 (current-buffer))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
190 (let ((buffer-read-only nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
191 (delete-region (point-min) (point)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
192 (message "Saving %s:%s in background. Bye!" host file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
193 (set-process-sentinel process
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
194 'ftp-asynchronous-output-sentinel)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
195 process)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
196 (switch-to-buffer buffer)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
197 (setq foo2 (current-buffer))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
198 (let ((buffer-read-only nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
199 (insert-before-markers "<<<Ftp lost>>>"))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
200 (delete-process process)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
201 (error "Ftp write %s:%s lost" host file))))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
202
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
203
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
204 (defun ftp-setup-buffer (host file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
205 (fundamental-mode)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
206 (and (get-buffer-process (current-buffer))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
207 (progn (discard-input)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
208 (if (y-or-n-p (format "Kill process \"%s\" in %s? "
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
209 (process-name (get-buffer-process
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
210 (current-buffer)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
211 (buffer-name (current-buffer))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
212 (while (get-buffer-process (current-buffer))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
213 (kill-process (get-buffer-process (current-buffer))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
214 (error "Foo"))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
215 ;(buffer-disable-undo (current-buffer))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
216 (setq buffer-read-only nil)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
217 (erase-buffer)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
218 (make-local-variable 'ftp-host)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
219 (setq ftp-host host)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
220 (make-local-variable 'ftp-file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
221 (setq ftp-file file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
222 (setq foo3 (current-buffer))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
223 (setq buffer-read-only t)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
224 (start-process "ftp" (current-buffer) "ftp" "-i" "-n" "-g"))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
225
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
226
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
227 (defun ftp-login (process host user password)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
228 (message "FTP logging in as %s@%s..." user host)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
229 (if (ftp-command process
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
230 (format "open %s\nuser %s %s\n" host user password)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
231 "230.*\n"
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
232 "\\(Connected to \\|220\\|331\\|Remote system type\\|Using.*mode\\|Remember to set\\).*\n")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
233 t
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
234 (switch-to-buffer (process-buffer process))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
235 (delete-process process)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
236 (if (listp ftp-password-alist)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
237 (setq ftp-password-alist (delq (assoc host ftp-password-alist)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
238 ftp-password-alist)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
239 nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
240
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
241 (defun ftp-command (process command win ignore)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
242 (process-send-string process command)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
243 (let ((p 1))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
244 (while (numberp p)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
245 (cond ;((not (bolp)))
318
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
246 ((looking-at "^[0-9]+-")
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
247 (while (not (re-search-forward "^[0-9]+ " nil t))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
248 (save-excursion
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
249 (accept-process-output process)))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
250 (beginning-of-line))
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
251 ((looking-at win)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
252 (goto-char (point-max))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
253 (setq p t))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
254 ((looking-at "^ftp> \\|^\n")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
255 (goto-char (match-end 0)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
256 ((looking-at ignore)
318
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
257 ;; Ignore status messages whose codes indicate no problem.
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
258 (forward-line 1))
633
379b94c9f29e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 318
diff changeset
259 ((looking-at "^[^0-9]")
379b94c9f29e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 318
diff changeset
260 ;; Ignore any lines that don't have status codes.
379b94c9f29e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 318
diff changeset
261 (forward-line 1))
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
262 ((not (search-forward "\n" nil t))
81
ef6cee0af549 *** empty log message ***
Robert J. Chassell <bob@rattlesnake.com>
parents: 64
diff changeset
263 ;; the way asynchronous process-output works with (point)
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
264 ;; is really really disgusting.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
265 (setq p (point))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
266 (condition-case ()
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
267 (accept-process-output process)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
268 (error nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
269 (goto-char p))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
270 (t
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
271 (setq p nil))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
272 p))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
273
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
274
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
275 (defun ftp-asynchronous-input-sentinel (process msg)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
276 (ftp-sentinel process msg t t))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
277 (defun ftp-synchronous-input-sentinel (process msg)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
278 (ftp-sentinel process msg nil t))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
279 (defun ftp-asynchronous-output-sentinel (process msg)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
280 (ftp-sentinel process msg t nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
281 (defun ftp-synchronous-output-sentinel (process msg)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
282 (ftp-sentinel process msg nil nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
283
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
284 (defun ftp-sentinel (process msg asynchronous input)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
285 (cond ((null (buffer-name (process-buffer process)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
286 ;; deleted buffer
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
287 (set-process-buffer process nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
288 ((and (eq (process-status process) 'exit)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
289 (= (process-exit-status process) 0))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
290 (save-excursion
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
291 (set-buffer (process-buffer process))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
292 (let (msg
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
293 (r (if input "[0-9]+ bytes received in [0-9]+\\.[0-9]+ seconds.*$" "[0-9]+ bytes sent in [0-9]+\\.[0-9]+ seconds.*$")))
318
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
294 (goto-char (point-max))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
295 (search-backward "226 ")
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
296 (if (looking-at r)
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
297 (search-backward "226 "))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
298 (let ((p (point)))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
299 (setq msg (concat (format "ftp %s %s:%s done"
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
300 (if input "read" "write")
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
301 ftp-host ftp-file)
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
302 (if (re-search-forward r nil t)
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
303 (concat ": " (buffer-substring
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
304 (match-beginning 0)
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
305 (match-end 0)))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
306 "")))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
307 (delete-region p (point-max))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
308 (save-excursion
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
309 (set-buffer (get-buffer-create "*ftp log*"))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
310 (let ((buffer-read-only nil))
036865305387 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 81
diff changeset
311 (insert msg ?\n))))
64
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
312 ;; Note the preceding let must end here
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
313 ;; so it doesn't cross the (kill-buffer (current-buffer)).
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
314 (if (not input)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
315 (progn
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
316 (condition-case ()
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
317 (and (boundp 'ftp-temp-file-name)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
318 ftp-temp-file-name
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
319 (delete-file ftp-temp-file-name))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
320 (error nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
321 ;; Kill the temporary buffer which the ftp process
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
322 ;; puts its output in.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
323 (kill-buffer (current-buffer)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
324 ;; You don't want to look at this.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
325 (let ((kludge (generate-new-buffer (format "%s:%s (ftp)"
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
326 ftp-host ftp-file))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
327 (setq kludge (prog1 (buffer-name kludge) (kill-buffer kludge)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
328 (rename-buffer kludge)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
329 ;; ok, you can look again now.
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
330 (set-buffer-modified-p nil)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
331 (ftp-setup-write-file-hooks)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
332 (if (and asynchronous
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
333 ;(waiting-for-user-input-p)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
334 )
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
335 (progn (message "%s" msg)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
336 (sleep-for 2))))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
337 ((memq (process-status process) '(exit signal))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
338 (save-excursion
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
339 (set-buffer (process-buffer process))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
340 (setq msg (format "Ftp died (buffer %s): %s"
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
341 (buffer-name (current-buffer))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
342 msg))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
343 (let ((buffer-read-only nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
344 (goto-char (point-max))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
345 (insert ?\n ?\n msg))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
346 (delete-process proc)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
347 (set-buffer (get-buffer-create "*ftp log*"))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
348 (let ((buffer-read-only nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
349 (goto-char (point-max))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
350 (insert msg))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
351 (if (waiting-for-user-input-p)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
352 (error "%s" msg))))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
353
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
354 (defun ftp-setup-write-file-hooks ()
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
355 (let ((hooks write-file-hooks))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
356 (make-local-variable 'write-file-hooks)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
357 (setq write-file-hooks (append write-file-hooks
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
358 '(ftp-write-file-hook))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
359 (make-local-variable 'revert-buffer-function)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
360 (setq revert-buffer-function 'ftp-revert-buffer)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
361 (setq default-directory "/tmp/")
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
362 (setq buffer-file-name (concat default-directory
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
363 (make-temp-name
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
364 (buffer-name (current-buffer)))))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
365 (setq buffer-read-only nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
366
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
367 (defun ftp-write-file-hook ()
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
368 (let ((process (ftp-write-file ftp-host ftp-file)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
369 (set-process-sentinel process 'ftp-synchronous-output-sentinel)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
370 (message "FTP writing %s:%s..." ftp-host ftp-file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
371 (while (eq (process-status process) 'run)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
372 (condition-case ()
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
373 (accept-process-output process)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
374 (error nil)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
375 (set-buffer-modified-p nil)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
376 (message "FTP writing %s:%s...done" ftp-host ftp-file))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
377 t)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
378
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
379 (defun ftp-revert-buffer (&rest ignore)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
380 (let ((process (ftp-find-file ftp-host ftp-file)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
381 (set-process-sentinel process 'ftp-synchronous-input-sentinel)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
382 (message "FTP reverting %s:%s" ftp-host ftp-file)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
383 (while (eq (process-status process) 'run)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
384 (condition-case ()
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
385 (accept-process-output process)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
386 (error nil)))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
387 (and (eq (process-status process) 'exit)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
388 (= (process-exit-status process) 0)
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
389 (set-buffer-modified-p nil))
b83e7a34c7ef Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
390 (message "Reverted")))
660
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 633
diff changeset
391
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 633
diff changeset
392 ;;; ftp.el ends here