Mercurial > emacs
annotate lisp/net/ange-ftp.el @ 107072:abe576120f76
* net/ange-ftp.el (ange-ftp-skip-msgs): Ignore all ""^500 .*AUTH"
messages.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Tue, 02 Feb 2010 12:19:36 +0100 |
parents | 5555e86608c1 |
children | 59d8f3cc91f4 |
rev | line source |
---|---|
28210 | 1 ;;; ange-ftp.el --- transparent FTP support for GNU Emacs |
2 | |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64667
diff
changeset
|
3 ;; Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, |
106815 | 4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
104552
10c38084881d
Remove code for defunct system-types emx, macos, mswindows,
Glenn Morris <rgm@gnu.org>
parents:
102850
diff
changeset
|
5 ;; Free Software Foundation, Inc. |
28210 | 6 |
7 ;; Author: Andy Norman (ange@hplb.hpl.hp.com) | |
8 ;; Maintainer: FSF | |
9 ;; Keywords: comm | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92148
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
28210 | 14 ;; it under the terms of the GNU General Public License as published by |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92148
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92148
diff
changeset
|
16 ;; (at your option) any later version. |
28210 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92148
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
28210 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This package attempts to make accessing files and directories using FTP | |
29 ;; from within GNU Emacs as simple and transparent as possible. A subset of | |
30 ;; the common file-handling routines are extended to interact with FTP. | |
31 | |
32 ;; Usage: | |
33 ;; | |
34 ;; Some of the common GNU Emacs file-handling operations have been made | |
35 ;; FTP-smart. If one of these routines is given a filename that matches | |
36 ;; '/user@host:name' then it will spawn an FTP process connecting to machine | |
37 ;; 'host' as account 'user' and perform its operation on the file 'name'. | |
38 ;; | |
39 ;; For example: if find-file is given a filename of: | |
40 ;; | |
41 ;; /ange@anorman:/tmp/notes | |
42 ;; | |
43 ;; then ange-ftp spawns an FTP process, connect to the host 'anorman' as | |
44 ;; user 'ange', get the file '/tmp/notes' and pop up a buffer containing the | |
45 ;; contents of that file as if it were on the local filesystem. If ange-ftp | |
46 ;; needs a password to connect then it reads one in the echo area. | |
47 | |
48 ;; Extended filename syntax: | |
49 ;; | |
50 ;; The default extended filename syntax is '/user@host:name', where the | |
51 ;; 'user@' part may be omitted. This syntax can be customised to a certain | |
52 ;; extent by changing ange-ftp-name-format. There are limitations. | |
53 ;; The `host' part has an optional suffix `#port' which may be used to | |
54 ;; specify a non-default port number for the connexion. | |
55 ;; | |
56 ;; If the user part is omitted then ange-ftp generates a default user | |
57 ;; instead whose value depends on the variable ange-ftp-default-user. | |
58 | |
59 ;; Passwords: | |
60 ;; | |
61 ;; A password is required for each host/user pair. Ange-ftp reads passwords | |
62 ;; as needed. You can also specify a password with ange-ftp-set-passwd, or | |
63 ;; in a *valid* ~/.netrc file. | |
64 | |
65 ;; Passwords for user "anonymous": | |
66 ;; | |
67 ;; Passwords for the user "anonymous" (or "ftp") are handled | |
68 ;; specially. The variable `ange-ftp-generate-anonymous-password' | |
69 ;; controls what happens: if the value of this variable is a string, | |
70 ;; then this is used as the password; if non-nil (the default), then | |
71 ;; the value of `user-mail-address' is used; if nil then the user | |
72 ;; is prompted for a password as normal. | |
73 | |
74 ;; "Dumb" UNIX hosts: | |
75 ;; | |
76 ;; The FTP servers on some UNIX machines have problems if the 'ls' command is | |
77 ;; used. | |
78 ;; | |
79 ;; The routine ange-ftp-add-dumb-unix-host can be called to tell ange-ftp to | |
80 ;; limit itself to the DIR command and not 'ls' for a given UNIX host. Note | |
81 ;; that this change will take effect for the current GNU Emacs session only. | |
82 ;; See below for a discussion of non-UNIX hosts. If a large number of | |
83 ;; machines with similar hostnames have this problem then it is easier to set | |
84 ;; the value of ange-ftp-dumb-unix-host-regexp in your .emacs file. ange-ftp | |
85 ;; is unable to automatically recognize dumb unix hosts. | |
86 | |
87 ;; File name completion: | |
88 ;; | |
89 ;; Full file-name completion is supported on UNIX, VMS, CMS, and MTS hosts. | |
90 ;; To do filename completion, ange-ftp needs a listing from the remote host. | |
91 ;; Therefore, for very slow connections, it might not save any time. | |
92 | |
93 ;; FTP processes: | |
94 ;; | |
95 ;; When ange-ftp starts up an FTP process, it leaves it running for speed | |
96 ;; purposes. Some FTP servers will close the connection after a period of | |
97 ;; time, but ange-ftp should be able to quietly reconnect the next time that | |
98 ;; the process is needed. | |
99 ;; | |
100 ;; Killing the "*ftp user@host*" buffer also kills the ftp process. | |
101 ;; This should not cause ange-ftp any grief. | |
102 | |
103 ;; Binary file transfers: | |
104 ;; | |
105 ;; By default ange-ftp transfers files in ASCII mode. If a file being | |
106 ;; transferred matches the value of ange-ftp-binary-file-name-regexp then | |
107 ;; binary mode is used for that transfer. | |
108 | |
109 ;; Account passwords: | |
110 ;; | |
111 ;; Some FTP servers require an additional password which is sent by the | |
112 ;; ACCOUNT command. ange-ftp partially supports this by allowing the user to | |
113 ;; specify an account password by either calling ange-ftp-set-account, or by | |
114 ;; specifying an account token in the .netrc file. If the account password | |
115 ;; is set by either of these methods then ange-ftp will issue an ACCOUNT | |
116 ;; command upon starting the FTP process. | |
117 | |
118 ;; Preloading: | |
119 ;; | |
120 ;; ange-ftp can be preloaded, but must be put in the site-init.el file and | |
121 ;; not the site-load.el file in order for the documentation strings for the | |
122 ;; functions being overloaded to be available. | |
123 | |
124 ;; Status reports: | |
125 ;; | |
126 ;; Most ange-ftp commands that talk to the FTP process output a status | |
127 ;; message on what they are doing. In addition, ange-ftp can take advantage | |
128 ;; of the FTP client's HASH command to display the status of transferring | |
129 ;; files and listing directories. See the documentation for the variables | |
130 ;; ange-ftp-{ascii,binary}-hash-mark-size, ange-ftp-send-hash and | |
131 ;; ange-ftp-process-verbose for more details. | |
132 | |
133 ;; Gateways: | |
134 ;; | |
135 ;; Sometimes it is necessary for the FTP process to be run on a different | |
136 ;; machine than the machine running GNU Emacs. This can happen when the | |
137 ;; local machine has restrictions on what hosts it can access. | |
138 ;; | |
139 ;; ange-ftp has support for running the ftp process on a different (gateway) | |
140 ;; machine. The way it works is as follows: | |
141 ;; | |
142 ;; 1) Set the variable 'ange-ftp-gateway-host' to the name of a machine | |
143 ;; that doesn't have the access restrictions. | |
144 ;; | |
145 ;; 2) Set the variable 'ange-ftp-local-host-regexp' to a regular expression | |
146 ;; that matches hosts that can be contacted from running a local ftp | |
147 ;; process, but fails to match hosts that can't be accessed locally. For | |
148 ;; example: | |
149 ;; | |
150 ;; "\\.hp\\.com$\\|^[^.]*$" | |
151 ;; | |
152 ;; will match all hosts that are in the .hp.com domain, or don't have an | |
153 ;; explicit domain in their name, but will fail to match hosts with | |
154 ;; explicit domains or that are specified by their ip address. | |
155 ;; | |
156 ;; 3) Using NFS and symlinks, make sure that there is a shared directory with | |
157 ;; the *same* name between the local machine and the gateway machine. | |
158 ;; This directory is necessary for temporary files created by ange-ftp. | |
159 ;; | |
160 ;; 4) Set the variable 'ange-ftp-gateway-tmp-name-template' to the name of | |
161 ;; this directory plus an identifying filename prefix. For example: | |
162 ;; | |
163 ;; "/nfs/hplose/ange/ange-ftp" | |
164 ;; | |
165 ;; where /nfs/hplose/ange is a directory that is shared between the | |
166 ;; gateway machine and the local machine. | |
167 ;; | |
168 ;; The simplest way of getting a ftp process running on the gateway machine | |
169 ;; is if you can spawn a remote shell using either 'rsh' or 'remsh'. If you | |
170 ;; can't do this for some reason such as security then points 7 onwards will | |
171 ;; discuss an alternative approach. | |
172 ;; | |
173 ;; 5) Set the variable ange-ftp-gateway-program to the name of the remote | |
174 ;; shell process such as 'remsh' or 'rsh' if the default isn't correct. | |
175 ;; | |
176 ;; 6) Set the variable ange-ftp-gateway-program-interactive to nil if it | |
177 ;; isn't already. This tells ange-ftp that you are using a remote shell | |
178 ;; rather than logging in using telnet or rlogin. | |
179 ;; | |
180 ;; That should be all you need to allow ange-ftp to spawn a ftp process on | |
181 ;; the gateway machine. If you have to use telnet or rlogin to get to the | |
182 ;; gateway machine then follow the instructions below. | |
183 ;; | |
184 ;; 7) Set the variable ange-ftp-gateway-program to the name of the program | |
185 ;; that lets you log onto the gateway machine. This may be something like | |
186 ;; telnet or rlogin. | |
187 ;; | |
188 ;; 8) Set the variable ange-ftp-gateway-prompt-pattern to a regular | |
189 ;; expression that matches the prompt you get when you login to the | |
190 ;; gateway machine. Be very specific here; this regexp must not match | |
191 ;; *anything* in your login banner except this prompt. | |
192 ;; shell-prompt-pattern is far too general as it appears to match some | |
193 ;; login banners from Sun machines. For example: | |
194 ;; | |
195 ;; "^$*$ *" | |
196 ;; | |
197 ;; 9) Set the variable ange-ftp-gateway-program-interactive to 't' to let | |
198 ;; ange-ftp know that it has to "hand-hold" the login to the gateway | |
199 ;; machine. | |
200 ;; | |
201 ;; 10) Set the variable ange-ftp-gateway-setup-term-command to a UNIX command | |
202 ;; that will put the pty connected to the gateway machine into a | |
203 ;; no-echoing mode, and will strip off carriage-returns from output from | |
204 ;; the gateway machine. For example: | |
205 ;; | |
206 ;; "stty -onlcr -echo" | |
207 ;; | |
208 ;; will work on HP-UX machines, whereas: | |
209 ;; | |
210 ;; "stty -echo nl" | |
211 ;; | |
212 ;; appears to work for some Sun machines. | |
213 ;; | |
214 ;; That's all there is to it. | |
215 | |
216 ;; Smart gateways: | |
217 ;; | |
218 ;; If you have a "smart" ftp program that allows you to issue commands like | |
219 ;; "USER foo@bar" which do nice proxy things, then look at the variables | |
220 ;; ange-ftp-smart-gateway and ange-ftp-smart-gateway-port. | |
221 ;; | |
222 ;; Otherwise, if there is an alternate ftp program that implements proxy in | |
223 ;; a transparent way (i.e. w/o specifying the proxy host), that will | |
224 ;; connect you directly to the desired destination host: | |
225 ;; Set ange-ftp-gateway-ftp-program-name to that program's name. | |
226 ;; Set ange-ftp-local-host-regexp to a value as stated earlier on. | |
227 ;; Leave ange-ftp-gateway-host set to nil. | |
228 ;; Set ange-ftp-smart-gateway to t. | |
229 | |
230 ;; Tips for using ange-ftp: | |
231 ;; | |
232 ;; 1. For dired to work on a host which marks symlinks with a trailing @ in | |
233 ;; an ls -alF listing, you need to (setq dired-ls-F-marks-symlinks t). | |
234 ;; Most UNIX systems do not do this, but ULTRIX does. If you think that | |
235 ;; there is a chance you might connect to an ULTRIX machine (such as | |
236 ;; prep.ai.mit.edu), then set this variable accordingly. This will have | |
237 ;; the side effect that dired will have problems with symlinks whose names | |
238 ;; end in an @. If you get yourself into this situation then editing | |
239 ;; dired's ls-switches to remove "F", will temporarily fix things. | |
240 ;; | |
241 ;; 2. If you know that you are connecting to a certain non-UNIX machine | |
242 ;; frequently, and ange-ftp seems to be unable to guess its host-type, | |
243 ;; then setting the appropriate host-type regexp | |
244 ;; (ange-ftp-vms-host-regexp, ange-ftp-mts-host-regexp, or | |
245 ;; ange-ftp-cms-host-regexp) accordingly should help. Also, please report | |
246 ;; ange-ftp's inability to recognize the host-type as a bug. | |
247 ;; | |
248 ;; 3. For slow connections, you might get "listing unreadable" error | |
249 ;; messages, or get an empty buffer for a file that you know has something | |
250 ;; in it. The solution is to increase the value of ange-ftp-retry-time. | |
251 ;; Its default value is 5 which is plenty for reasonable connections. | |
252 ;; However, for some transatlantic connections I set this to 20. | |
253 ;; | |
254 ;; 4. Beware of compressing files on non-UNIX hosts. Ange-ftp will do it by | |
255 ;; copying the file to the local machine, compressing it there, and then | |
256 ;; sending it back. Binary file transfers between machines of different | |
257 ;; architectures can be a risky business. Test things out first on some | |
258 ;; test files. See "Bugs" below. Also, note that ange-ftp copies files by | |
259 ;; moving them through the local machine. Again, be careful when doing | |
260 ;; this with binary files on non-Unix machines. | |
261 ;; | |
262 ;; 5. Beware that dired over ftp will use your setting of dired-no-confirm | |
263 ;; (list of dired commands for which confirmation is not asked). You | |
264 ;; might want to reconsider your setting of this variable, because you | |
265 ;; might want confirmation for more commands on remote direds than on | |
266 ;; local direds. For example, I strongly recommend that you not include | |
267 ;; compress and uncompress in this list. If there is enough demand it | |
268 ;; might be a good idea to have an alist ange-ftp-dired-no-confirm of | |
269 ;; pairs ( TYPE . LIST ), where TYPE is an operating system type and LIST | |
270 ;; is a list of commands for which confirmation would be suppressed. Then | |
271 ;; remote dired listings would take their (buffer-local) value of | |
272 ;; dired-no-confirm from this alist. Who votes for this? | |
273 | |
274 ;; --------------------------------------------------------------------- | |
275 ;; Non-UNIX support: | |
276 ;; --------------------------------------------------------------------- | |
277 | |
278 ;; VMS support: | |
279 ;; | |
280 ;; Ange-ftp has full support for VMS hosts. It | |
281 ;; should be able to automatically recognize any VMS machine. However, if it | |
282 ;; fails to do this, you can use the command ange-ftp-add-vms-host. As well, | |
283 ;; you can set the variable ange-ftp-vms-host-regexp in your .emacs file. We | |
284 ;; would be grateful if you would report any failures to automatically | |
285 ;; recognize a VMS host as a bug. | |
286 ;; | |
287 ;; Filename Syntax: | |
288 ;; | |
289 ;; For ease of *implementation*, the user enters the VMS filename syntax in a | |
290 ;; UNIX-y way. For example: | |
291 ;; PUB$:[ANONYMOUS.SDSCPUB.NEXT]README.TXT;1 | |
292 ;; would be entered as: | |
293 ;; /PUB$$:/ANONYMOUS/SDSCPUB/NEXT/README.TXT;1 | |
294 ;; i.e. to log in as anonymous on ymir.claremont.edu and grab the file: | |
295 ;; [.CSV.POLICY]RULES.MEM | |
296 ;; you would type: | |
297 ;; C-x C-f /anonymous@ymir.claremont.edu:CSV/POLICY/RULES.MEM | |
298 ;; | |
80044
b62f4b92bc13
*** empty log message ***
Juanma Barranquero <lekktu@gmail.com>
parents:
79714
diff
changeset
|
299 ;; A valid VMS filename is of the form: FILE.TYPE;## |
28210 | 300 ;; where FILE can be up to 39 characters |
301 ;; TYPE can be up to 39 characters | |
302 ;; ## is a version number (an integer between 1 and 32,767) | |
303 ;; Valid characters in FILE and TYPE are A-Z 0-9 _ - $ | |
304 ;; $ cannot begin a filename, and - cannot be used as the first or last | |
305 ;; character. | |
306 ;; | |
307 ;; Tips: | |
308 ;; 1. Although VMS is not case sensitive, EMACS running under UNIX is. | |
309 ;; Therefore, to access a VMS file, you must enter the filename with upper | |
310 ;; case letters. | |
311 ;; 2. To access the latest version of file under VMS, you use the filename | |
312 ;; without the ";" and version number. You should always edit the latest | |
313 ;; version of a file. If you want to edit an earlier version, copy it to a | |
314 ;; new file first. This has nothing to do with ange-ftp, but is simply | |
315 ;; good VMS operating practice. Therefore, to edit FILE.TXT;3 (say 3 is | |
316 ;; latest version), do C-x C-f /ymir.claremont.edu:FILE.TXT. If you | |
317 ;; inadvertently do C-x C-f /ymir.claremont.edu:FILE.TXT;3, you will find | |
318 ;; that VMS will not allow you to save the file because it will refuse to | |
319 ;; overwrite FILE.TXT;3, but instead will want to create FILE.TXT;4, and | |
320 ;; attach the buffer to this file. To get out of this situation, M-x | |
321 ;; write-file /ymir.claremont.edu:FILE.TXT will attach the buffer to | |
322 ;; latest version of the file. For this reason, in dired "f" | |
323 ;; (dired-find-file), always loads the file sans version, whereas "v", | |
324 ;; (dired-view-file), always loads the explicit version number. The | |
325 ;; reasoning being that it reasonable to view old versions of a file, but | |
326 ;; not to edit them. | |
327 ;; 3. EMACS has a feature in which it does environment variable substitution | |
328 ;; in filenames. Therefore, to enter a $ in a filename, you must quote it | |
329 ;; by typing $$. | |
330 | |
331 ;; MTS support: | |
332 ;; | |
333 ;; Ange-ftp has full support for hosts running | |
334 ;; the Michigan terminal system. It should be able to automatically | |
335 ;; recognize any MTS machine. However, if it fails to do this, you can use | |
336 ;; the command ange-ftp-add-mts-host. As well, you can set the variable | |
337 ;; ange-ftp-mts-host-regexp in your .emacs file. We would be grateful if you | |
338 ;; would report any failures to automatically recognize a MTS host as a bug. | |
339 ;; | |
340 ;; Filename syntax: | |
30459 | 341 ;; |
28210 | 342 ;; MTS filenames are entered in a UNIX-y way. For example, if your account |
343 ;; was YYYY, the file FILE in the account XXXX: on mtsg.ubc.ca would be | |
344 ;; entered as | |
345 ;; /YYYY@mtsg.ubc.ca:/XXXX:/FILE | |
346 ;; In other words, MTS accounts are treated as UNIX directories. Of course, | |
347 ;; to access a file in another account, you must have access permission for | |
348 ;; it. If FILE were in your own account, then you could enter it in a | |
349 ;; relative name fashion as | |
350 ;; /YYYY@mtsg.ubc.ca:FILE | |
351 ;; MTS filenames can be up to 12 characters. Like UNIX, the structure of the | |
352 ;; filename does not contain a TYPE (i.e. it can have as many "."'s as you | |
353 ;; like.) MTS filenames are always in upper case, and hence be sure to enter | |
354 ;; them as such! MTS is not case sensitive, but an EMACS running under UNIX | |
355 ;; is. | |
356 | |
357 ;; CMS support: | |
30459 | 358 ;; |
28210 | 359 ;; Ange-ftp has full support for hosts running |
360 ;; CMS. It should be able to automatically recognize any CMS machine. | |
361 ;; However, if it fails to do this, you can use the command | |
362 ;; ange-ftp-add-cms-host. As well, you can set the variable | |
363 ;; ange-ftp-cms-host-regexp in your .emacs file. We would be grateful if you | |
364 ;; would report any failures to automatically recognize a CMS host as a bug. | |
30459 | 365 ;; |
28210 | 366 ;; Filename syntax: |
367 ;; | |
368 ;; CMS filenames are entered in a UNIX-y way. In otherwords, minidisks are | |
369 ;; treated as UNIX directories. For example to access the file READ.ME in | |
370 ;; minidisk *.311 on cuvmb.cc.columbia.edu, you would enter | |
371 ;; /anonymous@cuvmb.cc.columbia.edu:/*.311/READ.ME | |
372 ;; If *.301 is the default minidisk for this account, you could access | |
373 ;; FOO.BAR on this minidisk as | |
374 ;; /anonymous@cuvmb.cc.columbia.edu:FOO.BAR | |
375 ;; CMS filenames are of the form FILE.TYPE, where both FILE and TYPE can be | |
376 ;; up to 8 characters. Again, beware that CMS filenames are always upper | |
377 ;; case, and hence must be entered as such. | |
378 ;; | |
379 ;; Tips: | |
380 ;; 1. CMS machines, with the exception of anonymous accounts, nearly always | |
381 ;; need an account password. To have ange-ftp send an account password, | |
382 ;; you can either include it in your .netrc file, or use | |
383 ;; ange-ftp-set-account. | |
384 ;; 2. Ange-ftp cannot send "write passwords" for a minidisk. Hopefully, we | |
385 ;; can fix this. | |
386 ;; | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
387 ;; BS2000 support: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
388 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
389 ;; Ange-ftp has full support for BS2000 hosts. It should be able to |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
390 ;; automatically recognize any BS2000 machine. However, if it fails to |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
391 ;; do this, you can use the command ange-ftp-add-bs2000-host. As well, |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
392 ;; you can set the variable ange-ftp-bs2000-host-regexp in your .emacs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
393 ;; file. We would be grateful if you would report any failures to auto- |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
394 ;; matically recognize a BS2000 host as a bug. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
395 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
396 ;; If you want to access the POSIX subsystem on BS2000 you MUST use |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
397 ;; command ange-ftp-add-bs2000-posix-host for that particular |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
398 ;; hostname. ange-ftp can't decide if you want to access the native |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
399 ;; filesystem or the POSIX filesystem, so it accesses the native |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
400 ;; filesystem by default. And if you have an ASCII filesystem in |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
401 ;; your BS2000 POSIX subsystem you must use |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
402 ;; ange-ftp-binary-file-name-regexp to access its files. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
403 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
404 ;; Filename Syntax: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
405 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
406 ;; For ease of *implementation*, the user enters the BS2000 filename |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
407 ;; syntax in a UNIX-y way. For example: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
408 ;; :PUB:$PUBLIC.ANONYMOUS.SDSCPUB.NEXT.README.TXT |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
409 ;; would be entered as: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
410 ;; /:PUB:/$$PUBLIC/ANONYMOUS.SDSCPUB.NEXT.README.TXT |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
411 ;; You don't have to type pubset and account, if they have default values, |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
412 ;; i.e. to log in as anonymous on bs2000.anywhere.com and grab the file |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
413 ;; IMPORTANT.TEXT.ON.BS2000 on the default pubset X on userid PUBLIC |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
414 ;; (there are only 8 characters in a valid username), you could type: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
415 ;; C-x C-f /public@bs2000.anywhere.com:/IMPORTANT.TEXT.ON.BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
416 ;; or |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
417 ;; C-x C-f /anonym@bs2000.anywhere.com:/:X:/$$PUBLIC/IMPORTANT.TEXT.ON.BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
418 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
419 ;; If X is not your default pubset, you could add it as 'subdirectory' (BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
420 ;; has a flat architecture) with the command |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
421 ;; (setq ange-ftp-bs2000-additional-pubsets '(":X:")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
422 ;; and then you could type: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
423 ;; C-x C-f /anonym@bs2000.anywhere.com:/:X:/IMPORTANT.TEXT.ON.BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
424 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
425 ;; Valid characters in an BS2000 filename are A-Z 0-9 $ # @ . - |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
426 ;; If the first character in a filename is # or @, this is replaced with |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
427 ;; ange-ftp-bs2000-special-prefix because names starting with # or @ |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
428 ;; are reserved for temporary files. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
429 ;; This is especially important for auto-save files. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47575
diff
changeset
|
430 ;; Valid file generations are ending with ([+|-|*]0-9...) . |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
431 ;; File generations are not supported yet! |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
432 ;; A filename must at least contain one character (A-Z) and cannot be longer |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
433 ;; than 41 characters. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
434 ;; |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
435 ;; Tips: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
436 ;; 1. Although BS2000 is not case sensitive, EMACS running under UNIX is. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
437 ;; Therefore, to access a BS2000 file, you must enter the filename with |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
438 ;; upper case letters. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
439 ;; 2. EMACS has a feature in which it does environment variable substitution |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
440 ;; in filenames. Therefore, to enter a $ in a filename, you must quote it |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
441 ;; by typing $$. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
442 ;; 3. BS2000 machines, with the exception of anonymous accounts, nearly |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
443 ;; always need an account password. To have ange-ftp send an account |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
444 ;; password, you can either include it in your .netrc file, or use |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
445 ;; ange-ftp-set-account. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
446 ;; |
28210 | 447 ;; ------------------------------------------------------------------ |
448 ;; Bugs: | |
449 ;; ------------------------------------------------------------------ | |
30459 | 450 ;; |
28210 | 451 ;; 1. Umask problems: |
452 ;; Be warned that files created by using ange-ftp will take account of the | |
453 ;; umask of the ftp daemon process rather than the umask of the creating | |
454 ;; user. This is particularly important when logging in as the root user. | |
455 ;; The way that I tighten up the ftp daemon's umask under HP-UX is to make | |
456 ;; sure that the umask is changed to 027 before I spawn /etc/inetd. I | |
457 ;; suspect that there is something similar on other systems. | |
458 ;; | |
459 ;; 2. Some combinations of FTP clients and servers break and get out of sync | |
460 ;; when asked to list a non-existent directory. Some of the ai.mit.edu | |
461 ;; machines cause this problem for some FTP clients. Using | |
462 ;; ange-ftp-kill-ftp-process can restart the ftp process, which | |
463 ;; should get things back in sync. | |
464 ;; | |
465 ;; 3. Ange-ftp does not check to make sure that when creating a new file, | |
466 ;; you provide a valid filename for the remote operating system. | |
467 ;; If you do not, then the remote FTP server will most likely | |
468 ;; translate your filename in some way. This may cause ange-ftp to | |
469 ;; get confused about what exactly is the name of the file. The | |
470 ;; most common causes of this are using lower case filenames on systems | |
471 ;; which support only upper case, and using filenames which are too | |
472 ;; long. | |
473 ;; | |
474 ;; 4. Null (blank) passwords confuse both ange-ftp and some FTP daemons. | |
475 ;; | |
476 ;; 5. Ange-ftp likes to use pty's to talk to its FTP processes. If GNU Emacs | |
477 ;; for some reason creates a FTP process that only talks via pipes then | |
478 ;; ange-ftp won't be getting the information it requires at the time that | |
479 ;; it wants it since pipes flush at different times to pty's. One | |
480 ;; disgusting way around this problem is to talk to the FTP process via | |
481 ;; rlogin which does the 'right' things with pty's. | |
482 ;; | |
483 ;; 6. For CMS support, we send too many cd's. Since cd's are cheap, I haven't | |
484 ;; worried about this too much. Eventually, we should have some caching | |
485 ;; of the current minidisk. | |
30459 | 486 ;; |
28210 | 487 ;; 7. Some CMS machines do not assign a default minidisk when you ftp them as |
488 ;; anonymous. It is then necessary to guess a valid minidisk name, and cd | |
489 ;; to it. This is (understandably) beyond ange-ftp. | |
490 ;; | |
491 ;; 8. Remote to remote copying of files on non-Unix machines can be risky. | |
492 ;; Depending on the variable ange-ftp-binary-file-name-regexp, ange-ftp | |
493 ;; will use binary mode for the copy. Between systems of different | |
494 ;; architecture, this still may not be enough to guarantee the integrity | |
495 ;; of binary files. Binary file transfers from VMS machines are | |
496 ;; particularly problematical. Should ange-ftp-binary-file-name-regexp be | |
497 ;; an alist of OS type, regexp pairs? | |
498 ;; | |
499 ;; 9. The code to do compression of files over ftp is not as careful as it | |
500 ;; should be. It deletes the old remote version of the file, before | |
501 ;; actually checking if the local to remote transfer of the compressed | |
502 ;; file succeeds. Of course to delete the original version of the file | |
503 ;; after transferring the compressed version back is also dangerous, | |
504 ;; because some OS's have severe restrictions on the length of filenames, | |
505 ;; and when the compressed version is copied back the "-Z" or ".Z" may be | |
506 ;; truncated. Then, ange-ftp would delete the only remaining version of | |
507 ;; the file. Maybe ange-ftp should make backups when it compresses files | |
508 ;; (of course, the backup "~" could also be truncated off, sigh...). | |
509 ;; Suggestions? | |
510 ;; | |
511 ;; 10. If a dir listing is attempted for an empty directory on (at least | |
512 ;; some) VMS hosts, an ftp error is given. This is really an ftp bug, and | |
513 ;; I don't know how to get ange-ftp work to around it. | |
514 ;; | |
515 ;; 11. Bombs on filenames that start with a space. Deals well with filenames | |
516 ;; containing spaces, but beware that the remote ftpd may not like them | |
517 ;; much. | |
518 ;; | |
519 ;; 12. The dired support for non-Unix-like systems does not currently work. | |
520 ;; It needs to be reimplemented by modifying the parse-...-listing | |
521 ;; functions to convert the directory listing to ls -l format. | |
30459 | 522 ;; |
28210 | 523 ;; 13. The famous @ bug. As mentioned above in TIPS, ULTRIX marks symlinks |
524 ;; with a trailing @ in a ls -alF listing. In order to account for this | |
525 ;; ange-ftp looks to chop trailing @'s off of symlink names when it is | |
526 ;; parsing a listing with the F switch. This will cause ange-ftp to | |
527 ;; incorrectly get the name of a symlink on a non-ULTRIX host if its name | |
528 ;; ends in an @. ange-ftp will correct itself if you take F out of the | |
529 ;; dired ls switches (C-u s will allow you to edit the switches). The | |
530 ;; dired buffer will be automatically reverted, which will allow ange-ftp | |
531 ;; to fix its files hashtable. A cookie to anyone who can think of a | |
532 ;; fast, sure-fire way to recognize ULTRIX over ftp. | |
533 | |
534 ;; If you find any bugs or problems with this package, PLEASE either e-mail | |
535 ;; the above author, or send a message to the ange-ftp-lovers mailing list | |
536 ;; below. Ideas and constructive comments are especially welcome. | |
537 | |
538 ;; ange-ftp-lovers: | |
539 ;; | |
540 ;; ange-ftp has its own mailing list modestly called ange-ftp-lovers. All | |
541 ;; users of ange-ftp are welcome to subscribe (see below) and to discuss | |
542 ;; aspects of ange-ftp. New versions of ange-ftp are posted periodically to | |
543 ;; the mailing list. | |
544 | |
545 ;; To [un]subscribe to ange-ftp-lovers, or to report mailer problems with the | |
546 ;; list, please mail one of the following addresses: | |
547 ;; | |
46811
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
548 ;; ange-ftp-lovers-request@hplb.hpl.hp.com |
28210 | 549 ;; |
550 ;; Please don't forget the -request part. | |
551 ;; | |
552 ;; For mail to be posted directly to ange-ftp-lovers, send to one of the | |
553 ;; following addresses: | |
30459 | 554 ;; |
46811
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
555 ;; ange-ftp-lovers@hplb.hpl.hp.com |
28210 | 556 ;; |
557 ;; Alternatively, there is a mailing list that only gets announcements of new | |
558 ;; ange-ftp releases. This is called ange-ftp-lovers-announce, and can be | |
559 ;; subscribed to by e-mailing to the -request address as above. Please make | |
560 ;; it clear in the request which mailing list you wish to join. | |
561 | |
562 ;; ----------------------------------------------------------- | |
563 ;; Technical information on this package: | |
564 ;; ----------------------------------------------------------- | |
565 | |
566 ;; ange-ftp works by putting a handler on file-name-handler-alist | |
567 ;; which is called by many primitives, and a few non-primitives, | |
568 ;; whenever they see a file name of the appropriate sort. | |
569 | |
570 ;; Checklist for adding non-UNIX support for TYPE | |
30459 | 571 ;; |
28210 | 572 ;; The following functions may need TYPE versions: |
573 ;; (not all functions will be needed for every OS) | |
574 ;; | |
575 ;; ange-ftp-fix-name-for-TYPE | |
576 ;; ange-ftp-fix-dir-name-for-TYPE | |
577 ;; ange-ftp-TYPE-host | |
578 ;; ange-ftp-TYPE-add-host | |
579 ;; ange-ftp-parse-TYPE-listing | |
580 ;; ange-ftp-TYPE-delete-file-entry | |
581 ;; ange-ftp-TYPE-add-file-entry | |
582 ;; ange-ftp-TYPE-file-name-as-directory | |
583 ;; ange-ftp-TYPE-make-compressed-filename | |
584 ;; ange-ftp-TYPE-file-name-sans-versions | |
585 ;; | |
586 ;; Variables: | |
587 ;; | |
588 ;; ange-ftp-TYPE-host-regexp | |
589 ;; May need to add TYPE to ange-ftp-dumb-host-types | |
590 ;; | |
591 ;; Check the following functions for OS dependent coding: | |
592 ;; | |
593 ;; ange-ftp-host-type | |
594 ;; ange-ftp-guess-host-type | |
595 ;; ange-ftp-allow-child-lookup | |
596 | |
597 ;; Host type conventions: | |
598 ;; | |
599 ;; The function ange-ftp-host-type and the variable ange-ftp-dired-host-type | |
600 ;; (mostly) follow the following conventions for remote host types. At | |
601 ;; least, I think that future code should try to follow these conventions, | |
602 ;; and the current code should eventually be made compliant. | |
603 ;; | |
604 ;; nil = local host type, whatever that is (probably unix). | |
605 ;; Think nil as in "not a remote host". This value is used by | |
606 ;; ange-ftp-dired-host-type for local buffers. | |
607 ;; | |
608 ;; t = a remote host of unknown type. Think t as in true, it's remote. | |
609 ;; Currently, `unix' is used as the default remote host type. | |
610 ;; Maybe we should use t. | |
611 ;; | |
612 ;; TYPE = a remote host of TYPE type. | |
613 ;; | |
614 ;; TYPE:LIST = a remote host of TYPE type, using a specialized ftp listing | |
615 ;; program called list. This is currently only used for Unix | |
616 ;; dl (descriptive listings), when ange-ftp-dired-host-type | |
617 ;; is set to `unix:dl'. | |
618 | |
619 ;; Bug report codes: | |
620 ;; | |
621 ;; Because of their naive faith in this code, there are certain situations | |
622 ;; which the writers of this program believe could never happen. However, | |
623 ;; being realists they have put calls to `error' in the program at these | |
624 ;; points. These errors provide a code, which is an integer, greater than 1. | |
625 ;; To aid debugging. the error codes, and the functions in which they reside | |
626 ;; are listed below. | |
30459 | 627 ;; |
28210 | 628 ;; 1: See ange-ftp-ls |
629 ;; | |
630 | |
631 ;; ----------------------------------------------------------- | |
632 ;; Hall of fame: | |
633 ;; ----------------------------------------------------------- | |
30459 | 634 ;; |
28210 | 635 ;; Thanks to Roland McGrath for improving the filename syntax handling, |
636 ;; for suggesting many enhancements and for numerous cleanups to the code. | |
637 ;; | |
638 ;; Thanks to Jamie Zawinski for bugfixes and for ideas such as gateways. | |
639 ;; | |
640 ;; Thanks to Ken Laprade for improved .netrc parsing, password reading, and | |
641 ;; dired / shell auto-loading. | |
642 ;; | |
643 ;; Thanks to Sebastian Kremer for dired support and for many ideas and | |
644 ;; bugfixes. | |
645 ;; | |
646 ;; Thanks to Joe Wells for bugfixes, the original non-UNIX system support, | |
647 ;; VOS support, and hostname completion. | |
648 ;; | |
649 ;; Thanks to Nakagawa Takayuki for many good ideas, filename-completion, help | |
650 ;; with file-name expansion, efficiency worries, stylistic concerns and many | |
651 ;; bugfixes. | |
652 ;; | |
653 ;; Thanks to Sandy Rutherford who re-wrote most of ange-ftp to support VMS, | |
654 ;; MTS, CMS and UNIX-dls. Sandy also added dired-support for non-UNIX OS and | |
655 ;; auto-recognition of the host type. | |
656 ;; | |
657 ;; Thanks to Dave Smith who wrote the info file for ange-ftp. | |
658 ;; | |
659 ;; Finally, thanks to Keith Waclena, Mark D. Baushke, Terence Kelleher, Ping | |
660 ;; Zhou, Edward Vielmetti, Jack Repenning, Mike Balenger, Todd Kaufmann, | |
661 ;; Kjetil Svarstad, Tom Wurgler, Linus Tolke, Niko Makila, Carl Edman, Bill | |
662 ;; Trost, Dave Brennan, Dan Jacobson, Andy Scott, Steve Anderson, Sanjay | |
663 ;; Mathur, the folks on the ange-ftp-lovers mailing list and many others | |
664 ;; whose names I've forgotten who have helped to debug and fix problems with | |
665 ;; ange-ftp.el. | |
666 | |
667 ;;; Code: | |
668 | |
669 (require 'comint) | |
670 | |
671 ;;;; ------------------------------------------------------------ | |
672 ;;;; User customization variables. | |
673 ;;;; ------------------------------------------------------------ | |
674 | |
675 (defgroup ange-ftp nil | |
30459 | 676 "Accessing remote files and directories using FTP |
28210 | 677 made as simple and transparent as possible." |
678 :group 'files | |
679 :prefix "ange-ftp-") | |
680 | |
681 (defcustom ange-ftp-name-format | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
682 '("\\`/\\(\\([^/:]*\\)@\\)?\\([^@/:]*[^@/:.]\\):\\(.*\\)" . (3 2 4)) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
683 "Format of a fully expanded remote file name. |
28210 | 684 |
685 This is a list of the form \(REGEXP HOST USER NAME\), | |
686 where REGEXP is a regular expression matching | |
687 the full remote name, and HOST, USER, and NAME are the numbers of | |
688 parenthesized expressions in REGEXP for the components (in that order)." | |
689 :group 'ange-ftp | |
53388
29c86aab2fa2
(ange-ftp-name-format): Allow USER to contain
Eli Zaretskii <eliz@is.elta.co.il>
parents:
53351
diff
changeset
|
690 :type '(list (regexp :tag "Name regexp") |
28210 | 691 (integer :tag "Host group") |
692 (integer :tag "User group") | |
693 (integer :tag "Name group"))) | |
694 | |
695 ;; ange-ftp-multi-skip-msgs should only match ###-, where ### is one of | |
696 ;; the number codes corresponding to ange-ftp-good-msgs or ange-ftp-fatal-msgs. | |
697 ;; Otherwise, ange-ftp will go into multi-skip mode, and never come out. | |
698 | |
699 (defvar ange-ftp-multi-msgs | |
102443
07f9480f83e6
(ange-ftp-multi-msgs): Add 150-.
Andreas Schwab <schwab@linux-m68k.org>
parents:
102225
diff
changeset
|
700 "^150-\\|^220-\\|^230-\\|^226\\|^25.-\\|^221-\\|^200-\\|^331-\\|^4[25]1-\\|^530-" |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
701 "*Regular expression matching the start of a multiline FTP reply.") |
28210 | 702 |
703 (defvar ange-ftp-good-msgs | |
704 "^220 \\|^230 \\|^226 \\|^25. \\|^221 \\|^200 \\|^[Hh]ash mark" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
705 "*Regular expression matching FTP \"success\" messages.") |
28210 | 706 |
707 ;; CMS and the odd VMS machine say 200 Port rather than 200 PORT. | |
708 ;; Also CMS machines use a multiline 550- reply to say that you | |
709 ;; don't have write permission. ange-ftp gets into multi-line skip | |
710 ;; mode and hangs. Have it ignore 550- instead. It will then barf | |
711 ;; when it gets the 550 line, as it should. | |
712 | |
28892
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
713 ;; RFC2228 "FTP Security Extensions" defines extensions to the FTP |
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
714 ;; protocol which involve the client requesting particular |
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
715 ;; authentication methods (typically) at connection establishment. Non |
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
716 ;; security-aware FTP servers should respond to this with a 500 code, |
19ae39682b38
(ange-ftp-skip-msgs): Include 500 code.for
Gerd Moellmann <gerd@gnu.org>
parents:
28210
diff
changeset
|
717 ;; which we ignore. |
28210 | 718 (defcustom ange-ftp-skip-msgs |
719 (concat "^200 \\(PORT\\|Port\\) \\|^331 \\|^150 \\|^350 \\|^[0-9]+ bytes \\|" | |
720 "^Connected \\|^$\\|^Remote system\\|^Using\\|^ \\|Password:\\|" | |
721 "^Data connection \\|" | |
722 "^local:\\|^Trying\\|^125 \\|^550-\\|^221 .*oodbye\\|" | |
107072
abe576120f76
* net/ange-ftp.el (ange-ftp-skip-msgs): Ignore all ""^500 .*AUTH"
Michael Albinus <michael.albinus@gmx.de>
parents:
107040
diff
changeset
|
723 "^500 .*AUTH\\|^KERBEROS\\|" |
47068
9026b0749c9e
(ange-ftp-skip-msgs): Skip the 530 response
Richard M. Stallman <rms@gnu.org>
parents:
46892
diff
changeset
|
724 "^530 Please login with USER and PASS\\|" ; non kerberised vsFTPd |
102715
55824e6d083c
* net/ange-ftp.el (ange-ftp-skip-msgs): Add 534.
Michael Albinus <michael.albinus@gmx.de>
parents:
102443
diff
changeset
|
725 "^534 Kerberos Authentication not enabled\\|" |
39533
75cd77e6f1d5
(ange-ftp-skip-msgs): Add 227 and 228 for Long
Andreas Schwab <schwab@suse.de>
parents:
38412
diff
changeset
|
726 "^22[789] .*[Pp]assive\\|^200 EPRT\\|^500 .*EPRT") |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
727 "Regular expression matching FTP messages that can be ignored." |
28210 | 728 :group 'ange-ftp |
729 :type 'regexp) | |
730 | |
731 (defcustom ange-ftp-fatal-msgs | |
732 (concat "^ftp: \\|^Not connected\\|^530 \\|^4[25]1 \\|rcmd: \\|" | |
733 "^No control connection\\|unknown host\\|^lost connection") | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
734 "Regular expression matching FTP messages that indicate serious errors. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
735 |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
736 These mean that the FTP process should be (or already has been) killed." |
28210 | 737 :group 'ange-ftp |
738 :type 'regexp) | |
739 | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
740 (defcustom ange-ftp-potential-error-msgs |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
741 ;; On Mac OS X we sometimes get things like: |
64701
34bd8e434dd7
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64667
diff
changeset
|
742 ;; |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
743 ;; ftp> open ftp.nluug.nl |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
744 ;; Trying 2001:610:1:80aa:192:87:102:36... |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
745 ;; ftp: connect to address 2001:610:1:80aa:192:87:102:36: No route to host |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
746 ;; Trying 192.87.102.36... |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
747 ;; Connected to ftp.nluug.nl. |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
748 "^ftp: connect to address .*: No route to host" |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
749 "Regular expression matching FTP messages that can indicate serious errors. |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
750 These mean that something went wrong, but they may be followed by more |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
751 messages indicating that the error was somehow corrected." |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
752 :group 'ange-ftp |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
753 :type 'regexp) |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
754 |
28210 | 755 (defcustom ange-ftp-gateway-fatal-msgs |
756 "No route to host\\|Connection closed\\|No such host\\|Login incorrect" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
757 "Regular expression matching login failure messages from rlogin/telnet." |
28210 | 758 :group 'ange-ftp |
759 :type 'regexp) | |
760 | |
761 (defcustom ange-ftp-xfer-size-msgs | |
762 "^150 .* connection for .* (\\([0-9]+\\) bytes)" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
763 "Regular expression used to determine the number of bytes in a FTP transfer." |
28210 | 764 :group 'ange-ftp |
765 :type 'regexp) | |
766 | |
30459 | 767 (defcustom ange-ftp-tmp-name-template |
28210 | 768 (expand-file-name "ange-ftp" temporary-file-directory) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
769 "Template used to create temporary files." |
28210 | 770 :group 'ange-ftp |
771 :type 'directory) | |
772 | |
773 (defcustom ange-ftp-gateway-tmp-name-template "/tmp/ange-ftp" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
774 "Template used to create temporary files when FTP-ing through a gateway. |
28210 | 775 |
776 Files starting with this prefix need to be accessible from BOTH the local | |
777 machine and the gateway machine, and need to have the SAME name on both | |
778 machines, that is, /tmp is probably NOT what you want, since that is rarely | |
779 cross-mounted." | |
780 :group 'ange-ftp | |
781 :type 'directory) | |
782 | |
783 (defcustom ange-ftp-netrc-filename "~/.netrc" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
784 "File in .netrc format to search for passwords." |
28210 | 785 :group 'ange-ftp |
786 :type 'file) | |
787 | |
788 (defcustom ange-ftp-disable-netrc-security-check (eq system-type 'windows-nt) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
789 "If non-nil avoid checking permissions on the .netrc file." |
28210 | 790 :group 'ange-ftp |
791 :type 'boolean) | |
792 | |
793 (defcustom ange-ftp-default-user nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
794 "User name to use when none is specified in a file name. |
28210 | 795 |
796 If non-nil but not a string, you are prompted for the name. | |
797 If nil, the value of `ange-ftp-netrc-default-user' is used. | |
798 If that is nil too, then your login name is used. | |
799 | |
800 Once a connection to a given host has been initiated, the user name | |
801 and password information for that host are cached and re-used by | |
802 ange-ftp. Use \\[ange-ftp-set-user] to change the cached values, | |
803 since setting `ange-ftp-default-user' directly does not affect | |
804 the cached information." | |
805 :group 'ange-ftp | |
806 :type '(choice (const :tag "Default" nil) | |
807 string | |
808 (other :tag "Prompt" t))) | |
809 | |
810 (defcustom ange-ftp-netrc-default-user nil | |
811 "Alternate default user name to use when none is specified. | |
812 | |
813 This variable is set from the `default' command in your `.netrc' file, | |
814 if there is one." | |
815 :group 'ange-ftp | |
816 :type '(choice (const :tag "Default" nil) | |
817 string)) | |
818 | |
819 (defcustom ange-ftp-default-password nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
820 "Password to use when the user name equals `ange-ftp-default-user'." |
28210 | 821 :group 'ange-ftp |
822 :type '(choice (const :tag "Default" nil) | |
823 string)) | |
824 | |
825 (defcustom ange-ftp-default-account nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
826 "Account to use when the user name equals `ange-ftp-default-user'." |
28210 | 827 :group 'ange-ftp |
828 :type '(choice (const :tag "Default" nil) | |
829 string)) | |
830 | |
831 (defcustom ange-ftp-netrc-default-password nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
832 "Password to use when the user name equals `ange-ftp-netrc-default-user'." |
28210 | 833 :group 'ange-ftp |
834 :type '(choice (const :tag "Default" nil) | |
835 string)) | |
836 | |
837 (defcustom ange-ftp-netrc-default-account nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
838 "Account to use when the user name equals `ange-ftp-netrc-default-user'." |
28210 | 839 :group 'ange-ftp |
840 :type '(choice (const :tag "Default" nil) | |
841 string)) | |
842 | |
843 (defcustom ange-ftp-generate-anonymous-password t | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
844 "If t, use value of `user-mail-address' as password for anonymous FTP. |
28210 | 845 |
846 If a string, then use that string as the password. | |
847 If nil, prompt the user for a password." | |
848 :group 'ange-ftp | |
849 :type '(choice (const :tag "Prompt" nil) | |
850 string | |
851 (other :tag "User address" t))) | |
852 | |
853 (defcustom ange-ftp-dumb-unix-host-regexp nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
854 "If non-nil, regexp matching hosts on which `dir' command lists directory." |
28210 | 855 :group 'ange-ftp |
856 :type '(choice (const :tag "Default" nil) | |
857 string)) | |
858 | |
859 (defcustom ange-ftp-binary-file-name-regexp | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
860 (concat "TAGS\\'\\|\\.\\(?:" |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
861 (eval-when-compile |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
862 (regexp-opt '("z" "Z" "lzh" "arc" "zip" "zoo" "tar" "dvi" |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
863 "ps" "elc" "gif" "gz" "taz" "tgz"))) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
864 "\\|EXE\\(;[0-9]+\\)?\\|[zZ]-part-..\\)\\'") |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
865 "If a file matches this regexp then it is transferred in binary mode." |
28210 | 866 :group 'ange-ftp |
867 :type 'regexp) | |
868 | |
869 (defcustom ange-ftp-gateway-host nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
870 "Name of host to use as gateway machine when local FTP isn't possible." |
28210 | 871 :group 'ange-ftp |
872 :type '(choice (const :tag "Default" nil) | |
873 string)) | |
874 | |
875 (defcustom ange-ftp-local-host-regexp ".*" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
876 "Regexp selecting hosts which can be reached directly with FTP. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
877 |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
878 For other hosts the FTP process is started on `ange-ftp-gateway-host' |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
879 instead, and/or reached via `ange-ftp-gateway-ftp-program-name'." |
28210 | 880 :group 'ange-ftp |
881 :type 'regexp) | |
882 | |
883 (defcustom ange-ftp-gateway-program-interactive nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
884 "If non-nil then the gateway program should give a shell prompt. |
28210 | 885 |
886 Both telnet and rlogin do something like this." | |
887 :group 'ange-ftp | |
888 :type 'boolean) | |
889 | |
890 (defcustom ange-ftp-gateway-program remote-shell-program | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
891 "Name of program to spawn a shell on the gateway machine. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
892 |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
893 Valid candidates are rsh (remsh on some systems), telnet and rlogin. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
894 See also the gateway variable above." |
28210 | 895 :group 'ange-ftp |
896 :type '(choice (const "rsh") | |
897 (const "telnet") | |
898 (const "rlogin") | |
899 string)) | |
900 | |
901 (defcustom ange-ftp-gateway-prompt-pattern "^[^#$%>;\n]*[#$%>;] *" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
902 "Regexp matching prompt after complete login sequence on gateway machine. |
28210 | 903 |
904 A match for this means the shell is now awaiting input. Make this regexp as | |
905 strict as possible; it shouldn't match *anything* at all except the user's | |
906 initial prompt. The above string will fail under most SUN-3's since it | |
907 matches the login banner." | |
908 :group 'ange-ftp | |
909 :type 'regexp) | |
910 | |
911 (defvar ange-ftp-gateway-setup-term-command | |
912 (if (eq system-type 'hpux) | |
913 "stty -onlcr -echo\n" | |
914 "stty -echo nl\n") | |
915 "*Set up terminal after logging in to the gateway machine. | |
916 This command should stop the terminal from echoing each command, and | |
917 arrange to strip out trailing ^M characters.") | |
918 | |
919 (defcustom ange-ftp-smart-gateway nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
920 "Non-nil says the FTP gateway (proxy) or gateway FTP program is smart. |
28210 | 921 |
922 Don't bother telnetting, etc., already connected to desired host transparently, | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
923 or just issue a user@host command in case `ange-ftp-gateway-host' is non-nil. |
46811
98f32ab61c61
(ange-ftp-smart-gateway): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
46355
diff
changeset
|
924 See also `ange-ftp-smart-gateway-port'." |
28210 | 925 :group 'ange-ftp |
926 :type 'boolean) | |
927 | |
928 (defcustom ange-ftp-smart-gateway-port "21" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
929 "Port on gateway machine to use when smart gateway is in operation." |
28210 | 930 :group 'ange-ftp |
931 :type 'string) | |
932 | |
933 (defcustom ange-ftp-send-hash t | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
934 "If non-nil, send the HASH command to the FTP client." |
28210 | 935 :group 'ange-ftp |
936 :type 'boolean) | |
937 | |
938 (defcustom ange-ftp-binary-hash-mark-size nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
939 "Default size, in bytes, between hash-marks when transferring a binary file. |
28210 | 940 If nil, this variable will be locally overridden if the FTP client outputs a |
941 suitable response to the HASH command. If non-nil, this value takes | |
942 precedence over the local value." | |
943 :group 'ange-ftp | |
944 :type '(choice (const :tag "Overridden" nil) | |
945 integer)) | |
946 | |
947 (defcustom ange-ftp-ascii-hash-mark-size 1024 | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
948 "Default size, in bytes, between hash-marks when transferring an ASCII file. |
28210 | 949 This variable is buffer-local and will be locally overridden if the FTP client |
950 outputs a suitable response to the HASH command." | |
951 :group 'ange-ftp | |
952 :type 'integer) | |
953 | |
954 (defcustom ange-ftp-process-verbose t | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
955 "If non-nil then be chatty about interaction with the FTP process." |
28210 | 956 :group 'ange-ftp |
957 :type 'boolean) | |
958 | |
959 (defcustom ange-ftp-ftp-program-name "ftp" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
960 "Name of FTP program to run." |
28210 | 961 :group 'ange-ftp |
962 :type 'string) | |
963 | |
964 (defcustom ange-ftp-gateway-ftp-program-name "ftp" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
965 "Name of FTP program to run when accessing non-local hosts. |
28210 | 966 |
967 Some AT&T folks claim to use something called `pftp' here." | |
968 :group 'ange-ftp | |
969 :type 'string) | |
970 | |
971 (defcustom ange-ftp-ftp-program-args '("-i" "-n" "-g" "-v") | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
972 "A list of arguments passed to the FTP program when started." |
28210 | 973 :group 'ange-ftp |
974 :type '(repeat string)) | |
975 | |
976 (defcustom ange-ftp-nslookup-program nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
977 "If non-nil, this is a string naming the nslookup program." |
28210 | 978 :group 'ange-ftp |
979 :type '(choice (const :tag "None" nil) | |
980 string)) | |
981 | |
982 (defcustom ange-ftp-make-backup-files () | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
983 "Non-nil means make backup files for \"magic\" remote files." |
28210 | 984 :group 'ange-ftp |
985 :type 'boolean) | |
986 | |
987 (defcustom ange-ftp-retry-time 5 | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
988 "Number of seconds to wait before retry if file or listing doesn't arrive. |
28210 | 989 This might need to be increased for very slow connections." |
990 :group 'ange-ftp | |
991 :type 'integer) | |
992 | |
993 (defcustom ange-ftp-auto-save 0 | |
994 "If 1, allow ange-ftp files to be auto-saved. | |
995 If 0, inhibit auto-saving of ange-ftp files. | |
996 Don't use any other value." | |
997 :group 'ange-ftp | |
998 :type '(choice (const :tag "Suppress" 0) | |
999 (const :tag "Allow" 1))) | |
1000 | |
1001 (defcustom ange-ftp-try-passive-mode nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1002 "If t, try to use passive mode in FTP, if the client program supports it." |
28210 | 1003 :group 'ange-ftp |
1004 :type 'boolean | |
45260 | 1005 :version "21.1") |
28210 | 1006 |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1007 (defcustom ange-ftp-passive-host-alist nil |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1008 "Alist of FTP servers that need \"passive\" mode. |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1009 Each element is of the form (HOSTNAME . SETTING). |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1010 HOSTNAME is a regular expression to match the FTP server host name(s). |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1011 SETTING is \"on\" to turn passive mode on, \"off\" to turn it off, |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1012 or nil meaning don't change it." |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
1013 :group 'ange-ftp |
44953
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
1014 :type '(repeat (cons regexp (choice (const :tag "On" "on") |
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
1015 (const :tag "Off" "off") |
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
1016 (const :tag "Don't change" nil)))) |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
57426
diff
changeset
|
1017 :version "22.1") |
28210 | 1018 |
1019 ;;;; ------------------------------------------------------------ | |
1020 ;;;; Hash table support. | |
1021 ;;;; ------------------------------------------------------------ | |
1022 | |
1023 (require 'backquote) | |
1024 | |
1025 (defun ange-ftp-hash-entry-exists-p (key tbl) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1026 "Return whether there is an association for KEY in table TBL." |
56742
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
1027 (and tbl (not (eq (gethash key tbl 'unknown) 'unknown)))) |
28210 | 1028 |
1029 (defun ange-ftp-hash-table-keys (tbl) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1030 "Return a sorted list of all the active keys in table TBL, as strings." |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1031 ;; (let ((keys nil)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1032 ;; (maphash (lambda (k v) (push k keys)) tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1033 ;; (sort keys 'string-lessp)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1034 (sort (all-completions "" tbl) 'string-lessp)) |
28210 | 1035 |
1036 ;;;; ------------------------------------------------------------ | |
1037 ;;;; Internal variables. | |
1038 ;;;; ------------------------------------------------------------ | |
1039 | |
1040 (defvar ange-ftp-data-buffer-name " *ftp data*" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1041 "Buffer name to hold directory listing data received from FTP process.") |
28210 | 1042 |
1043 (defvar ange-ftp-netrc-modtime nil | |
1044 "Last modified time of the netrc file from file-attributes.") | |
1045 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1046 (defvar ange-ftp-user-hashtable (make-hash-table :test 'equal) |
28210 | 1047 "Hash table holding associations between HOST, USER pairs.") |
1048 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1049 (defvar ange-ftp-passwd-hashtable (make-hash-table :test 'equal) |
28210 | 1050 "Mapping between a HOST, USER pair and a PASSWORD for them. |
1051 All HOST values should be in lower case.") | |
1052 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1053 (defvar ange-ftp-account-hashtable (make-hash-table :test 'equal) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1054 "Mapping between a HOST, USER pair and an ACCOUNT password for them.") |
28210 | 1055 |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1056 (defvar ange-ftp-files-hashtable (make-hash-table :test 'equal :size 97) |
28210 | 1057 "Hash table for storing directories and their respective files.") |
1058 | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1059 (defvar ange-ftp-inodes-hashtable (make-hash-table :test 'equal :size 97) |
28210 | 1060 "Hash table for storing file names and their \"inode numbers\".") |
1061 | |
1062 (defvar ange-ftp-next-inode-number 1 | |
1063 "Next \"inode number\" value. We give each file name a unique number.") | |
1064 | |
1065 (defvar ange-ftp-ls-cache-lsargs nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1066 "Last set of args used by `ange-ftp-ls'.") |
28210 | 1067 |
1068 (defvar ange-ftp-ls-cache-file nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1069 "Last file passed to `ange-ftp-ls'.") |
28210 | 1070 |
1071 (defvar ange-ftp-ls-cache-res nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1072 "Last result returned from `ange-ftp-ls'.") |
28210 | 1073 |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1074 (defconst ange-ftp-expand-dir-hashtable (make-hash-table :test 'equal)) |
28210 | 1075 |
1076 (defconst ange-ftp-expand-dir-regexp "^5.0 \\([^: ]+\\):") | |
1077 | |
1078 ;; These are local variables in each FTP process buffer. | |
1079 (defvar ange-ftp-hash-mark-unit nil) | |
1080 (defvar ange-ftp-hash-mark-count nil) | |
1081 (defvar ange-ftp-xfer-size nil) | |
1082 (defvar ange-ftp-process-string nil) | |
1083 (defvar ange-ftp-process-result-line nil) | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1084 (defvar ange-ftp-pending-error-line nil) |
28210 | 1085 (defvar ange-ftp-process-busy nil) |
1086 (defvar ange-ftp-process-result nil) | |
1087 (defvar ange-ftp-process-multi-skip nil) | |
1088 (defvar ange-ftp-process-msg nil) | |
1089 (defvar ange-ftp-process-continue nil) | |
1090 (defvar ange-ftp-last-percent nil) | |
1091 | |
1092 ;; These variables are bound by one function and examined by another. | |
1093 ;; Leave them void globally for error checking. | |
1094 (defvar ange-ftp-this-file) | |
1095 (defvar ange-ftp-this-dir) | |
1096 (defvar ange-ftp-this-user) | |
1097 (defvar ange-ftp-this-host) | |
1098 (defvar ange-ftp-this-msg) | |
1099 (defvar ange-ftp-completion-ignored-pattern) | |
1100 (defvar ange-ftp-trample-marker) | |
1101 | |
1102 ;; New error symbols. | |
1103 (put 'ftp-error 'error-conditions '(ftp-error file-error error)) | |
1104 ;; (put 'ftp-error 'error-message "FTP error") | |
1105 | |
1106 ;;; ------------------------------------------------------------ | |
1107 ;;; Enhanced message support. | |
1108 ;;; ------------------------------------------------------------ | |
1109 | |
1110 (defun ange-ftp-message (fmt &rest args) | |
1111 "Display message in echo area, but indicate if truncated. | |
1112 Args are as in `message': a format string, plus arguments to be formatted." | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1113 (let ((msg (apply 'format fmt args)) |
28210 | 1114 (max (window-width (minibuffer-window)))) |
1115 (if noninteractive | |
1116 msg | |
1117 (if (>= (length msg) max) | |
1118 ;; Take just the last MAX - 3 chars of the string. | |
1119 (setq msg (concat "> " (substring msg (- 3 max))))) | |
1120 (message "%s" msg)))) | |
1121 | |
1122 (defun ange-ftp-abbreviate-filename (file &optional new) | |
30459 | 1123 "Abbreviate the file name FILE relative to the `default-directory'. |
28210 | 1124 If the optional parameter NEW is given and the non-directory parts match, |
1125 only return the directory part of FILE." | |
1126 (save-match-data | |
1127 (if (and default-directory | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
1128 (string-match (concat "\\`" |
28210 | 1129 (regexp-quote default-directory) |
1130 ".") file)) | |
1131 (setq file (substring file (1- (match-end 0))))) | |
1132 (if (and new | |
1133 (string-equal (file-name-nondirectory file) | |
1134 (file-name-nondirectory new))) | |
1135 (setq file (file-name-directory file))) | |
1136 (or file "./"))) | |
1137 | |
1138 ;;;; ------------------------------------------------------------ | |
1139 ;;;; User / Host mapping support. | |
1140 ;;;; ------------------------------------------------------------ | |
1141 | |
1142 (defun ange-ftp-set-user (host user) | |
1143 "For a given HOST, set or change the default USER." | |
1144 (interactive "sHost: \nsUser: ") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1145 (puthash host user ange-ftp-user-hashtable)) |
28210 | 1146 |
1147 (defun ange-ftp-get-user (host) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1148 "Given a HOST, return the default user." |
28210 | 1149 (ange-ftp-parse-netrc) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1150 (let ((user (gethash host ange-ftp-user-hashtable))) |
28210 | 1151 (or user |
1152 (prog1 | |
1153 (setq user | |
1154 (cond ((stringp ange-ftp-default-user) | |
1155 ;; We have a default name. Use it. | |
1156 ange-ftp-default-user) | |
1157 (ange-ftp-default-user | |
1158 ;; Ask the user. | |
1159 (let ((enable-recursive-minibuffers t)) | |
1160 (read-string (format "User for %s: " host) | |
1161 (user-login-name)))) | |
1162 (ange-ftp-netrc-default-user) | |
1163 ;; Default to the user's login name. | |
1164 (t | |
1165 (user-login-name)))) | |
1166 (ange-ftp-set-user host user))))) | |
1167 | |
1168 ;;;; ------------------------------------------------------------ | |
1169 ;;;; Password support. | |
1170 ;;;; ------------------------------------------------------------ | |
1171 | |
1172 (defmacro ange-ftp-generate-passwd-key (host user) | |
105382
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
1173 `(and (stringp ,host) (stringp ,user) (concat (downcase ,host) "/" ,user))) |
28210 | 1174 |
1175 (defmacro ange-ftp-lookup-passwd (host user) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1176 `(gethash (ange-ftp-generate-passwd-key ,host ,user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1177 ange-ftp-passwd-hashtable)) |
28210 | 1178 |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1179 (defun ange-ftp-set-passwd (host user password) |
28210 | 1180 "For a given HOST and USER, set or change the associated PASSWORD." |
1181 (interactive (list (read-string "Host: ") | |
1182 (read-string "User: ") | |
1183 (read-passwd "Password: "))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1184 (puthash (ange-ftp-generate-passwd-key host user) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1185 password ange-ftp-passwd-hashtable)) |
28210 | 1186 |
1187 (defun ange-ftp-get-host-with-passwd (user) | |
1188 "Given a USER, return a host we know the password for." | |
1189 (ange-ftp-parse-netrc) | |
1190 (catch 'found-one | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1191 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1192 (lambda (host val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1193 (if (ange-ftp-lookup-passwd host user) (throw 'found-one host))) |
28210 | 1194 ange-ftp-user-hashtable) |
1195 (save-match-data | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1196 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1197 (lambda (key value) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
1198 (if (string-match "\\`[^/]*\\(/\\).*\\'" key) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1199 (let ((host (substring key 0 (match-beginning 1)))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1200 (if (and (string-equal user (substring key (match-end 1))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1201 value) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1202 (throw 'found-one host))))) |
28210 | 1203 ange-ftp-passwd-hashtable)) |
1204 nil)) | |
1205 | |
1206 (defun ange-ftp-get-passwd (host user) | |
1207 "Return the password for specified HOST and USER, asking user if necessary." | |
1208 (ange-ftp-parse-netrc) | |
1209 | |
1210 ;; look up password in the hash table first; user might have overridden the | |
1211 ;; defaults. | |
1212 (cond ((ange-ftp-lookup-passwd host user)) | |
30459 | 1213 |
28210 | 1214 ;; See if default user and password set. |
1215 ((and (stringp ange-ftp-default-user) | |
1216 ange-ftp-default-password | |
1217 (string-equal user ange-ftp-default-user)) | |
1218 ange-ftp-default-password) | |
30459 | 1219 |
28210 | 1220 ;; See if default user and password set from .netrc file. |
1221 ((and (stringp ange-ftp-netrc-default-user) | |
1222 ange-ftp-netrc-default-password | |
1223 (string-equal user ange-ftp-netrc-default-user)) | |
1224 ange-ftp-netrc-default-password) | |
30459 | 1225 |
28210 | 1226 ;; anonymous ftp password is handled specially since there is an |
1227 ;; unwritten rule about how that is used on the Internet. | |
1228 ((and (or (string-equal user "anonymous") | |
1229 (string-equal user "ftp")) | |
1230 ange-ftp-generate-anonymous-password) | |
1231 (if (stringp ange-ftp-generate-anonymous-password) | |
1232 ange-ftp-generate-anonymous-password | |
1233 user-mail-address)) | |
30459 | 1234 |
28210 | 1235 ;; see if same user has logged in to other hosts; if so then prompt |
1236 ;; with the password that was used there. | |
1237 (t | |
1238 (let* ((other (ange-ftp-get-host-with-passwd user)) | |
1239 (passwd (if other | |
30459 | 1240 |
28210 | 1241 ;; found another machine with the same user. |
1242 ;; Try that account. | |
1243 (read-passwd | |
1244 (format "passwd for %s@%s (default same as %s@%s): " | |
1245 user host user other) | |
1246 nil | |
1247 (ange-ftp-lookup-passwd other user)) | |
30459 | 1248 |
28210 | 1249 ;; I give up. Ask the user for the password. |
1250 (read-passwd | |
1251 (format "Password for %s@%s: " user host))))) | |
1252 (ange-ftp-set-passwd host user passwd) | |
1253 passwd)))) | |
1254 | |
1255 ;;;; ------------------------------------------------------------ | |
1256 ;;;; Account support | |
1257 ;;;; ------------------------------------------------------------ | |
1258 | |
1259 ;; Account passwords must be either specified in the .netrc file, or set | |
1260 ;; manually by calling ange-ftp-set-account. For the moment, ange-ftp doesn't | |
1261 ;; check to see whether the FTP process is actually prompting for an account | |
1262 ;; password. | |
30459 | 1263 |
28210 | 1264 (defun ange-ftp-set-account (host user account) |
1265 "For a given HOST and USER, set or change the associated ACCOUNT password." | |
1266 (interactive (list (read-string "Host: ") | |
1267 (read-string "User: ") | |
1268 (read-passwd "Account password: "))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1269 (puthash (ange-ftp-generate-passwd-key host user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1270 account ange-ftp-account-hashtable)) |
28210 | 1271 |
1272 (defun ange-ftp-get-account (host user) | |
1273 "Given a HOST and USER, return the FTP account." | |
1274 (ange-ftp-parse-netrc) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1275 (or (gethash (ange-ftp-generate-passwd-key host user) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1276 ange-ftp-account-hashtable) |
28210 | 1277 (and (stringp ange-ftp-default-user) |
1278 (string-equal user ange-ftp-default-user) | |
1279 ange-ftp-default-account) | |
1280 (and (stringp ange-ftp-netrc-default-user) | |
1281 (string-equal user ange-ftp-netrc-default-user) | |
1282 ange-ftp-netrc-default-account))) | |
1283 | |
1284 ;;;; ------------------------------------------------------------ | |
1285 ;;;; ~/.netrc support | |
1286 ;;;; ------------------------------------------------------------ | |
1287 | |
1288 (defun ange-ftp-chase-symlinks (file) | |
1289 "Return the filename that FILE references, following all symbolic links." | |
1290 (let (temp) | |
1291 (while (setq temp (ange-ftp-real-file-symlink-p file)) | |
1292 (setq file | |
1293 (if (file-name-absolute-p temp) | |
1294 temp | |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
1295 ;; Wouldn't `expand-file-name' be better than `concat' ? |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
1296 ;; It would fail when `a/b/..' != `a', tho. --Stef |
28210 | 1297 (concat (file-name-directory file) temp))))) |
1298 file) | |
1299 | |
1300 ;; Move along current line looking for the value of the TOKEN. | |
1301 ;; Valid separators between TOKEN and its value are commas and | |
1302 ;; whitespace. Second arg LIMIT is a limit for the search. | |
1303 | |
1304 (defun ange-ftp-parse-netrc-token (token limit) | |
1305 (if (search-forward token limit t) | |
1306 (let (beg) | |
1307 (skip-chars-forward ", \t\r\n" limit) | |
1308 (if (eq (following-char) ?\") ;quoted token value | |
1309 (progn (forward-char 1) | |
1310 (setq beg (point)) | |
1311 (skip-chars-forward "^\"" limit) | |
1312 (forward-char 1) | |
1313 (buffer-substring beg (1- (point)))) | |
1314 (setq beg (point)) | |
1315 (skip-chars-forward "^, \t\r\n" limit) | |
1316 (buffer-substring beg (point)))))) | |
1317 | |
1318 ;; Extract the values for the tokens `machine', `login', | |
1319 ;; `password' and `account' in the current buffer. If successful, | |
1320 ;; record the information found. | |
1321 | |
1322 (defun ange-ftp-parse-netrc-group () | |
1323 (let ((start (point)) | |
1324 (end (save-excursion | |
1325 (if (looking-at "machine\\>") | |
1326 ;; Skip `machine' and the machine name that follows. | |
1327 (progn | |
1328 (skip-chars-forward "^ \t\r\n") | |
1329 (skip-chars-forward " \t\r\n") | |
1330 (skip-chars-forward "^ \t\r\n")) | |
1331 ;; Skip `default'. | |
1332 (skip-chars-forward "^ \t\r\n")) | |
1333 ;; Find start of the next `machine' or `default' | |
1334 ;; or the end of the buffer. | |
1335 (if (re-search-forward "machine\\>\\|default\\>" nil t) | |
1336 (match-beginning 0) | |
1337 (point-max)))) | |
1338 machine login password account) | |
1339 (setq machine (ange-ftp-parse-netrc-token "machine" end) | |
1340 login (ange-ftp-parse-netrc-token "login" end) | |
1341 password (ange-ftp-parse-netrc-token "password" end) | |
1342 account (ange-ftp-parse-netrc-token "account" end)) | |
1343 (if (and machine login) | |
1344 ;; found a `machine` token. | |
1345 (progn | |
1346 (ange-ftp-set-user machine login) | |
1347 (ange-ftp-set-passwd machine login password) | |
1348 (and account | |
1349 (ange-ftp-set-account machine login account))) | |
1350 (goto-char start) | |
1351 (if (search-forward "default" end t) | |
1352 ;; found a `default' token | |
1353 (progn | |
1354 (setq login (ange-ftp-parse-netrc-token "login" end) | |
1355 password (ange-ftp-parse-netrc-token "password" end) | |
1356 account (ange-ftp-parse-netrc-token "account" end)) | |
1357 (and login | |
1358 (setq ange-ftp-netrc-default-user login)) | |
1359 (and password | |
1360 (setq ange-ftp-netrc-default-password password)) | |
1361 (and account | |
1362 (setq ange-ftp-netrc-default-account account))))) | |
1363 (goto-char end))) | |
1364 | |
1365 ;; Read in ~/.netrc, if one exists. If ~/.netrc file exists and has | |
1366 ;; the correct permissions then extract the \`machine\', \`login\', | |
1367 ;; \`password\' and \`account\' information from within. | |
1368 | |
1369 (defun ange-ftp-parse-netrc () | |
1370 ;; We set this before actually doing it to avoid the possibility | |
1371 ;; of an infinite loop if ange-ftp-netrc-filename is an FTP file. | |
1372 (interactive) | |
1373 (let (file attr) | |
1374 (let ((default-directory "/")) | |
1375 (setq file (ange-ftp-chase-symlinks | |
1376 (ange-ftp-real-expand-file-name ange-ftp-netrc-filename))) | |
1377 (setq attr (ange-ftp-real-file-attributes file))) | |
1378 (if (and attr ; file exists. | |
1379 (not (equal (nth 5 attr) ange-ftp-netrc-modtime))) ; file changed | |
1380 (save-match-data | |
1381 (if (or ange-ftp-disable-netrc-security-check | |
1382 (and (eq (nth 2 attr) (user-uid)) ; Same uids. | |
1383 (string-match ".r..------" (nth 8 attr)))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1384 (with-current-buffer |
28210 | 1385 ;; we are cheating a bit here. I'm trying to do the equivalent |
1386 ;; of find-file on the .netrc file, but then nuke it afterwards. | |
1387 ;; with the bit of logic below we should be able to have | |
1388 ;; encrypted .netrc files. | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1389 (generate-new-buffer "*ftp-.netrc*") |
28210 | 1390 (ange-ftp-real-insert-file-contents file) |
1391 (setq buffer-file-name file) | |
1392 (setq default-directory (file-name-directory file)) | |
1393 (normal-mode t) | |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
1394 (run-hooks 'find-file-hook) |
28210 | 1395 (setq buffer-file-name nil) |
1396 (goto-char (point-min)) | |
1397 (skip-chars-forward " \t\r\n") | |
1398 (while (not (eobp)) | |
1399 (ange-ftp-parse-netrc-group)) | |
1400 (kill-buffer (current-buffer))) | |
1401 (ange-ftp-message "%s either not owned by you or badly protected." | |
1402 ange-ftp-netrc-filename) | |
1403 (sit-for 1)) | |
1404 (setq ange-ftp-netrc-modtime (nth 5 attr)))))) | |
1405 | |
1406 ;; Return a list of prefixes of the form 'user@host:' to be used when | |
1407 ;; completion is done in the root directory. | |
1408 | |
1409 (defun ange-ftp-generate-root-prefixes () | |
1410 (ange-ftp-parse-netrc) | |
1411 (save-match-data | |
1412 (let (res) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1413 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1414 (lambda (key value) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
1415 (if (string-match "\\`[^/]*\\(/\\).*\\'" key) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1416 (let ((host (substring key 0 (match-beginning 1))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1417 (user (substring key (match-end 1)))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1418 (push (concat user "@" host ":") res)))) |
28210 | 1419 ange-ftp-passwd-hashtable) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1420 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1421 (lambda (host user) (push (concat host ":") res)) |
28210 | 1422 ange-ftp-user-hashtable) |
1423 (or res (list nil))))) | |
1424 | |
1425 ;;;; ------------------------------------------------------------ | |
1426 ;;;; Remote file name syntax support. | |
1427 ;;;; ------------------------------------------------------------ | |
1428 | |
1429 (defmacro ange-ftp-ftp-name-component (n ns name) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1430 "Extract the Nth FTP file name component from NS." |
30459 | 1431 `(let ((elt (nth ,n ,ns))) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1432 (match-string elt ,name))) |
28210 | 1433 |
1434 (defvar ange-ftp-ftp-name-arg "") | |
1435 (defvar ange-ftp-ftp-name-res nil) | |
1436 | |
1437 ;; Parse NAME according to `ange-ftp-name-format' (which see). | |
1438 ;; Returns a list (HOST USER NAME), or nil if NAME does not match the format. | |
1439 (defun ange-ftp-ftp-name (name) | |
1440 (if (string-equal name ange-ftp-ftp-name-arg) | |
1441 ange-ftp-ftp-name-res | |
1442 (setq ange-ftp-ftp-name-arg name | |
1443 ange-ftp-ftp-name-res | |
1444 (save-match-data | |
1445 (if (posix-string-match (car ange-ftp-name-format) name) | |
1446 (let* ((ns (cdr ange-ftp-name-format)) | |
1447 (host (ange-ftp-ftp-name-component 0 ns name)) | |
1448 (user (ange-ftp-ftp-name-component 1 ns name)) | |
1449 (name (ange-ftp-ftp-name-component 2 ns name))) | |
1450 (if (zerop (length user)) | |
1451 (setq user (ange-ftp-get-user host))) | |
1452 (list host user name)) | |
1453 nil))))) | |
1454 | |
1455 ;; Take a FULLNAME that matches according to ange-ftp-name-format and | |
1456 ;; replace the name component with NAME. | |
1457 (defun ange-ftp-replace-name-component (fullname name) | |
1458 (save-match-data | |
1459 (if (posix-string-match (car ange-ftp-name-format) fullname) | |
1460 (let* ((ns (cdr ange-ftp-name-format)) | |
1461 (elt (nth 2 ns))) | |
1462 (concat (substring fullname 0 (match-beginning elt)) | |
1463 name | |
1464 (substring fullname (match-end elt))))))) | |
1465 | |
1466 ;;;; ------------------------------------------------------------ | |
1467 ;;;; Miscellaneous utils. | |
1468 ;;;; ------------------------------------------------------------ | |
1469 | |
1470 ;; (setq ange-ftp-tmp-keymap (make-sparse-keymap)) | |
1471 ;; (define-key ange-ftp-tmp-keymap "\C-m" 'exit-minibuffer) | |
1472 | |
1473 (defun ange-ftp-repaint-minibuffer () | |
1474 "Clear any existing minibuffer message; let the minibuffer contents show." | |
1475 (message nil)) | |
1476 | |
1477 ;; Return the name of the buffer that collects output from the ftp process | |
1478 ;; connected to the given HOST and USER pair. | |
1479 (defun ange-ftp-ftp-process-buffer (host user) | |
1480 (concat "*ftp " user "@" host "*")) | |
1481 | |
1482 ;; Display the last chunk of output from the ftp process for the given HOST | |
1483 ;; USER pair, and signal an error including MSG in the text. | |
1484 (defun ange-ftp-error (host user msg) | |
52209
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1485 (save-excursion ;; Prevent pop-to-buffer from changing current buffer. |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1486 (let ((cur (selected-window)) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1487 (pop-up-windows t)) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1488 (pop-to-buffer |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1489 (get-buffer-create |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1490 (ange-ftp-ftp-process-buffer host user))) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1491 (goto-char (point-max)) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1492 (select-window cur)) |
abb0fb200345
(ange-ftp-error): Add save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
51799
diff
changeset
|
1493 (signal 'ftp-error (list (format "FTP Error: %s" msg))))) |
28210 | 1494 |
1495 (defun ange-ftp-set-buffer-mode () | |
1496 "Set correct modes for the current buffer if visiting a remote file." | |
1497 (if (and (stringp buffer-file-name) | |
1498 (ange-ftp-ftp-name buffer-file-name)) | |
1499 (auto-save-mode ange-ftp-auto-save))) | |
1500 | |
1501 (defun ange-ftp-kill-ftp-process (&optional buffer) | |
1502 "Kill the FTP process associated with BUFFER (the current buffer, if nil). | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1503 If the BUFFER's visited filename or `default-directory' is an FTP filename |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1504 then kill the related FTP process." |
28210 | 1505 (interactive "bKill FTP process associated with buffer: ") |
1506 (if (null buffer) | |
1507 (setq buffer (current-buffer)) | |
1508 (setq buffer (get-buffer buffer))) | |
1509 (let ((file (or (buffer-file-name buffer) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1510 (with-current-buffer buffer default-directory)))) |
28210 | 1511 (if file |
1512 (let ((parsed (ange-ftp-ftp-name (expand-file-name file)))) | |
1513 (if parsed | |
1514 (let ((host (nth 0 parsed)) | |
1515 (user (nth 1 parsed))) | |
1516 (kill-buffer (get-buffer (ange-ftp-ftp-process-buffer host user))))))))) | |
1517 | |
1518 (defun ange-ftp-quote-string (string) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1519 "Quote any characters in STRING that may confuse the FTP process." |
91814
c1e1558393ba
* net/ange-ftp.el (ange-ftp-quote-string): Use
Michael Albinus <michael.albinus@gmx.de>
parents:
91583
diff
changeset
|
1520 ;; This is said to be wrong; ftp is said to need quoting only for ", |
c1e1558393ba
* net/ange-ftp.el (ange-ftp-quote-string): Use
Michael Albinus <michael.albinus@gmx.de>
parents:
91583
diff
changeset
|
1521 ;; and that by doubling it. But experiment says UNIX-style kind of |
c1e1558393ba
* net/ange-ftp.el (ange-ftp-quote-string): Use
Michael Albinus <michael.albinus@gmx.de>
parents:
91583
diff
changeset
|
1522 ;; quoting is correct when talking to ftp on GNU/Linux systems, and |
c1e1558393ba
* net/ange-ftp.el (ange-ftp-quote-string): Use
Michael Albinus <michael.albinus@gmx.de>
parents:
91583
diff
changeset
|
1523 ;; W32-style kind of quoting on, yes, W32 systems. |
91961
93cf29ed1d24
* net/ange-ftp.el (ange-ftp-quote-string): Return the null string
Michael Albinus <michael.albinus@gmx.de>
parents:
91814
diff
changeset
|
1524 (if (stringp string) |
93cf29ed1d24
* net/ange-ftp.el (ange-ftp-quote-string): Return the null string
Michael Albinus <michael.albinus@gmx.de>
parents:
91814
diff
changeset
|
1525 (shell-quote-argument string) |
93cf29ed1d24
* net/ange-ftp.el (ange-ftp-quote-string): Return the null string
Michael Albinus <michael.albinus@gmx.de>
parents:
91814
diff
changeset
|
1526 "")) |
28210 | 1527 |
1528 (defun ange-ftp-barf-if-not-directory (directory) | |
1529 (or (file-directory-p directory) | |
1530 (signal 'file-error | |
1531 (list "Opening directory" | |
1532 (if (file-exists-p directory) | |
1533 "not a directory" | |
1534 "no such file or directory") | |
1535 directory)))) | |
1536 | |
1537 ;;;; ------------------------------------------------------------ | |
1538 ;;;; FTP process filter support. | |
1539 ;;;; ------------------------------------------------------------ | |
1540 | |
1541 (defun ange-ftp-process-handle-line (line proc) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1542 "Look at the given LINE from the FTP process PROC. |
28210 | 1543 Try to categorize it into one of four categories: |
1544 good, skip, fatal, or unknown." | |
1545 (cond ((string-match ange-ftp-xfer-size-msgs line) | |
1546 (setq ange-ftp-xfer-size | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1547 (/ (string-to-number (match-string 1 line)) |
43187
992a5c499b47
(ange-ftp-process-handle-line, ange-ftp-set-xfer-size): If the file's
Eli Zaretskii <eliz@gnu.org>
parents:
42898
diff
changeset
|
1548 1024))) |
28210 | 1549 ((string-match ange-ftp-skip-msgs line) |
1550 t) | |
1551 ((string-match ange-ftp-good-msgs line) | |
1552 (setq ange-ftp-process-busy nil | |
1553 ange-ftp-process-result t | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1554 ange-ftp-pending-error-line nil |
28210 | 1555 ange-ftp-process-result-line line)) |
1556 ;; Check this before checking for errors. | |
1557 ;; Otherwise the last line of these three seems to be an error: | |
1558 ;; 230-see a significant impact from the move. For those of you who can't | |
1559 ;; 230-use DNS to resolve hostnames and get an error message like | |
1560 ;; 230-"ftp.stsci.edu: unknown host", the new IP address will be... | |
1561 ((string-match ange-ftp-multi-msgs line) | |
1562 (setq ange-ftp-process-multi-skip t)) | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1563 ((string-match ange-ftp-potential-error-msgs line) |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1564 ;; This looks like an error, but we have to keep reading the output |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1565 ;; to see if it was fixed or not. E.g. it may indicate that IPv6 |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1566 ;; failed, but maybe a subsequent IPv4 fallback succeeded. |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1567 (set (make-local-variable 'ange-ftp-pending-error-line) line) |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1568 t) |
28210 | 1569 ((string-match ange-ftp-fatal-msgs line) |
1570 (delete-process proc) | |
1571 (setq ange-ftp-process-busy nil | |
1572 ange-ftp-process-result-line line)) | |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1573 (ange-ftp-process-multi-skip |
28210 | 1574 t) |
1575 (t | |
1576 (setq ange-ftp-process-busy nil | |
1577 ange-ftp-process-result-line line)))) | |
1578 | |
1579 (defun ange-ftp-set-xfer-size (host user bytes) | |
1580 "Set the size of the next FTP transfer in bytes." | |
1581 (let ((proc (ange-ftp-get-process host user))) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1582 (when proc |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1583 (let ((buf (process-buffer proc))) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1584 (when buf |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1585 (with-current-buffer buf |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1586 (setq ange-ftp-xfer-size |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1587 ;; For very large files, BYTES can be a float. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1588 (if (integerp bytes) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1589 (ash bytes -10) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1590 (/ bytes 1024))))))))) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1591 |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1592 (defun ange-ftp-process-handle-hash (string) |
28210 | 1593 "Remove hash marks from STRING and display count so far." |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1594 (setq string (concat (substring string 0 (match-beginning 0)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1595 (substring string (match-end 0))) |
28210 | 1596 ange-ftp-hash-mark-count (+ (- (match-end 0) |
1597 (match-beginning 0)) | |
1598 ange-ftp-hash-mark-count)) | |
1599 (and ange-ftp-hash-mark-unit | |
1600 ange-ftp-process-msg | |
1601 ange-ftp-process-verbose | |
1602 (not (eq (selected-window) (minibuffer-window))) | |
1603 (not (boundp 'search-message)) ;screws up isearch otherwise | |
1604 (not cursor-in-echo-area) ;screws up y-or-n-p otherwise | |
1605 (let ((kbytes (ash (* ange-ftp-hash-mark-unit | |
1606 ange-ftp-hash-mark-count) | |
1607 -6))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1608 (if (zerop ange-ftp-xfer-size) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1609 (ange-ftp-message "%s...%dk" ange-ftp-process-msg kbytes) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1610 (let ((percent (/ (* 100 kbytes) ange-ftp-xfer-size))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1611 ;; cut out the redisplay of identical %-age messages. |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1612 (unless (eq percent ange-ftp-last-percent) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1613 (setq ange-ftp-last-percent percent) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1614 (ange-ftp-message "%s...%d%%" ange-ftp-process-msg percent)))))) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1615 string) |
28210 | 1616 |
1617 ;; Call the function specified by CONT. CONT can be either a function | |
1618 ;; or a list of a function and some args. The first two parameters | |
1619 ;; passed to the function will be RESULT and LINE. The remaining args | |
1620 ;; will be taken from CONT if a list was passed. | |
1621 | |
1622 (defun ange-ftp-call-cont (cont result line) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1623 (when cont |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1624 (if (and (listp cont) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1625 (not (eq (car cont) 'lambda))) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1626 (apply (car cont) result line (cdr cont)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1627 (funcall cont result line)))) |
28210 | 1628 |
1629 ;; Build up a complete line of output from the ftp PROCESS and pass it | |
1630 ;; on to ange-ftp-process-handle-line to deal with. | |
1631 | |
1632 (defun ange-ftp-process-filter (proc str) | |
65516
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1633 ;; Eliminate nulls. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1634 (while (string-match "\000+" str) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1635 (setq str (replace-match "" nil nil str))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1636 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1637 ;; see if the buffer is still around... it could have been deleted. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1638 (when (buffer-live-p (process-buffer proc)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1639 (with-current-buffer (process-buffer proc) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1640 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1641 ;; handle hash mark printing |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1642 (and ange-ftp-process-busy |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1643 (string-match "^#+$" str) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1644 (setq str (ange-ftp-process-handle-hash str))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1645 (comint-output-filter proc str) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1646 ;; Replace STR by the result of the comint processing. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1647 (setq str (buffer-substring comint-last-output-start |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1648 (process-mark proc))) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1649 (when ange-ftp-process-busy |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1650 (setq ange-ftp-process-string (concat ange-ftp-process-string |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1651 str)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1652 |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1653 ;; if we gave an empty password to the USER command earlier |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1654 ;; then we should send a null password now. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1655 (if (string-match "Password: *$" ange-ftp-process-string) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1656 (process-send-string proc "\n"))) |
65516
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1657 (while (and ange-ftp-process-busy |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1658 (string-match "\n" ange-ftp-process-string)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1659 (let ((line (substring ange-ftp-process-string |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1660 0 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1661 (match-beginning 0))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1662 (seen-prompt nil)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1663 (setq ange-ftp-process-string (substring ange-ftp-process-string |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1664 (match-end 0))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1665 (while (string-match "\\`ftp> *" line) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1666 (setq seen-prompt t) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1667 (setq line (substring line (match-end 0)))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1668 (if (not (and seen-prompt ange-ftp-pending-error-line)) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1669 (ange-ftp-process-handle-line line proc) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1670 ;; If we've seen a potential error message and it |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1671 ;; hasn't been cancelled by a good message before |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1672 ;; seeing a propt, then the error was real. |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1673 (delete-process proc) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1674 (setq ange-ftp-process-busy nil |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1675 ange-ftp-process-result-line ange-ftp-pending-error-line)))) |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1676 |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1677 ;; has the ftp client finished? if so then do some clean-up |
5fd07f61ee51
(ange-ftp-process-filter): Revert to ^#+$.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64906
diff
changeset
|
1678 ;; actions. |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1679 (unless ange-ftp-process-busy |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1680 ;; reset the xfer size |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1681 (setq ange-ftp-xfer-size 0) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1682 |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1683 ;; issue the "done" message since we've finished. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1684 (when (and ange-ftp-process-msg |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1685 ange-ftp-process-verbose |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1686 ange-ftp-process-result) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1687 (ange-ftp-message "%s...done" ange-ftp-process-msg) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1688 (ange-ftp-repaint-minibuffer) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1689 (setq ange-ftp-process-msg nil)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1690 |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1691 ;; is there a continuation we should be calling? if so, |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1692 ;; we'd better call it, making sure we only call it once. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1693 (when ange-ftp-process-continue |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1694 (let ((cont ange-ftp-process-continue)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1695 (setq ange-ftp-process-continue nil) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1696 (ange-ftp-call-cont cont |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1697 ange-ftp-process-result |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1698 ange-ftp-process-result-line))))))) |
28210 | 1699 |
1700 (defun ange-ftp-process-sentinel (proc str) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1701 "When FTP process changes state, nuke all file-entries in cache." |
28210 | 1702 (let ((name (process-name proc))) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1703 (when (string-match "\\*ftp \\([^@]+\\)@\\([^*]+\\)\\*" name) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1704 (let ((user (match-string 1 name)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1705 (host (match-string 2 name))) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1706 (ange-ftp-wipe-file-entries host user)))) |
28210 | 1707 (setq ange-ftp-ls-cache-file nil)) |
1708 | |
1709 ;;;; ------------------------------------------------------------ | |
1710 ;;;; Gateway support. | |
1711 ;;;; ------------------------------------------------------------ | |
1712 | |
1713 (defun ange-ftp-use-gateway-p (host) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1714 "Return whether to access this HOST via a normal (non-smart) gateway." |
28210 | 1715 ;; yes, I know that I could simplify the following expression, but it is |
1716 ;; clearer (to me at least) this way. | |
1717 (and (not ange-ftp-smart-gateway) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1718 (not (string-match-p ange-ftp-local-host-regexp host)))) |
28210 | 1719 |
1720 (defun ange-ftp-use-smart-gateway-p (host) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1721 "Returns whether to access this HOST via a smart gateway." |
28210 | 1722 (and ange-ftp-smart-gateway |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1723 (not (string-match-p ange-ftp-local-host-regexp host)))) |
28210 | 1724 |
1725 | |
1726 ;;; ------------------------------------------------------------ | |
1727 ;;; Temporary file location and deletion... | |
1728 ;;; ------------------------------------------------------------ | |
1729 | |
1730 (defun ange-ftp-make-tmp-name (host) | |
1731 "This routine will return the name of a new file." | |
1732 (make-temp-file (if (ange-ftp-use-gateway-p host) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1733 ange-ftp-gateway-tmp-name-template |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
1734 ange-ftp-tmp-name-template))) |
28210 | 1735 |
1736 (defalias 'ange-ftp-del-tmp-name 'delete-file) | |
1737 | |
1738 ;;;; ------------------------------------------------------------ | |
1739 ;;;; Interactive gateway program support. | |
1740 ;;;; ------------------------------------------------------------ | |
1741 | |
1742 (defvar ange-ftp-gwp-running t) | |
1743 (defvar ange-ftp-gwp-status nil) | |
1744 | |
1745 (defun ange-ftp-gwp-sentinel (proc str) | |
1746 (setq ange-ftp-gwp-running nil)) | |
1747 | |
1748 (defun ange-ftp-gwp-filter (proc str) | |
1749 (comint-output-filter proc str) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1750 (with-current-buffer (process-buffer proc) |
28210 | 1751 ;; Replace STR by the result of the comint processing. |
1752 (setq str (buffer-substring comint-last-output-start (process-mark proc)))) | |
1753 (cond ((string-match "login: *$" str) | |
62460
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1754 (process-send-string proc |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1755 (concat |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1756 (let ((ange-ftp-default-user t)) |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1757 (ange-ftp-get-user ange-ftp-gateway-host)) |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1758 "\n"))) |
28210 | 1759 ((string-match "Password: *$" str) |
62460
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1760 (process-send-string proc |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1761 (concat |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1762 (ange-ftp-get-passwd ange-ftp-gateway-host |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1763 (ange-ftp-get-user |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1764 ange-ftp-gateway-host)) |
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1765 "\n"))) |
28210 | 1766 ((string-match ange-ftp-gateway-fatal-msgs str) |
1767 (delete-process proc) | |
1768 (setq ange-ftp-gwp-running nil)) | |
1769 ((string-match ange-ftp-gateway-prompt-pattern str) | |
1770 (setq ange-ftp-gwp-running nil | |
1771 ange-ftp-gwp-status t)))) | |
1772 | |
1773 (defun ange-ftp-gwp-start (host user name args) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1774 "Login to the gateway machine and fire up an FTP process." |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1775 (let (;; It would be nice to make process-connection-type nil, |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1776 ;; but that doesn't work: ftp never responds. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1777 ;; Can anyone find a fix for that? |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1778 (proc (let ((process-connection-type t)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1779 (start-process name name |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1780 ange-ftp-gateway-program |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1781 ange-ftp-gateway-host))) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1782 (ftp (mapconcat 'identity args " "))) |
56765
3c6aa215e03f
(ange-ftp-gwp-start, ange-ftp-nslookup-host)
Richard M. Stallman <rms@gnu.org>
parents:
56742
diff
changeset
|
1783 (set-process-query-on-exit-flag proc nil) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1784 (set-process-sentinel proc 'ange-ftp-gwp-sentinel) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1785 (set-process-filter proc 'ange-ftp-gwp-filter) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
1786 (with-current-buffer (process-buffer proc) |
28210 | 1787 (goto-char (point-max)) |
1788 (set-marker (process-mark proc) (point))) | |
1789 (setq ange-ftp-gwp-running t | |
1790 ange-ftp-gwp-status nil) | |
1791 (ange-ftp-message "Connecting to gateway %s..." ange-ftp-gateway-host) | |
1792 (while ange-ftp-gwp-running ;perform login sequence | |
1793 (accept-process-output proc)) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1794 (unless ange-ftp-gwp-status |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1795 (ange-ftp-error host user "unable to login to gateway")) |
28210 | 1796 (ange-ftp-message "Connecting to gateway %s...done" ange-ftp-gateway-host) |
1797 (setq ange-ftp-gwp-running t | |
1798 ange-ftp-gwp-status nil) | |
1799 (process-send-string proc ange-ftp-gateway-setup-term-command) | |
1800 (while ange-ftp-gwp-running ;zap ^M's and double echoing. | |
1801 (accept-process-output proc)) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1802 (unless ange-ftp-gwp-status |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1803 (ange-ftp-error host user "unable to set terminal modes on gateway")) |
28210 | 1804 (setq ange-ftp-gwp-running t |
1805 ange-ftp-gwp-status nil) | |
1806 (process-send-string proc (concat "exec " ftp "\n")) ;spawn ftp process | |
1807 proc)) | |
1808 | |
1809 ;;;; ------------------------------------------------------------ | |
1810 ;;;; Support for sending commands to the ftp process. | |
1811 ;;;; ------------------------------------------------------------ | |
1812 | |
1813 (defun ange-ftp-raw-send-cmd (proc cmd &optional msg cont nowait) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1814 "Low-level routine to send the given FTP CMD to the FTP process PROC. |
28210 | 1815 MSG is an optional message to output before and after the command. |
30459 | 1816 If CONT is non-nil then it is either a function or a list of function |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1817 and some arguments. The function will be called when the FTP command |
30459 | 1818 has completed. |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1819 If CONT is nil then this routine will return (RESULT . LINE) where RESULT |
28210 | 1820 is whether the command was successful, and LINE is the line from the FTP |
1821 process that caused the command to complete. | |
1822 If NOWAIT is given then the routine will return immediately the command has | |
1823 been queued with no result. CONT will still be called, however." | |
1824 (if (memq (process-status proc) '(run open)) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
1825 (with-current-buffer (process-buffer proc) |
28210 | 1826 (ange-ftp-wait-not-busy proc) |
1827 (setq ange-ftp-process-string "" | |
1828 ange-ftp-process-result-line "" | |
1829 ange-ftp-process-busy t | |
1830 ange-ftp-process-result nil | |
1831 ange-ftp-process-multi-skip nil | |
1832 ange-ftp-process-msg msg | |
1833 ange-ftp-process-continue cont | |
1834 ange-ftp-hash-mark-count 0 | |
1835 ange-ftp-last-percent -1 | |
1836 cmd (concat cmd "\n")) | |
1837 (and msg ange-ftp-process-verbose (ange-ftp-message "%s..." msg)) | |
1838 (goto-char (point-max)) | |
1839 (move-marker comint-last-input-start (point)) | |
1840 ;; don't insert the password into the buffer on the USER command. | |
1841 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
1842 (if (string-match "\\`user \"[^\"]*\"" cmd) |
28210 | 1843 (insert (substring cmd 0 (match-end 0)) " Turtle Power!\n") |
1844 (insert cmd))) | |
1845 (move-marker comint-last-input-end (point)) | |
62460
5bdce92e5771
Replace `send-string' by `process-send-string'.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
1846 (process-send-string proc cmd) |
28210 | 1847 (set-marker (process-mark proc) (point)) |
1848 (if nowait | |
1849 nil | |
1850 (ange-ftp-wait-not-busy proc) | |
1851 (if cont | |
1852 nil ;cont has already been called | |
1853 (cons ange-ftp-process-result ange-ftp-process-result-line)))))) | |
1854 | |
1855 ;; Wait for the ange-ftp process PROC not to be busy. | |
1856 (defun ange-ftp-wait-not-busy (proc) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
1857 (with-current-buffer (process-buffer proc) |
28210 | 1858 (condition-case nil |
1859 ;; This is a kludge to let user quit in case ftp gets hung. | |
1860 ;; It matters because this function can be called from the filter. | |
1861 ;; It is bad to allow quitting in a filter, but getting hung | |
1862 ;; is worse. By binding quit-flag to nil, we might avoid | |
1863 ;; most of the probability of getting screwed because the user | |
1864 ;; wants to quit some command. | |
1865 (let ((quit-flag nil) | |
1866 (inhibit-quit nil)) | |
1867 (while ange-ftp-process-busy | |
1868 (accept-process-output proc))) | |
1869 (quit | |
1870 ;; If the user does quit out of this, | |
1871 ;; kill the process. That stops any transfer in progress. | |
1872 ;; The next operation will open a new ftp connection. | |
1873 (delete-process proc) | |
1874 (signal 'quit nil))))) | |
1875 | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1876 (defun ange-ftp-nslookup-host (hostname) |
28210 | 1877 "Attempt to resolve the given HOSTNAME using nslookup if possible." |
1878 (interactive "sHost: ") | |
1879 (if ange-ftp-nslookup-program | |
1880 (let ((default-directory | |
1881 (if (file-accessible-directory-p default-directory) | |
1882 default-directory | |
1883 exec-directory)) | |
1884 ;; It would be nice to make process-connection-type nil, | |
1885 ;; but that doesn't work: ftp never responds. | |
1886 ;; Can anyone find a fix for that? | |
1887 (proc (let ((process-connection-type t)) | |
1888 (start-process " *nslookup*" " *nslookup*" | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1889 ange-ftp-nslookup-program hostname))) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1890 (res hostname)) |
56765
3c6aa215e03f
(ange-ftp-gwp-start, ange-ftp-nslookup-host)
Richard M. Stallman <rms@gnu.org>
parents:
56742
diff
changeset
|
1891 (set-process-query-on-exit-flag proc nil) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1892 (with-current-buffer (process-buffer proc) |
28210 | 1893 (while (memq (process-status proc) '(run open)) |
1894 (accept-process-output proc)) | |
1895 (goto-char (point-min)) | |
1896 (if (re-search-forward "Name:.*\nAddress: *\\(.*\\)$" nil t) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1897 (setq res (match-string 1))) |
28210 | 1898 (kill-buffer (current-buffer))) |
1899 res) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1900 hostname)) |
28210 | 1901 |
1902 (defun ange-ftp-start-process (host user name) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1903 "Spawn a new FTP process ready to connect to machine HOST and give it NAME. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1904 If HOST is only FTP-able through a gateway machine then spawn a shell |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1905 on the gateway machine to do the FTP instead." |
28210 | 1906 (let* ((use-gateway (ange-ftp-use-gateway-p host)) |
1907 (use-smart-ftp (and (not ange-ftp-gateway-host) | |
1908 (ange-ftp-use-smart-gateway-p host))) | |
1909 (ftp-prog (if (or use-gateway | |
30459 | 1910 use-smart-ftp) |
28210 | 1911 ange-ftp-gateway-ftp-program-name |
1912 ange-ftp-ftp-program-name)) | |
1913 (args (append (list ftp-prog) ange-ftp-ftp-program-args)) | |
1914 ;; Without the following binding, ange-ftp-start-process | |
1915 ;; recurses on file-accessible-directory-p, since it needs to | |
1916 ;; restart its process in order to determine anything about | |
1917 ;; default-directory. | |
1918 (file-name-handler-alist) | |
1919 (default-directory | |
1920 (if (file-accessible-directory-p default-directory) | |
1921 default-directory | |
1922 exec-directory)) | |
1923 proc) | |
1924 ;; It would be nice to make process-connection-type nil, | |
1925 ;; but that doesn't work: ftp never responds. | |
1926 ;; Can anyone find a fix for that? | |
1927 (let ((process-connection-type t) | |
53415
d2a77d389b0e
(ange-ftp-start-process): Copy the environment.
Richard M. Stallman <rms@gnu.org>
parents:
53388
diff
changeset
|
1928 ;; Copy this so we don't alter it permanently. |
d2a77d389b0e
(ange-ftp-start-process): Copy the environment.
Richard M. Stallman <rms@gnu.org>
parents:
53388
diff
changeset
|
1929 (process-environment (copy-tree process-environment)) |
28210 | 1930 (buffer (get-buffer-create name))) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1931 (with-current-buffer buffer |
28210 | 1932 (internal-ange-ftp-mode)) |
1933 ;; This tells GNU ftp not to output any fancy escape sequences. | |
1934 (setenv "TERM" "dumb") | |
1935 (if use-gateway | |
1936 (if ange-ftp-gateway-program-interactive | |
1937 (setq proc (ange-ftp-gwp-start host user name args)) | |
1938 (setq proc (apply 'start-process name name | |
1939 (append (list ange-ftp-gateway-program | |
1940 ange-ftp-gateway-host) | |
1941 args)))) | |
1942 (setq proc (apply 'start-process name name args)))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
1943 (with-current-buffer (process-buffer proc) |
28210 | 1944 (goto-char (point-max)) |
1945 (set-marker (process-mark proc) (point))) | |
56765
3c6aa215e03f
(ange-ftp-gwp-start, ange-ftp-nslookup-host)
Richard M. Stallman <rms@gnu.org>
parents:
56742
diff
changeset
|
1946 (set-process-query-on-exit-flag proc nil) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1947 (set-process-sentinel proc 'ange-ftp-process-sentinel) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
1948 (set-process-filter proc 'ange-ftp-process-filter) |
28210 | 1949 ;; On Windows, the standard ftp client buffers its output (because |
1950 ;; stdout is a pipe handle) so the startup message may never appear: | |
1951 ;; `accept-process-output' at this point would hang indefinitely. | |
1952 ;; However, sending an innocuous command ("help foo") forces some | |
1953 ;; output that will be ignored, which is just as good. Once we | |
1954 ;; start sending normal commands, the output no longer appears to be | |
1955 ;; buffered, and everything works correctly. My guess is that the | |
1956 ;; output of interest is being sent to stderr which is not buffered. | |
1957 (when (eq system-type 'windows-nt) | |
1958 ;; force ftp output to be treated as DOS text, otherwise the | |
1959 ;; output of "help foo" confuses the EOL detection logic. | |
1960 (set-process-coding-system proc 'raw-text-dos) | |
1961 (process-send-string proc "help foo\n")) | |
1962 (accept-process-output proc) ;wait for ftp startup message | |
1963 proc)) | |
1964 | |
104733
9902de48eab4
(internal-ange-ftp-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104552
diff
changeset
|
1965 (define-derived-mode internal-ange-ftp-mode comint-mode "Internal Ange-ftp" |
28210 | 1966 "Major mode for interacting with the FTP process. |
1967 | |
1968 \\{comint-mode-map}" | |
63413
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1969 (make-local-variable 'ange-ftp-process-string) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1970 (setq ange-ftp-process-string "") |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1971 (make-local-variable 'ange-ftp-process-busy) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1972 (make-local-variable 'ange-ftp-process-result) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1973 (make-local-variable 'ange-ftp-process-msg) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1974 (make-local-variable 'ange-ftp-process-multi-skip) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1975 (make-local-variable 'ange-ftp-process-result-line) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1976 (make-local-variable 'ange-ftp-process-continue) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1977 (make-local-variable 'ange-ftp-hash-mark-count) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1978 (make-local-variable 'ange-ftp-binary-hash-mark-size) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1979 (make-local-variable 'ange-ftp-ascii-hash-mark-size) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1980 (make-local-variable 'ange-ftp-hash-mark-unit) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1981 (make-local-variable 'ange-ftp-xfer-size) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1982 (make-local-variable 'ange-ftp-last-percent) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1983 (setq ange-ftp-hash-mark-count 0) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1984 (setq ange-ftp-xfer-size 0) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1985 (setq ange-ftp-process-result-line "") |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1986 (setq comint-prompt-regexp "^ftp> ") |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1987 (make-local-variable 'comint-password-prompt-regexp) |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1988 ;; This is a regexp that can't match anything. |
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1989 ;; ange-ftp has its own ways of handling passwords. |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
1990 (setq comint-password-prompt-regexp "\\`a\\`") |
63413
a66bfdd4586a
(internal-ange-ftp-mode): Use delay-mode-hooks and run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62460
diff
changeset
|
1991 (make-local-variable 'paragraph-start) |
104733
9902de48eab4
(internal-ange-ftp-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104552
diff
changeset
|
1992 (setq paragraph-start comint-prompt-regexp)) |
28210 | 1993 |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1994 (defcustom ange-ftp-raw-login nil |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1995 "Use raw FTP commands for login, if account password is not nil. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
1996 Some FTP implementations need this, e.g. ftp in NT 4.0." |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1997 :group 'ange-ftp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1998 :version "21.3" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
1999 :type 'boolean) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2000 |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2001 (defun ange-ftp-smart-login (host user password account proc) |
28210 | 2002 "Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT. |
2003 PROC is the FTP-client's process. This routine uses the smart-gateway | |
30459 | 2004 host specified in `ange-ftp-gateway-host'." |
28210 | 2005 (let ((result (ange-ftp-raw-send-cmd |
2006 proc | |
2007 (format "open %s %s" | |
2008 (ange-ftp-nslookup-host ange-ftp-gateway-host) | |
2009 ange-ftp-smart-gateway-port) | |
2010 (format "Opening FTP connection to %s via %s" | |
2011 host | |
2012 ange-ftp-gateway-host)))) | |
2013 (or (car result) | |
30459 | 2014 (ange-ftp-error host user |
28210 | 2015 (concat "OPEN request failed: " |
2016 (cdr result)))) | |
2017 (setq result (ange-ftp-raw-send-cmd | |
2018 proc (format "user \"%s\"@%s %s %s" | |
2019 user | |
2020 (ange-ftp-nslookup-host host) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2021 password |
28210 | 2022 account) |
2023 (format "Logging in as user %s@%s" | |
2024 user host))) | |
2025 (or (car result) | |
2026 (progn | |
2027 (ange-ftp-set-passwd host user nil) ; reset password | |
2028 (ange-ftp-set-account host user nil) ; reset account | |
2029 (ange-ftp-error host user | |
2030 (concat "USER request failed: " | |
2031 (cdr result))))))) | |
2032 | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2033 (defun ange-ftp-normal-login (host user password account proc) |
28210 | 2034 "Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT. |
2035 PROC is the process to the FTP-client. HOST may have an optional | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2036 suffix of the form #PORT to specify a non-default port." |
28210 | 2037 (save-match-data |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2038 (string-match "\\`\\([^#]+\\)\\(#\\([0-9]+\\)\\)?\\'" host) |
28210 | 2039 (let* ((nshost (ange-ftp-nslookup-host (match-string 1 host))) |
2040 (port (match-string 3 host)) | |
2041 (result (ange-ftp-raw-send-cmd | |
2042 proc | |
2043 (if port | |
2044 (format "open %s %s" nshost port) | |
2045 (format "open %s" nshost)) | |
2046 (format "Opening FTP connection to %s" host)))) | |
2047 (or (car result) | |
2048 (ange-ftp-error host user | |
2049 (concat "OPEN request failed: " | |
2050 (cdr result)))) | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2051 (if (not (and ange-ftp-raw-login (string< "" account))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2052 (setq result (ange-ftp-raw-send-cmd |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2053 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2054 (if (and (ange-ftp-use-smart-gateway-p host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2055 ange-ftp-gateway-host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2056 (format "user \"%s\"@%s %s %s" |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2057 user nshost password account) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2058 (format "user \"%s\" %s %s" user password account)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2059 (format "Logging in as user %s@%s" user host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2060 (let ((good ange-ftp-good-msgs) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2061 (skip ange-ftp-skip-msgs)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2062 (setq ange-ftp-good-msgs (concat ange-ftp-good-msgs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2063 "\\|^331 \\|^332 ")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2064 (if (string-match (regexp-quote "\\|^331 ") ange-ftp-skip-msgs) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2065 (setq ange-ftp-skip-msgs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2066 (replace-match "" t t ange-ftp-skip-msgs))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2067 (if (string-match (regexp-quote "\\|^332 ") ange-ftp-skip-msgs) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2068 (setq ange-ftp-skip-msgs |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2069 (replace-match "" t t ange-ftp-skip-msgs))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2070 (setq result (ange-ftp-raw-send-cmd |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2071 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2072 (format "quote \"USER %s\"" user) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2073 (format "Logging in as user %s@%s" user host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2074 (and (car result) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2075 (setq result (ange-ftp-raw-send-cmd |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2076 proc |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2077 (format "quote \"PASS %s\"" password) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2078 (format "Logging in as user %s@%s" user host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2079 (and (car result) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2080 (setq result (ange-ftp-raw-send-cmd |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2081 proc |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2082 (format "quote \"ACCT %s\"" account) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2083 (format "Logging in as user %s@%s" user host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2084 )) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2085 (setq ange-ftp-good-msgs good |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2086 ange-ftp-skip-msgs skip))) |
28210 | 2087 (or (car result) |
2088 (progn | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2089 (ange-ftp-set-passwd host user nil) ;reset password. |
28210 | 2090 (ange-ftp-set-account host user nil) ;reset account. |
2091 (ange-ftp-error host user | |
2092 (concat "USER request failed: " | |
2093 (cdr result)))))))) | |
2094 | |
2095 ;; ange@hplb.hpl.hp.com says this should not be changed. | |
2096 (defvar ange-ftp-hash-mark-msgs | |
2097 "[hH]ash mark [^0-9]*\\([0-9]+\\)" | |
2098 "*Regexp matching the FTP client's output upon doing a HASH command.") | |
2099 | |
2100 (defun ange-ftp-guess-hash-mark-size (proc) | |
2101 (if ange-ftp-send-hash | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2102 (with-current-buffer (process-buffer proc) |
28210 | 2103 (let* ((status (ange-ftp-raw-send-cmd proc "hash")) |
2104 (line (cdr status))) | |
2105 (save-match-data | |
2106 (if (string-match ange-ftp-hash-mark-msgs line) | |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
59996
diff
changeset
|
2107 (let ((size (string-to-number (match-string 1 line)))) |
28210 | 2108 (setq ange-ftp-ascii-hash-mark-size size |
2109 ange-ftp-hash-mark-unit (ash size -4)) | |
2110 | |
2111 ;; if a default value for this is set, use that value. | |
2112 (or ange-ftp-binary-hash-mark-size | |
2113 (setq ange-ftp-binary-hash-mark-size size))))))))) | |
2114 | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2115 (defvar ange-ftp-process-startup-hook nil) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2116 |
28210 | 2117 (defun ange-ftp-get-process (host user) |
2118 "Return an FTP subprocess connected to HOST and logged in as USER. | |
2119 Create a new process if needed." | |
2120 (let* ((name (ange-ftp-ftp-process-buffer host user)) | |
2121 (proc (get-process name))) | |
2122 (if (and proc (memq (process-status proc) '(run open))) | |
2123 proc | |
2124 ;; Must delete dead process so that new process can reuse the name. | |
2125 (if proc (delete-process proc)) | |
2126 (let ((pass (ange-ftp-quote-string | |
2127 (ange-ftp-get-passwd host user))) | |
2128 (account (ange-ftp-quote-string | |
2129 (ange-ftp-get-account host user)))) | |
2130 ;; grab a suitable process. | |
2131 (setq proc (ange-ftp-start-process host user name)) | |
30459 | 2132 |
28210 | 2133 ;; login to FTP server. |
2134 (if (and (ange-ftp-use-smart-gateway-p host) | |
2135 ange-ftp-gateway-host) | |
2136 (ange-ftp-smart-login host user pass account proc) | |
2137 (ange-ftp-normal-login host user pass account proc)) | |
30459 | 2138 |
28210 | 2139 ;; Tell client to send back hash-marks as progress. It isn't usually |
2140 ;; fatal if this command fails. | |
2141 (ange-ftp-guess-hash-mark-size proc) | |
2142 | |
2143 ;; Guess at the host type. | |
2144 (ange-ftp-guess-host-type host user) | |
2145 | |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2146 ;; Turn passive mode on or off as requested. |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2147 (let* ((case-fold-search t) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2148 (passive |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2149 (or (assoc-default host ange-ftp-passive-host-alist |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2150 'string-match) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2151 (if ange-ftp-try-passive-mode "on")))) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2152 (if passive |
42801
b719a1276b31
(ange-ftp-passive-mode): New arg PROC.
Richard M. Stallman <rms@gnu.org>
parents:
42740
diff
changeset
|
2153 (ange-ftp-passive-mode proc passive))) |
28210 | 2154 |
2155 ;; Run any user-specified hooks. Note that proc, host and user are | |
2156 ;; dynamically bound at this point. | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2157 (let ((ange-ftp-this-user user) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2158 (ange-ftp-this-host host)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2159 (run-hooks 'ange-ftp-process-startup-hook))) |
28210 | 2160 proc))) |
2161 | |
42801
b719a1276b31
(ange-ftp-passive-mode): New arg PROC.
Richard M. Stallman <rms@gnu.org>
parents:
42740
diff
changeset
|
2162 (defun ange-ftp-passive-mode (proc on-or-off) |
42393
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2163 (if (string-match (concat "Passive mode " on-or-off) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2164 (cdr (ange-ftp-raw-send-cmd |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2165 proc (concat "passive " on-or-off) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2166 "Trying passive mode..." nil))) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2167 (ange-ftp-message (concat "Trying passive mode..." on-or-off)) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2168 (error "Trying passive mode...failed"))) |
a31dc22699ed
(ange-ftp-allow-child-lookup): Always return nil.
Richard M. Stallman <rms@gnu.org>
parents:
42251
diff
changeset
|
2169 |
28210 | 2170 ;; Variables for caching host and host-type |
2171 (defvar ange-ftp-host-cache nil) | |
2172 (defvar ange-ftp-host-type-cache nil) | |
2173 | |
2174 ;; If ange-ftp-host-type is called with the optional user | |
2175 ;; argument, it will attempt to guess the host type by connecting | |
2176 ;; as user, if necessary. For efficiency, I have tried to give this | |
2177 ;; optional second argument only when necessary. Have I missed any calls | |
2178 ;; to ange-ftp-host-type where it should have been supplied? | |
2179 | |
2180 (defun ange-ftp-host-type (host &optional user) | |
2181 "Return a symbol which represents the type of the HOST given. | |
2182 If the optional argument USER is given, attempts to guess the | |
2183 host-type by logging in as USER." | |
2184 (cond ((null host) 'unix) | |
2185 ;; Return `unix' if HOST is nil, since that's the most vanilla | |
2186 ;; possible return value. | |
2187 ((eq host ange-ftp-host-cache) | |
2188 ange-ftp-host-type-cache) | |
2189 ;; Trigger an ftp connection, in case we need to guess at the host type. | |
2190 ((and user (ange-ftp-get-process host user) (eq host ange-ftp-host-cache)) | |
2191 ange-ftp-host-type-cache) | |
2192 (t | |
2193 (setq ange-ftp-host-cache host | |
2194 ange-ftp-host-type-cache | |
2195 (cond ((ange-ftp-dumb-unix-host host) | |
2196 'dumb-unix) | |
2197 ;; ((and (fboundp 'ange-ftp-vos-host) | |
2198 ;; (ange-ftp-vos-host host)) | |
2199 ;; 'vos) | |
2200 ((and (fboundp 'ange-ftp-vms-host) | |
2201 (ange-ftp-vms-host host)) | |
2202 'vms) | |
2203 ((and (fboundp 'ange-ftp-mts-host) | |
2204 (ange-ftp-mts-host host)) | |
2205 'mts) | |
2206 ((and (fboundp 'ange-ftp-cms-host) | |
2207 (ange-ftp-cms-host host)) | |
2208 'cms) | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2209 ((and (fboundp 'ange-ftp-bs2000-posix-host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2210 (ange-ftp-bs2000-posix-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2211 'text-unix) ; POSIX is a non-ASCII Unix |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2212 ((and (fboundp 'ange-ftp-bs2000-host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2213 (ange-ftp-bs2000-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2214 'bs2000) |
28210 | 2215 (t |
2216 'unix)))))) | |
2217 | |
2218 ;; It would be nice to abstract the functions ange-ftp-TYPE-host and | |
2219 ;; ange-ftp-add-TYPE-host. The trick is to abstract these functions | |
2220 ;; without sacrificing speed. Also, having separate variables | |
2221 ;; ange-ftp-TYPE-regexp is more user friendly then requiring the user to | |
2222 ;; set an alist to indicate that a host is of a given type. Even with | |
2223 ;; automatic host type recognition, setting a regexp is still a good idea | |
2224 ;; (for efficiency) if you log into a particular non-UNIX host frequently. | |
2225 | |
2226 (defvar ange-ftp-fix-name-func-alist nil | |
2227 "Alist saying how to convert file name to the host's syntax. | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2228 Association list of (TYPE . FUNC) pairs, where FUNC is a routine which can |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2229 change a UNIX file name into a name more suitable for a host of type TYPE.") |
28210 | 2230 |
2231 (defvar ange-ftp-fix-dir-name-func-alist nil | |
2232 "Alist saying how to convert directory name to the host's syntax. | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2233 Association list of (TYPE . FUNC) pairs, where FUNC is a routine which can |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2234 change UNIX directory name into a directory name more suitable for a host |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2235 of type TYPE.") |
28210 | 2236 |
2237 ;; *** Perhaps the sense of this variable should be inverted, since there | |
2238 ;; *** is only 1 host type that can take ls-style listing options. | |
2239 (defvar ange-ftp-dumb-host-types '(dumb-unix) | |
2240 "List of host types that can't take UNIX ls-style listing options.") | |
2241 | |
2242 (defun ange-ftp-send-cmd (host user cmd &optional msg cont nowait) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2243 "Find an FTP process connected to HOST logged in as USER and send it CMD. |
28210 | 2244 MSG is an optional status message to be output before and after issuing the |
2245 command. | |
30459 | 2246 See the documentation for `ange-ftp-raw-send-cmd' for a description of CONT |
28210 | 2247 and NOWAIT." |
2248 ;; Handle conversion to remote file name syntax and remote ls option | |
2249 ;; capability. | |
2250 (let ((cmd0 (car cmd)) | |
2251 (cmd1 (nth 1 cmd)) | |
2252 (ange-ftp-this-user user) | |
2253 (ange-ftp-this-host host) | |
2254 (ange-ftp-this-msg msg) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2255 cmd2 cmd3 host-type fix-name-func result) |
28210 | 2256 |
2257 (cond | |
30459 | 2258 |
28210 | 2259 ;; pwd case (We don't care what host-type.) |
2260 ((null cmd1)) | |
30459 | 2261 |
28210 | 2262 ;; cmd == 'dir "remote-name" "local-name" "ls-switches" |
2263 ((progn | |
2264 (setq cmd2 (nth 2 cmd) | |
2265 host-type (ange-ftp-host-type host user)) | |
2266 ;; This will trigger an FTP login, if one doesn't exist | |
2267 (eq cmd0 'dir)) | |
2268 (setq cmd1 (funcall | |
2269 (or (cdr (assq host-type ange-ftp-fix-dir-name-func-alist)) | |
2270 'identity) | |
2271 cmd1) | |
2272 cmd3 (nth 3 cmd)) | |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
2273 ;; Need to deal with the HP-UX ftp bug. This should also allow us to |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
2274 ;; resolve symlinks to directories on SysV machines. (Sebastian will |
28210 | 2275 ;; be happy.) |
2276 (and (eq host-type 'unix) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2277 (string-match "/\\'" cmd1) |
28210 | 2278 (not (string-match "R" cmd3)) |
2279 (setq cmd1 (concat cmd1 "."))) | |
2280 | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2281 ;; Using "ls -flags foo" has several problems: |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2282 ;; - if foo is a symlink, we may get a single line showing the symlink |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2283 ;; rather than the listing of the directory it points to. |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2284 ;; - if "foo" has spaces, the parsing of the command may be done wrong. |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2285 ;; - some version of netbsd's ftpd only accept a single argument after |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2286 ;; `ls', which can either be the directory or the flags. |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2287 ;; So to work around those problems, we use "cd foo; ls -flags". |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2288 |
28210 | 2289 ;; If the dir name contains a space, some ftp servers will |
2290 ;; refuse to list it. We instead change directory to the | |
2291 ;; directory in question and ls ".". | |
2292 (when (string-match " " cmd1) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2293 ;; Keep the result. In case of failure, we will (see below) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2294 ;; short-circuit CMD and return this result directly. |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2295 (setq result (ange-ftp-cd host user (nth 1 cmd) 'noerror)) |
28210 | 2296 (setq cmd1 ".")) |
2297 | |
2298 ;; If the remote ls can take switches, put them in | |
45432
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2299 (unless (memq host-type ange-ftp-dumb-host-types) |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2300 (setq cmd0 'ls) |
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2301 ;; We cd and then use `ls' with no directory argument. |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2302 ;; This works around a misfeature of some versions of netbsd ftpd |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2303 ;; where `ls' can only take one argument: either one set of flags |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2304 ;; or a file/directory name. |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
2305 ;; If we're trying to `ls' a single file, this fails since we |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2306 ;; can't cd to a file. We can't fix this problem here, tho, because |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2307 ;; at this point we don't know whether the argument is a file or |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
2308 ;; a directory. Such an `ls' is only ever used (apparently) from |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2309 ;; `insert-directory' when the `full-directory-p' argument is nil |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2310 ;; (which seems to only be used by dired when updating its display |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
2311 ;; after operating on a set of files). So we've changed |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
2312 ;; `ange-ftp-insert-directory' such that in this case it gets |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2313 ;; a full listing of the directory and extracting the line |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2314 ;; corresponding to the requested file. |
45432
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
2315 (unless (equal cmd1 ".") |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2316 (setq result (ange-ftp-cd host user (nth 1 cmd) 'noerror))) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2317 (setq cmd1 cmd3))) |
30459 | 2318 |
28210 | 2319 ;; First argument is the remote name |
2320 ((progn | |
2321 (setq fix-name-func (or (cdr (assq host-type | |
2322 ange-ftp-fix-name-func-alist)) | |
2323 'identity)) | |
2324 (memq cmd0 '(get delete mkdir rmdir cd))) | |
2325 (setq cmd1 (funcall fix-name-func cmd1))) | |
2326 | |
2327 ;; Second argument is the remote name | |
40361
8c6df631e62d
(ange-ftp-send-cmd): Call fix-name-func for
Gerd Moellmann <gerd@gnu.org>
parents:
39888
diff
changeset
|
2328 ((or (memq cmd0 '(append put chmod)) |
105636
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
2329 (and (eq cmd0 'quote) (member cmd1 '("mdtm" "size")))) |
28210 | 2330 (setq cmd2 (funcall fix-name-func cmd2))) |
2331 ;; Both arguments are remote names | |
2332 ((eq cmd0 'rename) | |
2333 (setq cmd1 (funcall fix-name-func cmd1) | |
2334 cmd2 (funcall fix-name-func cmd2)))) | |
30459 | 2335 |
2336 ;; Turn the command into one long string | |
28210 | 2337 (setq cmd0 (symbol-name cmd0)) |
2338 (setq cmd (concat cmd0 | |
2339 (and cmd1 (concat " " cmd1)) | |
2340 (and cmd2 (concat " " cmd2)))) | |
2341 | |
2342 ;; Actually send the resulting command. | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2343 (if (and (consp result) (null (car result))) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2344 ;; `ange-ftp-cd' has failed, so there's no point sending `cmd'. |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2345 result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2346 (let (afsc-result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2347 afsc-line) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2348 (ange-ftp-raw-send-cmd |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2349 (ange-ftp-get-process host user) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2350 cmd |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2351 msg |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2352 (list (lambda (result line host user cmd msg cont nowait) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2353 (or cont (setq afsc-result result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2354 afsc-line line)) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2355 (if result (ange-ftp-call-cont cont result line) |
30459 | 2356 (ange-ftp-raw-send-cmd |
2357 (ange-ftp-get-process host user) | |
2358 cmd | |
2359 msg | |
2360 (list (lambda (result line cont) | |
2361 (or cont (setq afsc-result result | |
2362 afsc-line line)) | |
2363 (ange-ftp-call-cont cont result line)) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2364 cont) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2365 nowait))) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2366 host user cmd msg cont nowait) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2367 nowait) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2368 |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2369 (if nowait |
28210 | 2370 nil |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2371 (if cont |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2372 nil |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2373 (cons afsc-result afsc-line))))))) |
28210 | 2374 |
2375 ;; It might be nice to message users about the host type identified, | |
2376 ;; but there is so much other messaging going on, it would not be | |
2377 ;; seen. No point in slowing things down just so users can read | |
2378 ;; a host type message. | |
2379 | |
2380 (defconst ange-ftp-cms-name-template | |
2381 (concat | |
2382 "^[-A-Z0-9$*][-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?" | |
2383 "[-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?\\.[0-9][0-9][0-9A-Z]$")) | |
2384 (defconst ange-ftp-vms-name-template | |
2385 "^[-A-Z0-9_$]+:\\[[-A-Z0-9_$]+\\(\\.[-A-Z0-9_$]+\\)*\\]$") | |
2386 (defconst ange-ftp-mts-name-template | |
2387 "^[A-Z0-9._][A-Z0-9._][A-Z0-9._][A-Z0-9._]:$") | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2388 (defconst ange-ftp-bs2000-filename-pubset-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2389 ":[A-Z0-9]+:" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2390 "Valid pubset for an BS2000 file name.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2391 (defconst ange-ftp-bs2000-filename-username-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2392 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2393 "\\$[A-Z0-9]*\\.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2394 "Valid username for an BS2000 file name.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2395 (defconst ange-ftp-bs2000-filename-prefix-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2396 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2397 ange-ftp-bs2000-filename-pubset-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2398 ange-ftp-bs2000-filename-username-regexp) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2399 "Valid prefix for an BS2000 file name (pubset and user).") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2400 (defconst ange-ftp-bs2000-name-template |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2401 (concat "^" ange-ftp-bs2000-filename-prefix-regexp "$")) |
28210 | 2402 |
2403 (defun ange-ftp-guess-host-type (host user) | |
42706 | 2404 "Guess the host type of HOST. |
28210 | 2405 Works by doing a pwd and examining the directory syntax." |
2406 (let ((host-type (ange-ftp-host-type host)) | |
2407 (key (concat host "/" user "/~"))) | |
2408 (if (eq host-type 'unix) | |
2409 ;; Note that ange-ftp-host-type returns unix as the default value. | |
2410 (save-match-data | |
2411 (let* ((result (ange-ftp-get-pwd host user)) | |
2412 (dir (car result)) | |
2413 fix-name-func) | |
2414 (cond ((null dir) | |
2415 (message "Warning! Unable to get home directory") | |
2416 (sit-for 1) | |
2417 (if (string-match | |
2418 "^450 No current working directory defined$" | |
2419 (cdr result)) | |
30459 | 2420 |
28210 | 2421 ;; We'll assume that if pwd bombs with this |
2422 ;; error message, then it's CMS. | |
2423 (progn | |
2424 (ange-ftp-add-cms-host host) | |
2425 (setq ange-ftp-host-cache host | |
2426 ange-ftp-host-type-cache 'cms)))) | |
2427 | |
2428 ;; try for VMS | |
2429 ((string-match ange-ftp-vms-name-template dir) | |
2430 (ange-ftp-add-vms-host host) | |
2431 ;; The add-host functions clear the host type cache. | |
2432 ;; Therefore, need to set the cache afterwards. | |
2433 (setq ange-ftp-host-cache host | |
2434 ange-ftp-host-type-cache 'vms)) | |
2435 | |
2436 ;; try for MTS | |
2437 ((string-match ange-ftp-mts-name-template dir) | |
2438 (ange-ftp-add-mts-host host) | |
2439 (setq ange-ftp-host-cache host | |
2440 ange-ftp-host-type-cache 'mts)) | |
30459 | 2441 |
28210 | 2442 ;; try for CMS |
2443 ((string-match ange-ftp-cms-name-template dir) | |
2444 (ange-ftp-add-cms-host host) | |
2445 (setq ange-ftp-host-cache host | |
2446 ange-ftp-host-type-cache 'cms)) | |
2447 | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2448 ;; try for BS2000-POSIX |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2449 ((ange-ftp-bs2000-posix-host host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2450 (ange-ftp-add-bs2000-host host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2451 (setq ange-ftp-host-cache host |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2452 ange-ftp-host-type-cache 'text-unix)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2453 ;; try for BS2000 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2454 ((and (string-match ange-ftp-bs2000-name-template dir) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2455 (not (ange-ftp-bs2000-posix-host host))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2456 (ange-ftp-add-bs2000-host host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2457 (setq ange-ftp-host-cache host |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
2458 ange-ftp-host-type-cache 'bs2000)) |
28210 | 2459 ;; assume UN*X |
2460 (t | |
2461 (setq ange-ftp-host-cache host | |
2462 ange-ftp-host-type-cache 'unix))) | |
2463 | |
2464 ;; Now that we have done a pwd, might as well put it in | |
2465 ;; the expand-dir hashtable. | |
2466 (let ((ange-ftp-this-user user) | |
2467 (ange-ftp-this-host host)) | |
2468 (setq fix-name-func (cdr (assq ange-ftp-host-type-cache | |
2469 ange-ftp-fix-name-func-alist))) | |
2470 (if fix-name-func | |
2471 (setq dir (funcall fix-name-func dir 'reverse)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2472 (puthash key dir ange-ftp-expand-dir-hashtable)))) |
28210 | 2473 |
2474 ;; In the special case of CMS make sure that know the | |
2475 ;; expansion of the home minidisk now, because we will | |
2476 ;; be doing a lot of cd's. | |
2477 (if (and (eq host-type 'cms) | |
2478 (not (ange-ftp-hash-entry-exists-p | |
2479 key ange-ftp-expand-dir-hashtable))) | |
2480 (let ((dir (car (ange-ftp-get-pwd host user)))) | |
2481 (if dir | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2482 (puthash key (concat "/" dir) ange-ftp-expand-dir-hashtable) |
28210 | 2483 (message "Warning! Unable to get home directory") |
2484 (sit-for 1)))))) | |
2485 | |
2486 | |
2487 ;;;; ------------------------------------------------------------ | |
2488 ;;;; Remote file and directory listing support. | |
2489 ;;;; ------------------------------------------------------------ | |
2490 | |
2491 ;; Returns whether HOST's FTP server doesn't like \'ls\' or \'dir\' commands | |
2492 ;; to take switch arguments. | |
2493 (defun ange-ftp-dumb-unix-host (host) | |
2494 (and host ange-ftp-dumb-unix-host-regexp | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2495 (string-match-p ange-ftp-dumb-unix-host-regexp host))) |
28210 | 2496 |
2497 (defun ange-ftp-add-dumb-unix-host (host) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2498 "Interactively add a given HOST to `ange-ftp-dumb-unix-host-regexp'." |
28210 | 2499 (interactive |
2500 (list (read-string "Host: " | |
2501 (let ((name (or (buffer-file-name) default-directory))) | |
2502 (and name (car (ange-ftp-ftp-name name))))))) | |
2503 (if (not (ange-ftp-dumb-unix-host host)) | |
2504 (setq ange-ftp-dumb-unix-host-regexp | |
2505 (concat "^" (regexp-quote host) "$" | |
2506 (and ange-ftp-dumb-unix-host-regexp "\\|") | |
2507 ange-ftp-dumb-unix-host-regexp) | |
2508 ange-ftp-host-cache nil))) | |
2509 | |
2510 (defvar ange-ftp-parse-list-func-alist nil | |
2511 "Alist saying how to parse directory listings for certain OS types. | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2512 Association list of (TYPE . FUNC) pairs. The FUNC is a routine which |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2513 can parse the output from a DIR listing for a host of type TYPE.") |
28210 | 2514 |
2515 ;; With no-error nil, this function returns: | |
2516 ;; an error if file is not an ange-ftp-name | |
30459 | 2517 ;; (This should never happen.) |
28210 | 2518 ;; an error if either the listing is unreadable or there is an ftp error. |
2519 ;; the listing (a string), if everything works. | |
30459 | 2520 ;; |
28210 | 2521 ;; With no-error t, it returns: |
2522 ;; an error if not an ange-ftp-name | |
2523 ;; error if listing is unreadable (most likely caused by a slow connection) | |
2524 ;; nil if ftp error (this is because although asking to list a nonexistent | |
2525 ;; directory on a remote unix machine usually (except | |
2526 ;; maybe for dumb hosts) returns an ls error, but no | |
2527 ;; ftp error, if the same is done on a VMS machine, | |
2528 ;; an ftp error is returned. Need to trap the error | |
2529 ;; so we can go on and try to list the parent.) | |
2530 ;; the listing, if everything works. | |
2531 | |
2532 ;; If WILDCARD is non-nil, then this implements the guts of insert-directory | |
2533 ;; in the wildcard case. Then we make a relative directory listing | |
2534 ;; of FILE within the directory specified by `default-directory'. | |
2535 | |
2536 (defvar ange-ftp-before-parse-ls-hook nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2537 "Normal hook run before parsing the text of an FTP directory listing.") |
28210 | 2538 |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2539 (defvar ange-ftp-after-parse-ls-hook nil |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2540 "Normal hook run after parsing the text of an FTP directory listing.") |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2541 |
28210 | 2542 (defun ange-ftp-ls (file lsargs parse &optional no-error wildcard) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2543 "Return the output of a `DIR' or `ls' command done over FTP. |
28210 | 2544 FILE is the full name of the remote file, LSARGS is any args to pass to the |
2545 `ls' command, and PARSE specifies that the output should be parsed and stored | |
2546 away in the internal cache." | |
47575
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
2547 (when (string-match "^--dired\\s-+" lsargs) |
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
2548 (setq lsargs (replace-match "" nil t lsargs))) |
28210 | 2549 ;; If parse is t, we assume that file is a directory. i.e. we only parse |
2550 ;; full directory listings. | |
2551 (let* ((ange-ftp-this-file (ange-ftp-expand-file-name file)) | |
2552 (parsed (ange-ftp-ftp-name ange-ftp-this-file))) | |
2553 (if parsed | |
2554 (let* ((host (nth 0 parsed)) | |
2555 (user (nth 1 parsed)) | |
2556 (name (ange-ftp-quote-string (nth 2 parsed))) | |
2557 (key (directory-file-name ange-ftp-this-file)) | |
2558 (host-type (ange-ftp-host-type host user)) | |
2559 (dumb (memq host-type ange-ftp-dumb-host-types)) | |
2560 result | |
2561 temp | |
2562 lscmd parse-func) | |
2563 (if (string-equal name "") | |
2564 (setq name | |
2565 (ange-ftp-real-file-name-as-directory | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2566 (ange-ftp-expand-dir host user "~")))) |
28210 | 2567 (if (and ange-ftp-ls-cache-file |
2568 (string-equal key ange-ftp-ls-cache-file) | |
2569 ;; Don't care about lsargs for dumb hosts. | |
2570 (or dumb (string-equal lsargs ange-ftp-ls-cache-lsargs))) | |
2571 ange-ftp-ls-cache-res | |
2572 (setq temp (ange-ftp-make-tmp-name host)) | |
2573 (if wildcard | |
2574 (progn | |
2575 (ange-ftp-cd host user (file-name-directory name)) | |
75552
4144cd078a1d
* files.el (get-free-disk-space): Return nil for remote
Michael Albinus <michael.albinus@gmx.de>
parents:
75347
diff
changeset
|
2576 (setq lscmd (list 'ls file temp lsargs))) |
28210 | 2577 (setq lscmd (list 'dir name temp lsargs))) |
2578 (unwind-protect | |
2579 (if (car (setq result (ange-ftp-send-cmd | |
2580 host | |
2581 user | |
2582 lscmd | |
2583 (format "Listing %s" | |
2584 (ange-ftp-abbreviate-filename | |
2585 ange-ftp-this-file))))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2586 (with-current-buffer (get-buffer-create |
65814
967a91879fee
(ange-ftp-ls): Fix typo introduced in last change.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65810
diff
changeset
|
2587 ange-ftp-data-buffer-name) |
28210 | 2588 (erase-buffer) |
2589 (if (ange-ftp-real-file-readable-p temp) | |
2590 (ange-ftp-real-insert-file-contents temp) | |
2591 (sleep-for ange-ftp-retry-time) | |
2592 ;wait for file to possibly appear | |
2593 (if (ange-ftp-real-file-readable-p temp) | |
2594 ;; Try again. | |
2595 (ange-ftp-real-insert-file-contents temp) | |
2596 (ange-ftp-error host user | |
2597 (format | |
2598 "list data file %s not readable" | |
2599 temp)))) | |
30518
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2600 ;; remove ^M inserted by the win32 ftp client |
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2601 (while (re-search-forward "\r$" nil t) |
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2602 (replace-match "")) |
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
2603 (goto-char 1) |
28210 | 2604 (run-hooks 'ange-ftp-before-parse-ls-hook) |
2605 (if parse | |
2606 (ange-ftp-set-files | |
2607 ange-ftp-this-file | |
2608 (if (setq | |
2609 parse-func | |
2610 (cdr (assq host-type | |
2611 ange-ftp-parse-list-func-alist))) | |
2612 (funcall parse-func) | |
2613 (ange-ftp-parse-dired-listing lsargs)))) | |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2614 ;; Place this hook here to convert the contents of the |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2615 ;; buffer to a ls compatible format if the host system |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2616 ;; that is being queried is other than Unix i.e. VMS |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2617 ;; returns an ls format that really sucks. |
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
2618 (run-hooks 'ange-ftp-after-parse-ls-hook) |
28210 | 2619 (setq ange-ftp-ls-cache-file key |
2620 ange-ftp-ls-cache-lsargs lsargs | |
2621 ; For dumb hosts-types this is | |
2622 ; meaningless but harmless. | |
2623 ange-ftp-ls-cache-res (buffer-string)) | |
2624 ;; (kill-buffer (current-buffer)) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2625 (if (equal ange-ftp-ls-cache-res "total 0\n") |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2626 ;; wu-ftpd seems to return a successful result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2627 ;; with an empty file-listing when doing a |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2628 ;; `DIR /some/file/.' which leads ange-ftp to |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2629 ;; believe that /some/file is a directory ;-( |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2630 nil |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2631 ange-ftp-ls-cache-res)) |
28210 | 2632 (if no-error |
2633 nil | |
2634 (ange-ftp-error host user | |
2635 (concat "DIR failed: " (cdr result))))) | |
2636 (ange-ftp-del-tmp-name temp)))) | |
2637 (error "Should never happen. Please report. Bug ref. no.: 1")))) | |
2638 | |
2639 ;;;; ------------------------------------------------------------ | |
2640 ;;;; Directory information caching support. | |
2641 ;;;; ------------------------------------------------------------ | |
2642 | |
2643 (defvar ange-ftp-add-file-entry-alist nil | |
2644 "Alist saying how to add file entries on certain OS types. | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2645 Association list of pairs (TYPE . FUNC), where FUNC is a function |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2646 to be used to add a file entry for the OS TYPE. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2647 The main reason for this alist is to deal with file versions in VMS.") |
28210 | 2648 |
2649 (defvar ange-ftp-delete-file-entry-alist nil | |
2650 "Alist saying how to delete files on certain OS types. | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2651 Association list of pairs (TYPE . FUNC), where FUNC is a function |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2652 to be used to delete a file entry for the OS TYPE. |
28210 | 2653 The main reason for this alist is to deal with file versions in VMS.") |
2654 | |
2655 (defun ange-ftp-add-file-entry (name &optional dir-p) | |
2656 "Add a file entry for file NAME, if its directory info exists." | |
2657 (funcall (or (cdr (assq (ange-ftp-host-type | |
2658 (car (ange-ftp-ftp-name name))) | |
2659 ange-ftp-add-file-entry-alist)) | |
2660 'ange-ftp-internal-add-file-entry) | |
2661 name dir-p) | |
2662 (setq ange-ftp-ls-cache-file nil)) | |
2663 | |
2664 (defun ange-ftp-delete-file-entry (name &optional dir-p) | |
2665 "Delete the file entry for file NAME, if its directory info exists." | |
2666 (funcall (or (cdr (assq (ange-ftp-host-type | |
2667 (car (ange-ftp-ftp-name name))) | |
2668 ange-ftp-delete-file-entry-alist)) | |
2669 'ange-ftp-internal-delete-file-entry) | |
2670 name dir-p) | |
2671 (setq ange-ftp-ls-cache-file nil)) | |
2672 | |
2673 (defmacro ange-ftp-parse-filename () | |
2674 ;;Extract the filename from the current line of a dired-like listing. | |
106309
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
2675 `(save-match-data |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
2676 (let ((eol (progn (end-of-line) (point)))) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
2677 (beginning-of-line) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
2678 (if (re-search-forward directory-listing-before-filename-regexp eol t) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
2679 (buffer-substring (point) eol))))) |
30459 | 2680 |
28210 | 2681 ;; This deals with the F switch. Should also do something about |
2682 ;; unquoting names obtained with the SysV b switch and the GNU Q | |
2683 ;; switch. See Sebastian's dired-get-filename. | |
2684 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2685 (defun ange-ftp-ls-parser (switches) |
28210 | 2686 ;; Meant to be called by ange-ftp-parse-dired-listing |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2687 (let ((tbl (make-hash-table :test 'equal)) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2688 (used-F (and (stringp switches) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2689 (string-match "F" switches))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2690 file-type symlink directory file) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2691 (while (setq file (ange-ftp-parse-filename)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2692 (beginning-of-line) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2693 (skip-chars-forward "\t 0-9") |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2694 (setq file-type (following-char) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2695 directory (eq file-type ?d)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2696 (if (eq file-type ?l) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2697 (let ((end (string-match " -> " file))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2698 (if end |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2699 ;; Sometimes `ls' appends a @ at the end of the target. |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2700 (setq symlink (substring file (match-end 0) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2701 (string-match "@\\'" file)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2702 file (substring file 0 end)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2703 ;; Shouldn't happen |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2704 (setq symlink ""))) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2705 (setq symlink nil)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2706 ;; Only do a costly regexp search if the F switch was used. |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2707 (if (and used-F |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2708 (not (string-equal file "")) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2709 (looking-at |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2710 ".[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)")) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2711 (let ((socket (eq file-type ?s)) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2712 (executable |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2713 (and (not symlink) ; x bits don't mean a thing for symlinks |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2714 (string-match |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2715 "[xst]" |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2716 (concat (match-string 1) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2717 (match-string 2) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2718 (match-string 3)))))) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2719 ;; Some ls's with the F switch mark symlinks with an @ (ULTRIX) |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2720 ;; and others don't. (sigh...) Beware, that some Unix's don't |
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2721 ;; seem to believe in the F-switch |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2722 (if (or (and symlink (string-match "@\\'" file)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2723 (and directory (string-match "/\\'" file)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2724 (and executable (string-match "*\\'" file)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
2725 (and socket (string-match "=\\'" file))) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2726 (setq file (substring file 0 -1))))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2727 (puthash file (or symlink directory) tbl) |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
2728 (forward-line 1)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2729 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2730 (puthash ".." t tbl) |
30459 | 2731 tbl)) |
28210 | 2732 |
2733 ;;; The dl stuff for descriptive listings | |
2734 | |
2735 (defvar ange-ftp-dl-dir-regexp nil | |
2736 "Regexp matching directories which are listed in dl format. | |
2737 This regexp should not be anchored with a trailing `$', because it should | |
2738 match subdirectories as well.") | |
2739 | |
2740 (defun ange-ftp-add-dl-dir (dir) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2741 "Interactively add a DIR to `ange-ftp-dl-dir-regexp'." |
28210 | 2742 (interactive |
2743 (list (read-string "Directory: " | |
2744 (let ((name (or (buffer-file-name) default-directory))) | |
2745 (and name (ange-ftp-ftp-name name) | |
2746 (file-name-directory name)))))) | |
2747 (if (not (and ange-ftp-dl-dir-regexp | |
2748 (string-match ange-ftp-dl-dir-regexp dir))) | |
2749 (setq ange-ftp-dl-dir-regexp | |
2750 (concat "^" (regexp-quote dir) | |
2751 (and ange-ftp-dl-dir-regexp "\\|") | |
2752 ange-ftp-dl-dir-regexp)))) | |
2753 | |
2754 (defmacro ange-ftp-dl-parser () | |
2755 ;; Parse the current buffer, which is assumed to be a descriptive | |
2756 ;; listing, and return a hashtable. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2757 `(let ((tbl (make-hash-table :test 'equal))) |
30459 | 2758 (while (not (eobp)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2759 (puthash |
30459 | 2760 (buffer-substring (point) |
2761 (progn | |
2762 (skip-chars-forward "^ /\n") | |
2763 (point))) | |
2764 (eq (following-char) ?/) | |
2765 tbl) | |
2766 (forward-line 1)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2767 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2768 (puthash ".." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2769 tbl)) |
28210 | 2770 |
2771 ;; Parse the current buffer which is assumed to be in a dired-like listing | |
2772 ;; format, and return a hashtable as the result. If the listing is not really | |
2773 ;; a listing, then return nil. | |
2774 | |
2775 (defun ange-ftp-parse-dired-listing (&optional switches) | |
2776 (save-match-data | |
2777 (cond | |
2778 ((looking-at "^total [0-9]+$") | |
2779 (forward-line 1) | |
2780 ;; Some systems put in a blank line here. | |
2781 (if (eolp) (forward-line 1)) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2782 (ange-ftp-ls-parser switches)) |
28210 | 2783 ((looking-at "[^\n]+\\( not found\\|: Not a directory\\)\n\\'") |
2784 ;; It's an ls error message. | |
2785 nil) | |
2786 ((eobp) ; i.e. (zerop (buffer-size)) | |
2787 ;; This could be one of: | |
2788 ;; (1) An Ultrix ls error message | |
2789 ;; (2) A listing with the A switch of an empty directory | |
2790 ;; on a machine which doesn't give a total line. | |
2791 ;; (3) The twilight zone. | |
2792 ;; We'll assume (1) for now. | |
2793 nil) | |
66325
fda96ff4c7e5
* files.el (directory-listing-before-filename-regexp): New
Michael Albinus <michael.albinus@gmx.de>
parents:
66256
diff
changeset
|
2794 ((re-search-forward directory-listing-before-filename-regexp nil t) |
28210 | 2795 (beginning-of-line) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2796 (ange-ftp-ls-parser switches)) |
28210 | 2797 ((re-search-forward "^[^ \n\t]+ +\\([0-9]+\\|-\\|=\\) " nil t) |
2798 ;; It's a dl listing (I hope). | |
2799 ;; file is bound by the call to ange-ftp-ls | |
2800 (ange-ftp-add-dl-dir ange-ftp-this-file) | |
2801 (beginning-of-line) | |
2802 (ange-ftp-dl-parser)) | |
2803 (t nil)))) | |
2804 | |
2805 (defun ange-ftp-set-files (directory files) | |
2806 "For a given DIRECTORY, set or change the associated FILES hashtable." | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2807 (and files (puthash (file-name-as-directory directory) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2808 files ange-ftp-files-hashtable))) |
28210 | 2809 |
2810 (defun ange-ftp-get-files (directory &optional no-error) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2811 "Given a DIRECTORY, return a hashtable of file entries. |
28210 | 2812 This will give an error or return nil, depending on the value of |
2813 NO-ERROR, if a listing for DIRECTORY cannot be obtained." | |
2814 (setq directory (file-name-as-directory directory)) ;normalize | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2815 (or (gethash directory ange-ftp-files-hashtable) |
28210 | 2816 (save-match-data |
2817 (and (ange-ftp-ls directory | |
2818 ;; This is an efficiency hack. We try to | |
2819 ;; anticipate what sort of listing dired | |
2820 ;; might want, and cache just such a listing. | |
2821 (if (and (boundp 'dired-actual-switches) | |
2822 (stringp dired-actual-switches) | |
2823 ;; We allow the A switch, which lists | |
2824 ;; all files except "." and "..". | |
2825 ;; This is OK because we manually | |
2826 ;; insert these entries | |
2827 ;; in the hash table. | |
2828 (string-match | |
2829 "[aA]" dired-actual-switches) | |
2830 (string-match | |
2831 "l" dired-actual-switches) | |
2832 (not (string-match | |
2833 "R" dired-actual-switches))) | |
2834 dired-actual-switches | |
2835 (if (and (boundp 'dired-listing-switches) | |
2836 (stringp dired-listing-switches) | |
2837 (string-match | |
2838 "[aA]" dired-listing-switches) | |
2839 (string-match | |
2840 "l" dired-listing-switches) | |
2841 (not (string-match | |
2842 "R" dired-listing-switches))) | |
2843 dired-listing-switches | |
2844 "-al")) | |
2845 t no-error) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2846 (gethash directory ange-ftp-files-hashtable))))) |
28210 | 2847 |
2848 ;; Given NAME, return the file part that can be used for looking up the | |
2849 ;; file's entry in a hashtable. | |
2850 (defmacro ange-ftp-get-file-part (name) | |
30459 | 2851 `(let ((file (file-name-nondirectory ,name))) |
2852 (if (string-equal file "") | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2853 "." |
30459 | 2854 file))) |
28210 | 2855 |
2856 ;; Return whether ange-ftp-file-entry-p and ange-ftp-get-file-entry are | |
2857 ;; allowed to determine if NAME is a sub-directory by listing it directly, | |
2858 ;; rather than listing its parent directory. This is used for efficiency so | |
2859 ;; that a wasted listing is not done: | |
2860 ;; 1. When looking for a .dired file in dired-x.el. | |
2861 ;; 2. The syntax of FILE and DIR make it impossible that FILE could be a valid | |
2862 ;; subdirectory. This is of course an OS dependent judgement. | |
2863 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
2864 (defvar dired-local-variables-file) |
28210 | 2865 (defmacro ange-ftp-allow-child-lookup (dir file) |
45459
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2866 `(not |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2867 (let* ((efile ,file) ; expand once. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2868 (edir ,dir) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2869 (parsed (ange-ftp-ftp-name edir)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2870 (host-type (ange-ftp-host-type |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2871 (car parsed)))) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2872 (or |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2873 ;; Deal with dired |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2874 (and (boundp 'dired-local-variables-file) ; in the dired-x package |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2875 (stringp dired-local-variables-file) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2876 (string-equal dired-local-variables-file efile)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2877 ;; No dots in dir names in vms. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2878 (and (eq host-type 'vms) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2879 (string-match "\\." efile)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2880 ;; No subdirs in mts of cms. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2881 (and (memq host-type '(mts cms)) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2882 (not (string-equal "/" (nth 2 parsed)))) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2883 ;; No dots in pseudo-dir names in bs2000. |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2884 (and (eq host-type 'bs2000) |
d9e7dc0ccc84
(ange-ftp-allow-child-lookup): Re-enable since
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45432
diff
changeset
|
2885 (string-match "\\." efile)))))) |
28210 | 2886 |
2887 (defun ange-ftp-file-entry-p (name) | |
2888 "Given NAME, return whether there is a file entry for it." | |
2889 (let* ((name (directory-file-name name)) | |
2890 (dir (file-name-directory name)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2891 (ent (gethash dir ange-ftp-files-hashtable)) |
28210 | 2892 (file (ange-ftp-get-file-part name))) |
2893 (if ent | |
2894 (ange-ftp-hash-entry-exists-p file ent) | |
2895 (or (and (ange-ftp-allow-child-lookup dir file) | |
2896 (setq ent (ange-ftp-get-files name t)) | |
2897 ;; Try a child lookup. i.e. try to list file as a | |
2898 ;; subdirectory of dir. This is a good idea because | |
2899 ;; we may not have read permission for file's parent. Also, | |
2900 ;; people tend to work down directory trees anyway. We use | |
2901 ;; no-error ;; because if file does not exist as a subdir., | |
2902 ;; then dumb hosts will give an ftp error. Smart unix hosts | |
2903 ;; will simply send back the ls | |
2904 ;; error message. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2905 (gethash "." ent)) |
28210 | 2906 ;; Child lookup failed, so try the parent. |
56742
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
2907 (ange-ftp-hash-entry-exists-p |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
2908 file (ange-ftp-get-files dir 'no-error)))))) |
28210 | 2909 |
2910 (defun ange-ftp-get-file-entry (name) | |
2911 "Given NAME, return the given file entry. | |
2912 The entry will be either t for a directory, nil for a normal file, | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2913 or a string for a symlink. If the file isn't in the hashtable, |
28210 | 2914 this also returns nil." |
2915 (let* ((name (directory-file-name name)) | |
2916 (dir (file-name-directory name)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2917 (ent (gethash dir ange-ftp-files-hashtable)) |
28210 | 2918 (file (ange-ftp-get-file-part name))) |
2919 (if ent | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2920 (gethash file ent) |
28210 | 2921 (or (and (ange-ftp-allow-child-lookup dir file) |
2922 (setq ent (ange-ftp-get-files name t)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2923 (gethash "." ent)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2924 ;; i.e. it's a directory by child lookup |
49805
6e4a6658cec0
(ange-ftp-get-file-entry): Allow for graceful
David Kastrup <dak@gnu.org>
parents:
49598
diff
changeset
|
2925 (and (setq ent (ange-ftp-get-files dir t)) |
6e4a6658cec0
(ange-ftp-get-file-entry): Allow for graceful
David Kastrup <dak@gnu.org>
parents:
49598
diff
changeset
|
2926 (gethash file ent)))))) |
28210 | 2927 |
2928 (defun ange-ftp-internal-delete-file-entry (name &optional dir-p) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2929 (when dir-p |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2930 (setq name (file-name-as-directory name)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2931 (remhash name ange-ftp-files-hashtable) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2932 (setq name (directory-file-name name))) |
28210 | 2933 ;; Note that file-name-as-directory followed by directory-file-name |
2934 ;; serves to canonicalize directory file names to their unix form. | |
2935 ;; i.e. in VMS, FOO.DIR -> FOO/ -> FOO | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2936 (let ((files (gethash (file-name-directory name) ange-ftp-files-hashtable))) |
28210 | 2937 (if files |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2938 (remhash (ange-ftp-get-file-part name) files)))) |
28210 | 2939 |
2940 (defun ange-ftp-internal-add-file-entry (name &optional dir-p) | |
2941 (and dir-p | |
2942 (setq name (directory-file-name name))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2943 (let ((files (gethash (file-name-directory name) ange-ftp-files-hashtable))) |
28210 | 2944 (if files |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2945 (puthash (ange-ftp-get-file-part name) dir-p files)))) |
28210 | 2946 |
2947 (defun ange-ftp-wipe-file-entries (host user) | |
2948 "Get rid of entry for HOST, USER pair from file entry information hashtable." | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2949 (let ((new-tbl (make-hash-table :test 'equal |
46892
6e8123be5cab
(ange-ftp-wipe-file-entries): Fix type mismatch;
David Kastrup <dak@gnu.org>
parents:
46811
diff
changeset
|
2950 :size (hash-table-size |
6e8123be5cab
(ange-ftp-wipe-file-entries): Fix type mismatch;
David Kastrup <dak@gnu.org>
parents:
46811
diff
changeset
|
2951 ange-ftp-files-hashtable)))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2952 (maphash |
30459 | 2953 (lambda (key val) |
2954 (let ((parsed (ange-ftp-ftp-name key))) | |
2955 (if parsed | |
2956 (let ((h (nth 0 parsed)) | |
2957 (u (nth 1 parsed))) | |
2958 (or (and (equal host h) (equal user u)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
2959 (puthash key val new-tbl)))))) |
28210 | 2960 ange-ftp-files-hashtable) |
2961 (setq ange-ftp-files-hashtable new-tbl))) | |
2962 | |
2963 ;;;; ------------------------------------------------------------ | |
2964 ;;;; File transfer mode support. | |
2965 ;;;; ------------------------------------------------------------ | |
2966 | |
2967 (defun ange-ftp-set-binary-mode (host user) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2968 "Tell the FTP process for the given HOST & USER to switch to binary mode." |
105636
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
2969 ;; FIXME: We should keep track of the current mode, so as to avoid |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
2970 ;; unnecessary roundtrips. |
28210 | 2971 (let ((result (ange-ftp-send-cmd host user '(type "binary")))) |
2972 (if (not (car result)) | |
2973 (ange-ftp-error host user (concat "BINARY failed: " (cdr result))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2974 (with-current-buffer (process-buffer (ange-ftp-get-process host user)) |
28210 | 2975 (and ange-ftp-binary-hash-mark-size |
2976 (setq ange-ftp-hash-mark-unit | |
2977 (ash ange-ftp-binary-hash-mark-size -4))))))) | |
2978 | |
2979 (defun ange-ftp-set-ascii-mode (host user) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2980 "Tell the FTP process for the given HOST & USER to switch to ASCII mode." |
105636
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
2981 ;; FIXME: We should keep track of the current mode, so as to avoid |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
2982 ;; unnecessary roundtrips. |
28210 | 2983 (let ((result (ange-ftp-send-cmd host user '(type "ascii")))) |
2984 (if (not (car result)) | |
2985 (ange-ftp-error host user (concat "ASCII failed: " (cdr result))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
2986 (with-current-buffer (process-buffer (ange-ftp-get-process host user)) |
28210 | 2987 (and ange-ftp-ascii-hash-mark-size |
2988 (setq ange-ftp-hash-mark-unit | |
2989 (ash ange-ftp-ascii-hash-mark-size -4))))))) | |
2990 | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2991 (defun ange-ftp-cd (host user dir &optional noerror) |
28210 | 2992 (let ((result (ange-ftp-send-cmd host user (list 'cd dir) "Doing CD"))) |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2993 (if noerror result |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2994 (or (car result) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
2995 (ange-ftp-error host user (concat "CD failed: " (cdr result))))))) |
28210 | 2996 |
2997 (defun ange-ftp-get-pwd (host user) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2998 "Attempt to get the current working directory for the given HOST/USER pair. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
2999 Returns (DIR . LINE) where DIR is either the directory or nil if not found, |
28210 | 3000 and LINE is the relevant success or fail line from the FTP-client." |
3001 (let* ((result (ange-ftp-send-cmd host user '(pwd) "Getting PWD")) | |
3002 (line (cdr result)) | |
3003 dir) | |
3004 (if (car result) | |
3005 (save-match-data | |
3006 (and (or (string-match "\"\\([^\"]*\\)\"" line) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3007 (string-match " \\([^ ]+\\) " line)) ; stone-age VMS servers! |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3008 (setq dir (match-string 1 line))))) |
28210 | 3009 (cons dir line))) |
3010 | |
3011 ;;; ------------------------------------------------------------ | |
3012 ;;; expand-file-name and friends...which currently don't work | |
3013 ;;; ------------------------------------------------------------ | |
3014 | |
3015 (defun ange-ftp-expand-dir (host user dir) | |
3016 "Return the result of doing a PWD in the current FTP session. | |
3017 Use the connection to machine HOST | |
3018 logged in as user USER and cd'd to directory DIR." | |
3019 (let* ((host-type (ange-ftp-host-type host user)) | |
3020 ;; It is more efficient to call ange-ftp-host-type | |
3021 ;; before binding res, because ange-ftp-host-type sometimes | |
3022 ;; adds to the info in the expand-dir-hashtable. | |
3023 (fix-name-func | |
3024 (cdr (assq host-type ange-ftp-fix-name-func-alist))) | |
3025 (key (concat host "/" user "/" dir)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3026 (res (gethash key ange-ftp-expand-dir-hashtable))) |
28210 | 3027 (or res |
3028 (progn | |
3029 (or | |
3030 (string-equal user "anonymous") | |
3031 (string-equal user "ftp") | |
3032 (not (eq host-type 'unix)) | |
3033 (let* ((ange-ftp-good-msgs (concat ange-ftp-expand-dir-regexp | |
3034 "\\|" | |
3035 ange-ftp-good-msgs)) | |
3036 (result (ange-ftp-send-cmd host user | |
3037 (list 'get dir null-device) | |
3038 (format "expanding %s" dir))) | |
3039 (line (cdr result))) | |
3040 (setq res | |
3041 (if (string-match ange-ftp-expand-dir-regexp line) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3042 (match-string 1 line))))) |
28210 | 3043 (or res |
3044 (if (string-equal dir "~") | |
3045 (setq res (car (ange-ftp-get-pwd host user))) | |
3046 (let ((home (ange-ftp-expand-dir host user "~"))) | |
3047 (unwind-protect | |
3048 (and (ange-ftp-cd host user dir) | |
3049 (setq res (car (ange-ftp-get-pwd host user)))) | |
3050 (ange-ftp-cd host user home))))) | |
3051 (if res | |
3052 (let ((ange-ftp-this-user user) | |
3053 (ange-ftp-this-host host)) | |
3054 (if fix-name-func | |
3055 (setq res (funcall fix-name-func res 'reverse))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3056 (puthash key res ange-ftp-expand-dir-hashtable))) |
28210 | 3057 res)))) |
3058 | |
3059 (defun ange-ftp-canonize-filename (n) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3060 "Take a string N and short-circuit //, /. and /.." |
28210 | 3061 (if (string-match "[^:]+//" n) ;don't upset Apollo users |
3062 (setq n (substring n (1- (match-end 0))))) | |
3063 (let ((parsed (ange-ftp-ftp-name n))) | |
3064 (if parsed | |
3065 (let ((host (car parsed)) | |
3066 (user (nth 1 parsed)) | |
3067 (name (nth 2 parsed))) | |
30459 | 3068 |
28210 | 3069 ;; See if remote name is absolute. If so then just expand it and |
3070 ;; replace the name component of the overall name. | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3071 (cond ((string-match "\\`/" name) |
28210 | 3072 name) |
30459 | 3073 |
28210 | 3074 ;; Name starts with ~ or ~user. Resolve that part of the name |
3075 ;; making it absolute then re-expand it. | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3076 ((string-match "\\`~[^/]*" name) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3077 (let* ((tilda (match-string 0 name)) |
28210 | 3078 (rest (substring name (match-end 0))) |
3079 (dir (ange-ftp-expand-dir host user tilda))) | |
3080 (if dir | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3081 ;; C-x d /ftp:anonymous@ftp.gnu.org:~/ RET |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3082 ;; seems to cause `rest' to sometimes be empty. |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3083 ;; Maybe it's an error for `rest' to be empty here, |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3084 ;; but until we figure this out, this quick fix |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3085 ;; seems to do the trick. |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3086 (setq name (cond ((string-equal rest "") dir) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3087 ((string-equal dir "/") rest) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3088 (t (concat dir rest)))) |
30459 | 3089 (error "User \"%s\" is not known" |
28210 | 3090 (substring tilda 1))))) |
30459 | 3091 |
28210 | 3092 ;; relative name. Tack on homedir and re-expand. |
3093 (t | |
3094 (let ((dir (ange-ftp-expand-dir host user "~"))) | |
3095 (if dir | |
3096 (setq name (concat | |
3097 (ange-ftp-real-file-name-as-directory dir) | |
3098 name)) | |
3099 (error "Unable to obtain CWD"))))) | |
30459 | 3100 |
28210 | 3101 ;; If name starts with //, preserve that, for apollo system. |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3102 (unless (string-match "\\`//" name) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3103 (if (not (eq system-type 'windows-nt)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3104 (setq name (ange-ftp-real-expand-file-name name)) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3105 ;; Windows UNC default dirs do not make sense for ftp. |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3106 (setq name (if (string-match "\\`//" default-directory) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3107 (ange-ftp-real-expand-file-name name "c:/") |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3108 (ange-ftp-real-expand-file-name name))) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3109 ;; Strip off possible drive specifier. |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3110 (if (string-match "\\`[a-zA-Z]:" name) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3111 (setq name (substring name 2)))) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3112 (if (string-match "\\`//" name) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3113 (setq name (substring name 1)))) |
30459 | 3114 |
28210 | 3115 ;; Now substitute the expanded name back into the overall filename. |
3116 (ange-ftp-replace-name-component n name)) | |
30459 | 3117 |
28210 | 3118 ;; non-ange-ftp name. Just expand normally. |
3119 (if (eq (string-to-char n) ?/) | |
3120 (ange-ftp-real-expand-file-name n) | |
3121 (ange-ftp-real-expand-file-name | |
3122 (ange-ftp-real-file-name-nondirectory n) | |
3123 (ange-ftp-real-file-name-directory n)))))) | |
3124 | |
3125 (defun ange-ftp-expand-file-name (name &optional default) | |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
3126 "Documented as `expand-file-name'." |
28210 | 3127 (save-match-data |
3128 (setq default (or default default-directory)) | |
3129 (cond ((eq (string-to-char name) ?~) | |
3130 (ange-ftp-real-expand-file-name name)) | |
3131 ((eq (string-to-char name) ?/) | |
3132 (ange-ftp-canonize-filename name)) | |
3133 ((and (eq system-type 'windows-nt) | |
3134 (eq (string-to-char name) ?\\)) | |
3135 (ange-ftp-canonize-filename name)) | |
3136 ((and (eq system-type 'windows-nt) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3137 (or (string-match "\\`[a-zA-Z]:" name) |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3138 (string-match "\\`[a-zA-Z]:" default))) |
28210 | 3139 (ange-ftp-real-expand-file-name name default)) |
3140 ((zerop (length name)) | |
3141 (ange-ftp-canonize-filename default)) | |
3142 ((ange-ftp-canonize-filename | |
3143 (concat (file-name-as-directory default) name)))))) | |
3144 | |
3145 ;;; These are problems--they are currently not enabled. | |
3146 | |
3147 (defvar ange-ftp-file-name-as-directory-alist nil | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3148 "Association list of (TYPE . FUNC) pairs. |
28210 | 3149 FUNC converts a filename to a directory name for the operating |
3150 system TYPE.") | |
3151 | |
3152 (defun ange-ftp-file-name-as-directory (name) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3153 "Documented as `file-name-as-directory'." |
28210 | 3154 (let ((parsed (ange-ftp-ftp-name name))) |
3155 (if parsed | |
3156 (if (string-equal (nth 2 parsed) "") | |
3157 name | |
3158 (funcall (or (cdr (assq | |
3159 (ange-ftp-host-type (car parsed)) | |
3160 ange-ftp-file-name-as-directory-alist)) | |
3161 'ange-ftp-real-file-name-as-directory) | |
3162 name)) | |
3163 (ange-ftp-real-file-name-as-directory name)))) | |
30459 | 3164 |
28210 | 3165 (defun ange-ftp-file-name-directory (name) |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3166 "Documented as `file-name-directory'." |
28210 | 3167 (let ((parsed (ange-ftp-ftp-name name))) |
3168 (if parsed | |
3169 (let ((filename (nth 2 parsed))) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3170 (if (string-match-p "\\`~[^/]*\\'" filename) |
28210 | 3171 name |
3172 (ange-ftp-replace-name-component | |
3173 name | |
3174 (ange-ftp-real-file-name-directory filename)))) | |
3175 (ange-ftp-real-file-name-directory name)))) | |
3176 | |
3177 (defun ange-ftp-file-name-nondirectory (name) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3178 "Documented as `file-name-nondirectory'." |
28210 | 3179 (let ((parsed (ange-ftp-ftp-name name))) |
3180 (if parsed | |
3181 (let ((filename (nth 2 parsed))) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3182 (if (string-match-p "\\`~[^/]*\\'" filename) |
28210 | 3183 "" |
3184 (ange-ftp-real-file-name-nondirectory filename))) | |
3185 (ange-ftp-real-file-name-nondirectory name)))) | |
3186 | |
3187 (defun ange-ftp-directory-file-name (dir) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3188 "Documented as `directory-file-name'." |
28210 | 3189 (let ((parsed (ange-ftp-ftp-name dir))) |
3190 (if parsed | |
3191 (ange-ftp-replace-name-component | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3192 dir |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3193 (ange-ftp-real-directory-file-name (nth 2 parsed))) |
28210 | 3194 (ange-ftp-real-directory-file-name dir)))) |
3195 | |
3196 | |
3197 ;;; Hooks that handle Emacs primitives. | |
3198 | |
3199 ;; Returns non-nil if should transfer FILE in binary mode. | |
3200 (defun ange-ftp-binary-file (file) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3201 (string-match-p ange-ftp-binary-file-name-regexp file)) |
28210 | 3202 |
3203 (defun ange-ftp-write-region (start end filename &optional append visit) | |
3204 (setq filename (expand-file-name filename)) | |
3205 (let ((parsed (ange-ftp-ftp-name filename))) | |
3206 (if parsed | |
3207 (let* ((host (nth 0 parsed)) | |
3208 (user (nth 1 parsed)) | |
3209 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3210 (temp (ange-ftp-make-tmp-name host)) | |
3211 ;; What we REALLY need here is a way to determine if the mode | |
3212 ;; of the transfer is irrelevant, i.e. we can use binary mode | |
3213 ;; regardless. Maybe a system-type to host-type lookup? | |
3214 (binary (or (ange-ftp-binary-file filename) | |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3215 (and (not (memq system-type |
104552
10c38084881d
Remove code for defunct system-types emx, macos, mswindows,
Glenn Morris <rgm@gnu.org>
parents:
102850
diff
changeset
|
3216 '(ms-dos windows-nt))) |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3217 (memq (ange-ftp-host-type host user) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3218 '(unix dumb-unix))))) |
28210 | 3219 (cmd (if append 'append 'put)) |
3220 (abbr (ange-ftp-abbreviate-filename filename)) | |
3221 ;; we need to reset `last-coding-system-used' to its | |
3222 ;; value immediately after calling the real write-region, | |
3223 ;; so that `basic-save-buffer' doesn't see whatever value | |
3224 ;; might be used when communicating with the ftp process. | |
3225 (coding-system-used last-coding-system-used)) | |
3226 (unwind-protect | |
3227 (progn | |
46336
af464c20ffb2
(ange-ftp-write-region): Don't bind executing-kbd-macro; instead, pass
Richard M. Stallman <rms@gnu.org>
parents:
46178
diff
changeset
|
3228 (let ((filename (buffer-file-name)) |
28210 | 3229 (mod-p (buffer-modified-p))) |
3230 (unwind-protect | |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3231 (progn |
46336
af464c20ffb2
(ange-ftp-write-region): Don't bind executing-kbd-macro; instead, pass
Richard M. Stallman <rms@gnu.org>
parents:
46178
diff
changeset
|
3232 (ange-ftp-real-write-region start end temp nil |
af464c20ffb2
(ange-ftp-write-region): Don't bind executing-kbd-macro; instead, pass
Richard M. Stallman <rms@gnu.org>
parents:
46178
diff
changeset
|
3233 (or visit 'quiet)) |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3234 (setq coding-system-used last-coding-system-used)) |
28210 | 3235 ;; cleanup forms |
37774
a3b587b05ab3
(ange-ftp-write-region): Make sure to record the
Gerd Moellmann <gerd@gnu.org>
parents:
33539
diff
changeset
|
3236 (setq coding-system-used last-coding-system-used) |
28210 | 3237 (setq buffer-file-name filename) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
3238 (restore-buffer-modified-p mod-p))) |
28210 | 3239 (if binary |
3240 (ange-ftp-set-binary-mode host user)) | |
3241 | |
3242 ;; tell the process filter what size the transfer will be. | |
3243 (let ((attr (file-attributes temp))) | |
3244 (if attr | |
3245 (ange-ftp-set-xfer-size host user (nth 7 attr)))) | |
3246 | |
3247 ;; put or append the file. | |
3248 (let ((result (ange-ftp-send-cmd host user | |
3249 (list cmd temp name) | |
3250 (format "Writing %s" abbr)))) | |
3251 (or (car result) | |
3252 (signal 'ftp-error | |
3253 (list | |
3254 "Opening output file" | |
3255 (format "FTP Error: \"%s\"" (cdr result)) | |
3256 filename))))) | |
3257 (ange-ftp-del-tmp-name temp) | |
30459 | 3258 (if binary |
28210 | 3259 (ange-ftp-set-ascii-mode host user))) |
3260 (if (eq visit t) | |
3261 (progn | |
30459 | 3262 (set-visited-file-modtime (ange-ftp-file-modtime filename)) |
28210 | 3263 (ange-ftp-set-buffer-mode) |
3264 (setq buffer-file-name filename) | |
3265 (set-buffer-modified-p nil))) | |
3266 ;; ensure `last-coding-system-used' has an appropriate value | |
3267 (setq last-coding-system-used coding-system-used) | |
3268 (ange-ftp-message "Wrote %s" abbr) | |
3269 (ange-ftp-add-file-entry filename)) | |
3270 (ange-ftp-real-write-region start end filename append visit)))) | |
3271 | |
3272 (defun ange-ftp-insert-file-contents (filename &optional visit beg end replace) | |
3273 (barf-if-buffer-read-only) | |
3274 (setq filename (expand-file-name filename)) | |
3275 (let ((parsed (ange-ftp-ftp-name filename))) | |
3276 (if parsed | |
3277 (progn | |
3278 (if visit | |
3279 (setq buffer-file-name filename)) | |
3280 (if (or (file-exists-p filename) | |
3281 (progn | |
3282 (setq ange-ftp-ls-cache-file nil) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3283 (remhash (file-name-directory filename) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3284 ange-ftp-files-hashtable) |
28210 | 3285 (file-exists-p filename))) |
3286 (let* ((host (nth 0 parsed)) | |
3287 (user (nth 1 parsed)) | |
3288 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3289 (temp (ange-ftp-make-tmp-name host)) | |
3290 (binary (or (ange-ftp-binary-file filename) | |
3291 (memq (ange-ftp-host-type host user) | |
3292 '(unix dumb-unix)))) | |
3293 (abbr (ange-ftp-abbreviate-filename filename)) | |
3294 (coding-system-used last-coding-system-used) | |
3295 size) | |
3296 (unwind-protect | |
3297 (progn | |
3298 (if binary | |
3299 (ange-ftp-set-binary-mode host user)) | |
3300 (let ((result (ange-ftp-send-cmd host user | |
3301 (list 'get name temp) | |
3302 (format "Retrieving %s" abbr)))) | |
3303 (or (car result) | |
3304 (signal 'ftp-error | |
3305 (list | |
3306 "Opening input file" | |
3307 (format "FTP Error: \"%s\"" (cdr result)) | |
3308 filename)))) | |
3309 (if (or (ange-ftp-real-file-readable-p temp) | |
3310 (sleep-for ange-ftp-retry-time) | |
3311 ;; Wait for file to hopefully appear. | |
3312 (ange-ftp-real-file-readable-p temp)) | |
3313 (setq | |
3314 size | |
3315 (nth 1 (ange-ftp-real-insert-file-contents | |
3316 temp visit beg end replace)) | |
3317 coding-system-used last-coding-system-used | |
3318 ;; override autodetection of buffer file type | |
3319 ;; to ensure buffer is saved in DOS format | |
3320 buffer-file-type binary) | |
3321 (signal 'ftp-error | |
3322 (list | |
3323 "Opening input file:" | |
3324 (format | |
3325 "FTP Error: %s not arrived or readable" | |
3326 filename))))) | |
3327 (if binary | |
3328 ;; We must keep `last-coding-system-used' | |
3329 ;; unchanged. | |
3330 (let (last-coding-system-used) | |
3331 (ange-ftp-set-ascii-mode host user))) | |
3332 (ange-ftp-del-tmp-name temp)) | |
3333 (if visit | |
3334 (progn | |
30459 | 3335 (set-visited-file-modtime |
3336 (ange-ftp-file-modtime filename)) | |
28210 | 3337 (setq buffer-file-name filename))) |
3338 (setq last-coding-system-used coding-system-used) | |
3339 (list filename size)) | |
3340 (signal 'file-error | |
30459 | 3341 (list |
28210 | 3342 "Opening input file" |
3343 filename)))) | |
3344 (ange-ftp-real-insert-file-contents filename visit beg end replace)))) | |
30459 | 3345 |
28210 | 3346 (defun ange-ftp-expand-symlink (file dir) |
50578
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3347 (let ((res (if (file-name-absolute-p file) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3348 (ange-ftp-replace-name-component dir file) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3349 (expand-file-name file dir)))) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3350 (if (file-symlink-p res) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3351 (ange-ftp-expand-symlink |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3352 (ange-ftp-get-file-entry res) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3353 (file-name-directory (directory-file-name res))) |
2bf79af13e21
From Michael Albinus <Michael.Albinus@alcatel.de>.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
49805
diff
changeset
|
3354 res))) |
28210 | 3355 |
3356 (defun ange-ftp-file-symlink-p (file) | |
3357 ;; call ange-ftp-expand-file-name rather than the normal | |
3358 ;; expand-file-name to stop loops when using a package that | |
3359 ;; redefines both file-symlink-p and expand-file-name. | |
3360 (setq file (ange-ftp-expand-file-name file)) | |
3361 (if (ange-ftp-ftp-name file) | |
51799
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3362 (condition-case nil |
56742
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3363 (let ((ent (ange-ftp-get-files (file-name-directory file)))) |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3364 (and ent |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3365 (stringp (setq ent |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3366 (gethash (ange-ftp-get-file-part file) ent))) |
19c16bca1b49
(ange-ftp-hash-entry-exists-p)
David Kastrup <dak@gnu.org>
parents:
56259
diff
changeset
|
3367 ent)) |
51799
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3368 ;; If we can't read the parent directory, just assume |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3369 ;; this file is not a symlink. |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3370 ;; This makes it possible to access a directory that |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3371 ;; whose parent is not readable. |
2a6ed9e210b2
(ange-ftp-file-symlink-p):
Richard M. Stallman <rms@gnu.org>
parents:
50578
diff
changeset
|
3372 (file-error nil)) |
28210 | 3373 (ange-ftp-real-file-symlink-p file))) |
3374 | |
3375 (defun ange-ftp-file-exists-p (name) | |
3376 (setq name (expand-file-name name)) | |
3377 (if (ange-ftp-ftp-name name) | |
3378 (if (ange-ftp-file-entry-p name) | |
3379 (let ((file-ent (ange-ftp-get-file-entry name))) | |
3380 (if (stringp file-ent) | |
3381 (file-exists-p | |
3382 (ange-ftp-expand-symlink file-ent | |
3383 (file-name-directory | |
3384 (directory-file-name name)))) | |
3385 t))) | |
3386 (ange-ftp-real-file-exists-p name))) | |
3387 | |
3388 (defun ange-ftp-file-directory-p (name) | |
3389 (setq name (expand-file-name name)) | |
3390 (if (ange-ftp-ftp-name name) | |
3391 ;; We do a file-name-as-directory on name here because some | |
3392 ;; machines (VMS) use a .DIR to indicate the filename associated | |
3393 ;; with a directory. This needs to be canonicalized. | |
3394 (let ((file-ent (ange-ftp-get-file-entry | |
3395 (ange-ftp-file-name-as-directory name)))) | |
3396 (if (stringp file-ent) | |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
3397 ;; Calling file-directory-p doesn't work because ange-ftp |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
3398 ;; is temporarily disabled for this operation. |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
3399 (ange-ftp-file-directory-p |
28210 | 3400 (ange-ftp-expand-symlink file-ent |
3401 (file-name-directory | |
3402 (directory-file-name name)))) | |
3403 file-ent)) | |
3404 (ange-ftp-real-file-directory-p name))) | |
3405 | |
3406 (defun ange-ftp-directory-files (directory &optional full match | |
3407 &rest v19-args) | |
3408 (setq directory (expand-file-name directory)) | |
3409 (if (ange-ftp-ftp-name directory) | |
3410 (progn | |
3411 (ange-ftp-barf-if-not-directory directory) | |
3412 (let ((tail (ange-ftp-hash-table-keys | |
3413 (ange-ftp-get-files directory))) | |
3414 files f) | |
3415 (setq directory (file-name-as-directory directory)) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3416 (while tail |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3417 (setq f (car tail) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3418 tail (cdr tail)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3419 (if (or (not match) (string-match-p match f)) |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3420 (setq files |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3421 (cons (if full (concat directory f) f) files)))) |
28210 | 3422 (nreverse files))) |
3423 (apply 'ange-ftp-real-directory-files directory full match v19-args))) | |
3424 | |
106309
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3425 (defun ange-ftp-directory-files-and-attributes |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3426 (directory &optional full match nosort id-format) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3427 (setq directory (expand-file-name directory)) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3428 (if (ange-ftp-ftp-name directory) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3429 (mapcar |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3430 (lambda (file) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3431 (cons file (file-attributes (expand-file-name file directory)))) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3432 (ange-ftp-directory-files directory full match nosort)) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3433 (ange-ftp-real-directory-files-and-attributes |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3434 directory full match nosort id-format))) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
3435 |
53351
d3b9902eacfe
(ange-ftp-file-attributes): Add new optional parameter ID-FORMAT.
Sam Steingold <sds@gnu.org>
parents:
52401
diff
changeset
|
3436 (defun ange-ftp-file-attributes (file &optional id-format) |
28210 | 3437 (setq file (expand-file-name file)) |
3438 (let ((parsed (ange-ftp-ftp-name file))) | |
3439 (if parsed | |
3440 (let ((part (ange-ftp-get-file-part file)) | |
3441 (files (ange-ftp-get-files (file-name-directory file)))) | |
3442 (if (ange-ftp-hash-entry-exists-p part files) | |
3443 (let ((host (nth 0 parsed)) | |
3444 (user (nth 1 parsed)) | |
3445 (name (nth 2 parsed)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3446 (dirp (gethash part files)) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3447 (inode (gethash file ange-ftp-inodes-hashtable))) |
28210 | 3448 (unless inode |
3449 (setq inode ange-ftp-next-inode-number | |
3450 ange-ftp-next-inode-number (1+ inode)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3451 (puthash file inode ange-ftp-inodes-hashtable)) |
28210 | 3452 (list (if (and (stringp dirp) (file-name-absolute-p dirp)) |
3453 (ange-ftp-expand-symlink dirp | |
3454 (file-name-directory file)) | |
3455 dirp) ;0 file type | |
3456 -1 ;1 link count | |
3457 -1 ;2 uid | |
3458 -1 ;3 gid | |
3459 '(0 0) ;4 atime | |
30459 | 3460 (ange-ftp-file-modtime file) ;5 mtime |
28210 | 3461 '(0 0) ;6 ctime |
105636
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3462 (ange-ftp-file-size file) ;7 size |
28210 | 3463 (concat (if (stringp dirp) "l" (if dirp "d" "-")) |
3464 "?????????") ;8 mode | |
3465 nil ;9 gid weird | |
3466 inode ;10 "inode number". | |
3467 -1 ;11 device number [v19 only] | |
3468 )))) | |
53500
530a52a3971b
(ange-ftp-file-attributes):
Richard M. Stallman <rms@gnu.org>
parents:
53415
diff
changeset
|
3469 (if id-format |
530a52a3971b
(ange-ftp-file-attributes):
Richard M. Stallman <rms@gnu.org>
parents:
53415
diff
changeset
|
3470 (ange-ftp-real-file-attributes file id-format) |
530a52a3971b
(ange-ftp-file-attributes):
Richard M. Stallman <rms@gnu.org>
parents:
53415
diff
changeset
|
3471 (ange-ftp-real-file-attributes file))))) |
28210 | 3472 |
30481 | 3473 (defun ange-ftp-file-newer-than-file-p (f1 f2) |
3474 (let ((f1-parsed (ange-ftp-ftp-name f1)) | |
3475 (f2-parsed (ange-ftp-ftp-name f2))) | |
3476 (if (or f1-parsed f2-parsed) | |
3477 (let ((f1-mt (nth 5 (file-attributes f1))) | |
3478 (f2-mt (nth 5 (file-attributes f2)))) | |
3479 (cond ((null f1-mt) nil) | |
3480 ((null f2-mt) t) | |
3481 (t (> (float-time f1-mt) (float-time f2-mt))))) | |
3482 (ange-ftp-real-file-newer-than-file-p f1 f2)))) | |
3483 | |
28210 | 3484 (defun ange-ftp-file-writable-p (file) |
33533 | 3485 (let ((ange-ftp-process-verbose nil)) |
3486 (setq file (expand-file-name file)) | |
3487 (if (ange-ftp-ftp-name file) | |
3488 (or (file-exists-p file) ;guess here for speed | |
3489 (file-directory-p (file-name-directory file))) | |
3490 (ange-ftp-real-file-writable-p file)))) | |
28210 | 3491 |
3492 (defun ange-ftp-file-readable-p (file) | |
33533 | 3493 (let ((ange-ftp-process-verbose nil)) |
3494 (setq file (expand-file-name file)) | |
3495 (if (ange-ftp-ftp-name file) | |
3496 (file-exists-p file) | |
3497 (ange-ftp-real-file-readable-p file)))) | |
28210 | 3498 |
3499 (defun ange-ftp-file-executable-p (file) | |
33533 | 3500 (let ((ange-ftp-process-verbose nil)) |
3501 (setq file (expand-file-name file)) | |
3502 (if (ange-ftp-ftp-name file) | |
3503 (file-exists-p file) | |
3504 (ange-ftp-real-file-executable-p file)))) | |
28210 | 3505 |
3506 (defun ange-ftp-delete-file (file) | |
3507 (interactive "fDelete file: ") | |
3508 (setq file (expand-file-name file)) | |
3509 (let ((parsed (ange-ftp-ftp-name file))) | |
3510 (if parsed | |
3511 (let* ((host (nth 0 parsed)) | |
3512 (user (nth 1 parsed)) | |
3513 (name (ange-ftp-quote-string (nth 2 parsed))) | |
3514 (abbr (ange-ftp-abbreviate-filename file)) | |
3515 (result (ange-ftp-send-cmd host user | |
3516 (list 'delete name) | |
3517 (format "Deleting %s" abbr)))) | |
3518 (or (car result) | |
3519 (signal 'ftp-error | |
3520 (list | |
3521 "Removing old name" | |
3522 (format "FTP Error: \"%s\"" (cdr result)) | |
3523 file))) | |
3524 (ange-ftp-delete-file-entry file)) | |
3525 (ange-ftp-real-delete-file file)))) | |
3526 | |
30459 | 3527 (defun ange-ftp-file-modtime (file) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3528 "Return the modification time of remote file FILE. |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3529 Value is (0 0) if the modification time cannot be determined." |
30459 | 3530 (let* ((parsed (ange-ftp-ftp-name file)) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3531 ;; At least one FTP server (wu-ftpd) can return a "226 |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3532 ;; Transfer complete" before the "213 MODTIME". Let's skip |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3533 ;; that. |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3534 (ange-ftp-skip-msgs (concat ange-ftp-skip-msgs "\\|^226")) |
30459 | 3535 (res (ange-ftp-send-cmd (car parsed) (cadr parsed) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3536 (list 'quote "mdtm" (cadr (cdr parsed))))) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3537 (line (cdr res)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3538 (modtime '(0 0))) |
38328
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3539 ;; MDTM should return "213 YYYYMMDDhhmmss" GMT on success |
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3540 ;; following the Internet draft for FTP extensions. |
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3541 ;; Bob@rattlesnake.com reports that is returns something different |
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3542 ;; for at least one FTP server. So, let's use the response only |
3c2404604bae
(ange-ftp-file-modtime): Check a 213 response
Gerd Moellmann <gerd@gnu.org>
parents:
38312
diff
changeset
|
3543 ;; if it matches the Internet draft. |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3544 (when (string-match-p "^213 [0-9]\\{14\\}$" line) |
38312
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3545 (setq modtime |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3546 (encode-time |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3547 (string-to-number (substring line 16 18)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3548 (string-to-number (substring line 14 16)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3549 (string-to-number (substring line 12 14)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3550 (string-to-number (substring line 10 12)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3551 (string-to-number (substring line 8 10)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3552 (string-to-number (substring line 4 8)) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3553 0))) |
b6dd8b1368af
(ange-ftp-file-modtime): Ignore 226 responses
Gerd Moellmann <gerd@gnu.org>
parents:
37813
diff
changeset
|
3554 modtime)) |
30459 | 3555 |
28210 | 3556 (defun ange-ftp-verify-visited-file-modtime (buf) |
3557 (let ((name (buffer-file-name buf))) | |
3558 (if (and (stringp name) (ange-ftp-ftp-name name)) | |
30459 | 3559 (let ((file-mdtm (ange-ftp-file-modtime name)) |
3560 (buf-mdtm (with-current-buffer buf (visited-file-modtime)))) | |
3561 (or (zerop (car file-mdtm)) | |
30518
ba9bd1bf0ef8
Ange-ftp handles the output of the w32-style clients
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
3562 (<= (float-time file-mdtm) (float-time buf-mdtm)))) |
28210 | 3563 (ange-ftp-real-verify-visited-file-modtime buf)))) |
105636
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3564 |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3565 (defun ange-ftp-file-size (file &optional ascii-mode) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3566 "Return the size of remote file FILE. Return -1 if can't get it. |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3567 If ascii-mode is non-nil, return the size with the extra octets that |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3568 need to be inserted, one at the end of each line, to provide correct |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3569 end-of-line semantics for a transfer using TYPE=A. The default is nil, |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3570 so return the size on the remote host exactly. See RFC 3659." |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3571 (let* ((parsed (ange-ftp-ftp-name file)) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3572 (host (nth 0 parsed)) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3573 (user (nth 1 parsed)) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3574 (name (ange-ftp-quote-string (nth 2 parsed))) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3575 ;; At least one FTP server (wu-ftpd) can return a "226 |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3576 ;; Transfer complete" before the "213 SIZE". Let's skip |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3577 ;; that. |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3578 (ange-ftp-skip-msgs (concat ange-ftp-skip-msgs "\\|^226")) |
105658
1165f7844d0a
(ange-ftp-file-size): Use unwind-protect.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105636
diff
changeset
|
3579 (res (unwind-protect |
1165f7844d0a
(ange-ftp-file-size): Use unwind-protect.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105636
diff
changeset
|
3580 (progn |
1165f7844d0a
(ange-ftp-file-size): Use unwind-protect.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105636
diff
changeset
|
3581 (unless ascii-mode |
1165f7844d0a
(ange-ftp-file-size): Use unwind-protect.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105636
diff
changeset
|
3582 (ange-ftp-set-binary-mode host user)) |
1165f7844d0a
(ange-ftp-file-size): Use unwind-protect.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105636
diff
changeset
|
3583 (ange-ftp-send-cmd host user (list 'quote "size" name))) |
105636
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3584 (unless ascii-mode |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3585 (ange-ftp-set-ascii-mode host user)))) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3586 (line (cdr res))) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3587 (if (string-match "^213 \\([0-9]+\\)$" line) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3588 (string-to-number (match-string 1 line)) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3589 -1))) |
889d12d7c95b
(ange-ftp-send-cmd): Handle `size' like `mdtm'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105382
diff
changeset
|
3590 |
28210 | 3591 |
3592 ;;;; ------------------------------------------------------------ | |
3593 ;;;; File copying support... totally re-written 6/24/92. | |
3594 ;;;; ------------------------------------------------------------ | |
3595 | |
3596 (defun ange-ftp-barf-or-query-if-file-exists (absname querystring interactive) | |
3597 (if (file-exists-p absname) | |
3598 (if (not interactive) | |
3599 (signal 'file-already-exists (list absname)) | |
3600 (if (not (yes-or-no-p (format "File %s already exists; %s anyway? " | |
3601 absname querystring))) | |
3602 (signal 'file-already-exists (list absname)))))) | |
3603 | |
3604 ;; async local copy commented out for now since I don't seem to get | |
3605 ;; the process sentinel called for some processes. | |
3606 ;; | |
3607 ;; (defun ange-ftp-copy-file-locally (filename newname ok-if-already-exists | |
3608 ;; keep-date cont) | |
3609 ;; "Kludge to copy a local file and call a continuation when the copy | |
3610 ;; finishes." | |
3611 ;; ;; check to see if we can overwrite | |
3612 ;; (if (or (not ok-if-already-exists) | |
3613 ;; (numberp ok-if-already-exists)) | |
30459 | 3614 ;; (ange-ftp-barf-or-query-if-file-exists newname "copy to it" |
28210 | 3615 ;; (numberp ok-if-already-exists))) |
3616 ;; (let ((proc (start-process " *copy*" | |
3617 ;; (generate-new-buffer "*copy*") | |
3618 ;; "cp" | |
3619 ;; filename | |
3620 ;; newname)) | |
3621 ;; res) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3622 ;; (set-process-sentinel proc 'ange-ftp-copy-file-locally-sentinel) |
28210 | 3623 ;; (process-kill-without-query proc) |
39888
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3624 ;; (with-current-buffer (process-buffer proc) |
b429be6f52ac
(ange-ftp-raw-send-cmd, ange-ftp-wait-not-busy):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39839
diff
changeset
|
3625 ;; (set (make-local-variable 'copy-cont) cont)))) |
30459 | 3626 ;; |
28210 | 3627 ;; (defun ange-ftp-copy-file-locally-sentinel (proc status) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
3628 ;; (with-current-buffer (process-buffer proc) |
28210 | 3629 ;; (let ((cont copy-cont) |
3630 ;; (result (buffer-string))) | |
3631 ;; (unwind-protect | |
3632 ;; (if (and (string-equal status "finished\n") | |
3633 ;; (zerop (length result))) | |
3634 ;; (ange-ftp-call-cont cont t nil) | |
3635 ;; (ange-ftp-call-cont cont | |
3636 ;; nil | |
3637 ;; (if (zerop (length result)) | |
3638 ;; (substring status 0 -1) | |
3639 ;; (substring result 0 -1)))) | |
3640 ;; (kill-buffer (current-buffer)))))) | |
3641 | |
3642 ;; this is the extended version of ange-ftp-copy-file-internal that works | |
3643 ;; asynchronously if asked nicely. | |
3644 (defun ange-ftp-copy-file-internal (filename newname ok-if-already-exists | |
3645 keep-date &optional msg cont nowait) | |
3646 (setq filename (expand-file-name filename) | |
3647 newname (expand-file-name newname)) | |
3648 | |
3649 ;; canonicalize newname if a directory. | |
3650 (if (file-directory-p newname) | |
3651 (setq newname (expand-file-name (file-name-nondirectory filename) newname))) | |
3652 | |
3653 (let ((f-parsed (ange-ftp-ftp-name filename)) | |
3654 (t-parsed (ange-ftp-ftp-name newname))) | |
3655 | |
3656 ;; local file to local file copy? | |
3657 (if (and (not f-parsed) (not t-parsed)) | |
3658 (progn | |
3659 (ange-ftp-real-copy-file filename newname ok-if-already-exists | |
3660 keep-date) | |
3661 (if cont | |
3662 (ange-ftp-call-cont cont t "Copied locally"))) | |
3663 ;; one or both files are remote. | |
3664 (let* ((f-host (and f-parsed (nth 0 f-parsed))) | |
3665 (f-user (and f-parsed (nth 1 f-parsed))) | |
3666 (f-name (and f-parsed (ange-ftp-quote-string (nth 2 f-parsed)))) | |
3667 (f-abbr (ange-ftp-abbreviate-filename filename)) | |
3668 (t-host (and t-parsed (nth 0 t-parsed))) | |
3669 (t-user (and t-parsed (nth 1 t-parsed))) | |
3670 (t-name (and t-parsed (ange-ftp-quote-string (nth 2 t-parsed)))) | |
3671 (t-abbr (ange-ftp-abbreviate-filename newname filename)) | |
3672 (binary (or (ange-ftp-binary-file filename) | |
3673 (ange-ftp-binary-file newname) | |
3674 (and (memq (ange-ftp-host-type f-host f-user) | |
3675 '(unix dumb-unix)) | |
3676 (memq (ange-ftp-host-type t-host t-user) | |
3677 '(unix dumb-unix))))) | |
3678 temp1 | |
3679 temp2) | |
3680 | |
3681 ;; check to see if we can overwrite | |
3682 (if (or (not ok-if-already-exists) | |
3683 (numberp ok-if-already-exists)) | |
30459 | 3684 (ange-ftp-barf-or-query-if-file-exists newname "copy to it" |
28210 | 3685 (numberp ok-if-already-exists))) |
3686 | |
3687 ;; do the copying. | |
3688 (if f-parsed | |
30459 | 3689 |
28210 | 3690 ;; filename was remote. |
3691 (progn | |
3692 (if (or (ange-ftp-use-gateway-p f-host) | |
3693 t-parsed) | |
3694 ;; have to use intermediate file if we are getting via | |
3695 ;; gateway machine or we are doing a remote to remote copy. | |
3696 (setq temp1 (ange-ftp-make-tmp-name f-host))) | |
30459 | 3697 |
28210 | 3698 (if binary |
3699 (ange-ftp-set-binary-mode f-host f-user)) | |
3700 | |
3701 (ange-ftp-send-cmd | |
3702 f-host | |
3703 f-user | |
3704 (list 'get f-name (or temp1 (ange-ftp-quote-string newname))) | |
3705 (or msg | |
3706 (if (and temp1 t-parsed) | |
3707 (format "Getting %s" f-abbr) | |
3708 (format "Copying %s to %s" f-abbr t-abbr))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3709 (list 'ange-ftp-cf1 |
28210 | 3710 filename newname binary msg |
3711 f-parsed f-host f-user f-name f-abbr | |
3712 t-parsed t-host t-user t-name t-abbr | |
3713 temp1 temp2 cont nowait) | |
3714 nowait)) | |
3715 | |
3716 ;; filename wasn't remote. newname must be remote. call the | |
3717 ;; function which does the remainder of the copying work. | |
3718 (ange-ftp-cf1 t nil | |
3719 filename newname binary msg | |
3720 f-parsed f-host f-user f-name f-abbr | |
3721 t-parsed t-host t-user t-name t-abbr | |
3722 nil nil cont nowait)))))) | |
3723 | |
3724 (defvar ange-ftp-waiting-flag nil) | |
3725 | |
3726 ;; next part of copying routine. | |
3727 (defun ange-ftp-cf1 (result line | |
3728 filename newname binary msg | |
3729 f-parsed f-host f-user f-name f-abbr | |
3730 t-parsed t-host t-user t-name t-abbr | |
3731 temp1 temp2 cont nowait) | |
3732 (if line | |
3733 ;; filename must have been remote, and we must have just done a GET. | |
3734 (unwind-protect | |
3735 (or result | |
3736 ;; GET failed for some reason. Clean up and get out. | |
3737 (progn | |
3738 (and temp1 (ange-ftp-del-tmp-name temp1)) | |
3739 (or cont | |
3740 (if ange-ftp-waiting-flag | |
3741 (throw 'ftp-error t) | |
3742 (signal 'ftp-error | |
3743 (list "Opening input file" | |
3744 (format "FTP Error: \"%s\"" line) | |
3745 filename)))))) | |
3746 ;; cleanup | |
3747 (if binary | |
3748 (ange-ftp-set-ascii-mode f-host f-user)))) | |
3749 | |
3750 (if result | |
3751 ;; We now have to copy either temp1 or filename to newname. | |
3752 (if t-parsed | |
30459 | 3753 |
28210 | 3754 ;; newname was remote. |
3755 (progn | |
3756 (if (ange-ftp-use-gateway-p t-host) | |
3757 (setq temp2 (ange-ftp-make-tmp-name t-host))) | |
30459 | 3758 |
28210 | 3759 ;; make sure data is moved into the right place for the |
3760 ;; outgoing transfer. gateway temporary files complicate | |
3761 ;; things nicely. | |
3762 (if temp1 | |
3763 (if temp2 | |
3764 (if (string-equal temp1 temp2) | |
3765 (setq temp1 nil) | |
3766 (ange-ftp-real-copy-file temp1 temp2 t)) | |
3767 (setq temp2 temp1 temp1 nil)) | |
3768 (if temp2 | |
3769 (ange-ftp-real-copy-file filename temp2 t))) | |
30459 | 3770 |
28210 | 3771 (if binary |
3772 (ange-ftp-set-binary-mode t-host t-user)) | |
3773 | |
3774 ;; tell the process filter what size the file is. | |
3775 (let ((attr (file-attributes (or temp2 filename)))) | |
3776 (if attr | |
3777 (ange-ftp-set-xfer-size t-host t-user (nth 7 attr)))) | |
3778 | |
3779 (ange-ftp-send-cmd | |
3780 t-host | |
3781 t-user | |
80116
91513d7aa412
* net/ange-ftp.el (ange-ftp-cf1): Quote FILENAME.
Michael Albinus <michael.albinus@gmx.de>
parents:
80044
diff
changeset
|
3782 (list 'put (or temp2 (ange-ftp-quote-string filename)) t-name) |
28210 | 3783 (or msg |
3784 (if (and temp2 f-parsed) | |
3785 (format "Putting %s" newname) | |
3786 (format "Copying %s to %s" f-abbr t-abbr))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3787 (list 'ange-ftp-cf2 |
28210 | 3788 newname t-host t-user binary temp1 temp2 cont) |
3789 nowait)) | |
30459 | 3790 |
28210 | 3791 ;; newname wasn't remote. |
3792 (ange-ftp-cf2 t nil newname t-host t-user binary temp1 temp2 cont)) | |
3793 | |
3794 ;; first copy failed, tell caller | |
3795 (ange-ftp-call-cont cont result line))) | |
3796 | |
3797 ;; last part of copying routine. | |
3798 (defun ange-ftp-cf2 (result line newname t-host t-user binary temp1 temp2 cont) | |
3799 (unwind-protect | |
3800 (if line | |
3801 ;; result from doing a local to remote copy. | |
3802 (unwind-protect | |
3803 (progn | |
3804 (or result | |
3805 (or cont | |
3806 (if ange-ftp-waiting-flag | |
3807 (throw 'ftp-error t) | |
3808 (signal 'ftp-error | |
3809 (list "Opening output file" | |
3810 (format "FTP Error: \"%s\"" line) | |
3811 newname))))) | |
30459 | 3812 |
28210 | 3813 (ange-ftp-add-file-entry newname)) |
30459 | 3814 |
28210 | 3815 ;; cleanup. |
3816 (if binary | |
3817 (ange-ftp-set-ascii-mode t-host t-user))) | |
30459 | 3818 |
28210 | 3819 ;; newname was local. |
3820 (if temp1 | |
3821 (ange-ftp-real-copy-file temp1 newname t))) | |
30459 | 3822 |
28210 | 3823 ;; clean up |
3824 (and temp1 (ange-ftp-del-tmp-name temp1)) | |
3825 (and temp2 (ange-ftp-del-tmp-name temp2)) | |
3826 (ange-ftp-call-cont cont result line))) | |
3827 | |
3828 (defun ange-ftp-copy-file (filename newname &optional ok-if-already-exists | |
85505
bc97f31b2cf1
* files.el (backup-buffer-copy): Call `copy-file' with non-nil
Michael Albinus <michael.albinus@gmx.de>
parents:
84913
diff
changeset
|
3829 keep-date preserve-uid-gid) |
28210 | 3830 (interactive "fCopy file: \nFCopy %s to file: \np") |
3831 (ange-ftp-copy-file-internal filename | |
3832 newname | |
3833 ok-if-already-exists | |
3834 keep-date | |
3835 nil | |
3836 nil | |
105372
bd2966850aac
Use `called-interactively-p' instead of `interactive-p'.
Juanma Barranquero <lekktu@gmail.com>
parents:
105350
diff
changeset
|
3837 (called-interactively-p 'interactive))) |
39839
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3838 |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3839 (defun ange-ftp-copy-files-async (okay-p line verbose-p files) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3840 "Copy some files in the background. |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3841 OKAY-P must be t, and LINE does not matter. They are here to make this |
39839
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3842 function a valid CONT argument for `ange-ftp-raw-send-cmd'. |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3843 If VERBOSE-P is non-nil, print progress report in the echo area. |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3844 When all the files have been copied already, a message is shown anyway. |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3845 FILES is a list of files to copy in the form |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3846 (from-file to-file ok-if-already-exists keep-date) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3847 E.g., |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3848 (ange-ftp-copy-files-async t nil t '((\"a\" \"b\" t t) (\"c\" \"d\" t t)))" |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3849 (unless okay-p (error "%s: %s" 'ange-ftp-copy-files-async line)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3850 (if files |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3851 (let* ((ff (car files)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3852 (from-file (nth 0 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3853 (to-file (nth 1 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3854 (ok-if-exists (nth 2 ff)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3855 (keep-date (nth 3 ff))) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3856 (ange-ftp-copy-file-internal |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3857 from-file to-file ok-if-exists keep-date |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3858 (and verbose-p (format "%s --> %s" from-file to-file)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3859 (list 'ange-ftp-copy-files-async verbose-p (cdr files)) |
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3860 t)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3861 (message "%s: done" 'ange-ftp-copy-files-async))) |
39839
c5c5558d34cc
(ange-ftp-copy-files-async): New function for
Sam Steingold <sds@gnu.org>
parents:
39533
diff
changeset
|
3862 |
28210 | 3863 |
3864 ;;;; ------------------------------------------------------------ | |
3865 ;;;; File renaming support. | |
3866 ;;;; ------------------------------------------------------------ | |
3867 | |
3868 (defun ange-ftp-rename-remote-to-remote (filename newname f-parsed t-parsed) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3869 "Rename remote file FILENAME to remote file NEWNAME." |
28210 | 3870 (let ((f-host (nth 0 f-parsed)) |
3871 (f-user (nth 1 f-parsed)) | |
3872 (t-host (nth 0 t-parsed)) | |
3873 (t-user (nth 1 t-parsed))) | |
3874 (if (and (string-equal f-host t-host) | |
3875 (string-equal f-user t-user)) | |
3876 (let* ((f-name (ange-ftp-quote-string (nth 2 f-parsed))) | |
3877 (t-name (ange-ftp-quote-string (nth 2 t-parsed))) | |
3878 (cmd (list 'rename f-name t-name)) | |
3879 (fabbr (ange-ftp-abbreviate-filename filename)) | |
3880 (nabbr (ange-ftp-abbreviate-filename newname filename)) | |
3881 (result (ange-ftp-send-cmd f-host f-user cmd | |
3882 (format "Renaming %s to %s" | |
3883 fabbr | |
3884 nabbr)))) | |
3885 (or (car result) | |
3886 (signal 'ftp-error | |
3887 (list | |
3888 "Renaming" | |
3889 (format "FTP Error: \"%s\"" (cdr result)) | |
3890 filename | |
3891 newname))) | |
3892 (ange-ftp-add-file-entry newname) | |
3893 (ange-ftp-delete-file-entry filename)) | |
3894 (ange-ftp-copy-file-internal filename newname t nil) | |
3895 (delete-file filename)))) | |
3896 | |
3897 (defun ange-ftp-rename-local-to-remote (filename newname) | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
3898 "Rename local file FILENAME to remote file NEWNAME." |
28210 | 3899 (let* ((fabbr (ange-ftp-abbreviate-filename filename)) |
3900 (nabbr (ange-ftp-abbreviate-filename newname filename)) | |
3901 (msg (format "Renaming %s to %s" fabbr nabbr))) | |
3902 (ange-ftp-copy-file-internal filename newname t nil msg) | |
3903 (let (ange-ftp-process-verbose) | |
3904 (delete-file filename)))) | |
3905 | |
3906 (defun ange-ftp-rename-remote-to-local (filename newname) | |
3907 "Rename remote file FILENAME to local file NEWNAME." | |
3908 (let* ((fabbr (ange-ftp-abbreviate-filename filename)) | |
3909 (nabbr (ange-ftp-abbreviate-filename newname filename)) | |
3910 (msg (format "Renaming %s to %s" fabbr nabbr))) | |
3911 (ange-ftp-copy-file-internal filename newname t nil msg) | |
3912 (let (ange-ftp-process-verbose) | |
3913 (delete-file filename)))) | |
3914 | |
3915 (defun ange-ftp-rename-file (filename newname &optional ok-if-already-exists) | |
3916 (interactive "fRename file: \nFRename %s to file: \np") | |
3917 (setq filename (expand-file-name filename)) | |
3918 (setq newname (expand-file-name newname)) | |
3919 (let* ((f-parsed (ange-ftp-ftp-name filename)) | |
3920 (t-parsed (ange-ftp-ftp-name newname))) | |
3921 (if (and (or f-parsed t-parsed) | |
3922 (or (not ok-if-already-exists) | |
3923 (numberp ok-if-already-exists))) | |
3924 (ange-ftp-barf-or-query-if-file-exists | |
3925 newname | |
3926 "rename to it" | |
3927 (numberp ok-if-already-exists))) | |
3928 (if f-parsed | |
3929 (if t-parsed | |
3930 (ange-ftp-rename-remote-to-remote filename newname f-parsed | |
3931 t-parsed) | |
3932 (ange-ftp-rename-remote-to-local filename newname)) | |
3933 (if t-parsed | |
3934 (ange-ftp-rename-local-to-remote filename newname) | |
3935 (ange-ftp-real-rename-file filename newname ok-if-already-exists))))) | |
3936 | |
3937 ;;;; ------------------------------------------------------------ | |
3938 ;;;; File name completion support. | |
3939 ;;;; ------------------------------------------------------------ | |
3940 | |
3941 ;; If the file entry is not a directory (nor a symlink pointing to a directory) | |
3942 ;; returns whether the file (or file pointed to by the symlink) is ignored | |
3943 ;; by completion-ignored-extensions. | |
3944 ;; Note that `ange-ftp-this-dir' and `ange-ftp-completion-ignored-pattern' | |
3945 ;; are used as free variables. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3946 (defun ange-ftp-file-entry-not-ignored-p (symname val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3947 (if (stringp val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3948 (let ((file (ange-ftp-expand-symlink val ange-ftp-this-dir))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3949 (or (file-directory-p file) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3950 (and (file-exists-p file) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3951 (not (string-match ange-ftp-completion-ignored-pattern |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3952 symname))))) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3953 (or val ; is a directory name |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3954 (not (string-match ange-ftp-completion-ignored-pattern symname))))) |
28210 | 3955 |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3956 (defun ange-ftp-root-dir-p (dir) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3957 ;; Maybe we should use something more like |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3958 ;; (equal dir (file-name-directory (directory-file-name dir))) -stef |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3959 (or (and (eq system-type 'windows-nt) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
3960 (string-match "\\`[a-zA-Z]:[/\\]\\'" dir)) |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3961 (string-equal "/" dir))) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3962 |
28210 | 3963 (defun ange-ftp-file-name-all-completions (file dir) |
3964 (let ((ange-ftp-this-dir (expand-file-name dir))) | |
3965 (if (ange-ftp-ftp-name ange-ftp-this-dir) | |
3966 (progn | |
3967 (ange-ftp-barf-if-not-directory ange-ftp-this-dir) | |
3968 (setq ange-ftp-this-dir | |
3969 (ange-ftp-real-file-name-as-directory ange-ftp-this-dir)) | |
3970 (let* ((tbl (ange-ftp-get-files ange-ftp-this-dir)) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
3971 (completions (all-completions file tbl))) |
28210 | 3972 |
3973 ;; see whether each matching file is a directory or not... | |
3974 (mapcar | |
30459 | 3975 (lambda (file) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3976 (let ((ent (gethash file tbl))) |
30459 | 3977 (if (and ent |
3978 (or (not (stringp ent)) | |
3979 (file-directory-p | |
3980 (ange-ftp-expand-symlink ent | |
3981 ange-ftp-this-dir)))) | |
3982 (concat file "/") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
3983 file))) |
28210 | 3984 completions))) |
3985 | |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
3986 (if (ange-ftp-root-dir-p ange-ftp-this-dir) |
28210 | 3987 (nconc (all-completions file (ange-ftp-generate-root-prefixes)) |
3988 (ange-ftp-real-file-name-all-completions file | |
3989 ange-ftp-this-dir)) | |
3990 (ange-ftp-real-file-name-all-completions file ange-ftp-this-dir))))) | |
3991 | |
74766
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
3992 (defun ange-ftp-file-name-completion (file dir &optional predicate) |
28210 | 3993 (let ((ange-ftp-this-dir (expand-file-name dir))) |
3994 (if (ange-ftp-ftp-name ange-ftp-this-dir) | |
3995 (progn | |
3996 (ange-ftp-barf-if-not-directory ange-ftp-this-dir) | |
3997 (if (equal file "") | |
3998 "" | |
3999 (setq ange-ftp-this-dir | |
4000 (ange-ftp-real-file-name-as-directory ange-ftp-this-dir)) ;real? | |
4001 (let* ((tbl (ange-ftp-get-files ange-ftp-this-dir)) | |
4002 (ange-ftp-completion-ignored-pattern | |
30459 | 4003 (mapconcat (lambda (s) (if (stringp s) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
4004 (concat (regexp-quote s) "$") |
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
4005 "/")) ; / never in filename |
28210 | 4006 completion-ignored-extensions |
4007 "\\|"))) | |
4008 (save-match-data | |
4009 (or (ange-ftp-file-name-completion-1 | |
4010 file tbl ange-ftp-this-dir | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4011 'ange-ftp-file-entry-not-ignored-p) |
28210 | 4012 (ange-ftp-file-name-completion-1 |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4013 file tbl ange-ftp-this-dir)))))) |
28210 | 4014 |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4015 (if (ange-ftp-root-dir-p ange-ftp-this-dir) |
28210 | 4016 (try-completion |
4017 file | |
4018 (nconc (ange-ftp-generate-root-prefixes) | |
45432
85b978f04df7
(ange-ftp-generate-root-prefixes)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
45260
diff
changeset
|
4019 (ange-ftp-real-file-name-all-completions |
74766
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4020 file ange-ftp-this-dir)) |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4021 predicate) |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4022 (if predicate |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4023 (ange-ftp-real-file-name-completion |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4024 file ange-ftp-this-dir predicate) |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4025 (ange-ftp-real-file-name-completion |
ca4412906dbd
* net/ange-ftp.el (ange-ftp-file-name-completion): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
68648
diff
changeset
|
4026 file ange-ftp-this-dir)))))) |
28210 | 4027 |
4028 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4029 (defun ange-ftp-file-name-completion-1 (file tbl dir &optional predicate) |
28210 | 4030 (let ((bestmatch (try-completion file tbl predicate))) |
4031 (if bestmatch | |
4032 (if (eq bestmatch t) | |
4033 (if (file-directory-p (expand-file-name file dir)) | |
4034 (concat file "/") | |
4035 t) | |
4036 (if (and (eq (try-completion bestmatch tbl predicate) t) | |
4037 (file-directory-p | |
4038 (expand-file-name bestmatch dir))) | |
4039 (concat bestmatch "/") | |
4040 bestmatch))))) | |
4041 | |
4042 ;; Put these lines uncommmented in your .emacs if you want C-r to refresh | |
4043 ;; ange-ftp's cache whilst doing filename completion. | |
4044 ;; | |
4045 ;;(define-key minibuffer-local-completion-map "\C-r" 'ange-ftp-re-read-dir) | |
4046 ;;(define-key minibuffer-local-must-match-map "\C-r" 'ange-ftp-re-read-dir) | |
4047 | |
45170
1f468f3ca959
(ange-ftp-re-read-dir): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44953
diff
changeset
|
4048 ;;;###autoload |
1f468f3ca959
(ange-ftp-re-read-dir): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44953
diff
changeset
|
4049 (defalias 'ange-ftp-re-read-dir 'ange-ftp-reread-dir) |
1f468f3ca959
(ange-ftp-re-read-dir): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44953
diff
changeset
|
4050 |
28210 | 4051 ;;;###autoload |
4052 (defun ange-ftp-reread-dir (&optional dir) | |
4053 "Reread remote directory DIR to update the directory cache. | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
4054 The implementation of remote FTP file names caches directory contents |
28210 | 4055 for speed. Therefore, when new remote files are created, Emacs |
4056 may not know they exist. You can use this command to reread a specific | |
4057 directory, so that Emacs will know its current contents." | |
4058 (interactive) | |
4059 (if dir | |
4060 (setq dir (expand-file-name dir)) | |
4061 (setq dir (file-name-directory (expand-file-name (buffer-string))))) | |
4062 (if (ange-ftp-ftp-name dir) | |
4063 (progn | |
4064 (setq ange-ftp-ls-cache-file nil) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4065 (remhash dir ange-ftp-files-hashtable) |
28210 | 4066 (ange-ftp-get-files dir t)))) |
4067 | |
4068 (defun ange-ftp-make-directory (dir &optional parents) | |
4069 (interactive (list (expand-file-name (read-file-name "Make directory: ")))) | |
4070 (if parents | |
4071 (let ((parent (file-name-directory (directory-file-name dir)))) | |
4072 (or (file-exists-p parent) | |
4073 (ange-ftp-make-directory parent parents)))) | |
4074 (if (file-exists-p dir) | |
4075 (error "Cannot make directory %s: file already exists" dir) | |
4076 (let ((parsed (ange-ftp-ftp-name dir))) | |
4077 (if parsed | |
4078 (let* ((host (nth 0 parsed)) | |
4079 (user (nth 1 parsed)) | |
4080 ;; Some ftp's on unix machines (at least on Suns) | |
4081 ;; insist that mkdir take a filename, and not a | |
4082 ;; directory-name name as an arg. Argh!! This is a bug. | |
4083 ;; Non-unix machines will probably always insist | |
4084 ;; that mkdir takes a directory-name as an arg | |
4085 ;; (as the ftp man page says it should). | |
4086 (name (ange-ftp-quote-string | |
4087 (if (eq (ange-ftp-host-type host) 'unix) | |
4088 (ange-ftp-real-directory-file-name (nth 2 parsed)) | |
4089 (ange-ftp-real-file-name-as-directory | |
4090 (nth 2 parsed))))) | |
4091 (abbr (ange-ftp-abbreviate-filename dir)) | |
4092 (result (ange-ftp-send-cmd host user | |
4093 (list 'mkdir name) | |
4094 (format "Making directory %s" | |
4095 abbr)))) | |
4096 (or (car result) | |
4097 (ange-ftp-error host user | |
4098 (format "Could not make directory %s: %s" | |
4099 dir | |
4100 (cdr result)))) | |
4101 (ange-ftp-add-file-entry dir t)) | |
4102 (ange-ftp-real-make-directory dir))))) | |
4103 | |
105350
05719e53cf8b
* net/ange-ftp.el (ange-ftp-delete-directory ): Add optional
Michael Albinus <michael.albinus@gmx.de>
parents:
104933
diff
changeset
|
4104 (defun ange-ftp-delete-directory (dir &optional recursive) |
28210 | 4105 (if (file-directory-p dir) |
4106 (let ((parsed (ange-ftp-ftp-name dir))) | |
105382
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4107 (if recursive |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4108 (mapc |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4109 (lambda (file) |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4110 (if (file-directory-p file) |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4111 (ange-ftp-delete-directory file recursive) |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4112 (delete-file file))) |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4113 ;; We do not want to delete "." and "..". |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4114 (directory-files |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4115 dir 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))) |
28210 | 4116 (if parsed |
4117 (let* ((host (nth 0 parsed)) | |
4118 (user (nth 1 parsed)) | |
4119 ;; Some ftp's on unix machines (at least on Suns) | |
4120 ;; insist that rmdir take a filename, and not a | |
4121 ;; directory-name name as an arg. Argh!! This is a bug. | |
4122 ;; Non-unix machines will probably always insist | |
4123 ;; that rmdir takes a directory-name as an arg | |
4124 ;; (as the ftp man page says it should). | |
4125 (name (ange-ftp-quote-string | |
4126 (if (eq (ange-ftp-host-type host) 'unix) | |
4127 (ange-ftp-real-directory-file-name | |
4128 (nth 2 parsed)) | |
4129 (ange-ftp-real-file-name-as-directory | |
4130 (nth 2 parsed))))) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4131 (abbr (ange-ftp-abbreviate-filename dir)) |
105382
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4132 (result |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4133 (progn |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4134 ;; CWD must not in this directory. |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4135 (ange-ftp-cd host user "/" 'noerror) |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4136 (ange-ftp-send-cmd host user |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4137 (list 'rmdir name) |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4138 (format "Removing directory %s" |
7cb911a9baab
* net/ange-ftp.el (ange-ftp-generate-passwd-key): Check, whether
Michael Albinus <michael.albinus@gmx.de>
parents:
105372
diff
changeset
|
4139 abbr))))) |
28210 | 4140 (or (car result) |
4141 (ange-ftp-error host user | |
4142 (format "Could not remove directory %s: %s" | |
4143 dir | |
4144 (cdr result)))) | |
4145 (ange-ftp-delete-file-entry dir t)) | |
105350
05719e53cf8b
* net/ange-ftp.el (ange-ftp-delete-directory ): Add optional
Michael Albinus <michael.albinus@gmx.de>
parents:
104933
diff
changeset
|
4146 (ange-ftp-real-delete-directory dir recursive))) |
28210 | 4147 (error "Not a directory: %s" dir))) |
4148 | |
4149 ;; Make a local copy of FILE and return its name. | |
4150 | |
4151 (defun ange-ftp-file-local-copy (file) | |
4152 (let* ((fn1 (expand-file-name file)) | |
4153 (pa1 (ange-ftp-ftp-name fn1))) | |
4154 (if pa1 | |
4155 (let ((tmp1 (ange-ftp-make-tmp-name (car pa1)))) | |
4156 (ange-ftp-copy-file-internal fn1 tmp1 t nil | |
4157 (format "Getting %s" fn1)) | |
4158 tmp1)))) | |
4159 | |
81937
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4160 (defun ange-ftp-file-remote-p (file &optional identification connected) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4161 (let* ((parsed (ange-ftp-ftp-name file)) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4162 (host (nth 0 parsed)) |
98390
e2da96799e45
* net/ange-ftp.el (ange-ftp-file-remote-p): Handle `localname' as
Michael Albinus <michael.albinus@gmx.de>
parents:
94677
diff
changeset
|
4163 (user (nth 1 parsed)) |
e2da96799e45
* net/ange-ftp.el (ange-ftp-file-remote-p): Handle `localname' as
Michael Albinus <michael.albinus@gmx.de>
parents:
94677
diff
changeset
|
4164 (localname (nth 2 parsed))) |
81937
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4165 (and (or (not connected) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4166 (let ((proc (get-process (ange-ftp-ftp-process-buffer host user)))) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4167 (and proc (processp proc) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4168 (memq (process-status proc) '(run open))))) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4169 (cond |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4170 ((eq identification 'method) (and parsed "ftp")) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4171 ((eq identification 'user) user) |
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4172 ((eq identification 'host) host) |
98390
e2da96799e45
* net/ange-ftp.el (ange-ftp-file-remote-p): Handle `localname' as
Michael Albinus <michael.albinus@gmx.de>
parents:
94677
diff
changeset
|
4173 ((eq identification 'localname) localname) |
81937
c2b7868011b1
* net/ange-ftp.el: (ange-ftp-file-remote-p): Handle optional
Michael Albinus <michael.albinus@gmx.de>
parents:
81758
diff
changeset
|
4174 (t (ange-ftp-replace-name-component file "")))))) |
55846
aed680fa845d
(ange-ftp-file-remote-p): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
53500
diff
changeset
|
4175 |
28210 | 4176 (defun ange-ftp-load (file &optional noerror nomessage nosuffix) |
4177 (if (ange-ftp-ftp-name file) | |
4178 (let ((tryfiles (if nosuffix | |
4179 (list file) | |
4180 (list (concat file ".elc") (concat file ".el") file))) | |
4181 ;; make sure there are no references to temp files | |
4182 (load-force-doc-strings t) | |
4183 copy) | |
4184 (while (and tryfiles (not copy)) | |
4185 (catch 'ftp-error | |
4186 (let ((ange-ftp-waiting-flag t)) | |
4187 (condition-case error | |
4188 (setq copy (ange-ftp-file-local-copy (car tryfiles))) | |
4189 (ftp-error nil)))) | |
4190 (setq tryfiles (cdr tryfiles))) | |
4191 (if copy | |
4192 (unwind-protect | |
4193 (funcall 'load copy noerror nomessage nosuffix) | |
4194 (delete-file copy)) | |
4195 (or noerror | |
4196 (signal 'file-error (list "Cannot open load file" file))) | |
4197 nil)) | |
4198 (ange-ftp-real-load file noerror nomessage nosuffix))) | |
4199 | |
4200 ;; Calculate default-unhandled-directory for a given ange-ftp buffer. | |
4201 (defun ange-ftp-unhandled-file-name-directory (filename) | |
91583
846fe57f9c57
(ange-ftp-unhandled-file-name-directory):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
4202 nil) |
28210 | 4203 |
4204 | |
4205 ;; Need the following functions for making filenames of compressed | |
4206 ;; files, because some OS's (unlike UNIX) do not allow a filename to | |
4207 ;; have two extensions. | |
4208 | |
4209 (defvar ange-ftp-make-compressed-filename-alist nil | |
4210 "Alist of host-type-specific functions to process file names for compression. | |
4211 Each element has the form (TYPE . FUNC). | |
4212 FUNC should take one argument, a file name, and return a list | |
4213 of the form (COMPRESSING NEWNAME). | |
30459 | 4214 COMPRESSING should be t if the specified file should be compressed, |
28210 | 4215 and nil if it should be uncompressed (that is, if it is a compressed file). |
4216 NEWNAME should be the name to give the new compressed or uncompressed file.") | |
4217 | |
104933
5d527d3bf1fa
(dired-compress-file): Declare.
Glenn Morris <rgm@gnu.org>
parents:
104733
diff
changeset
|
4218 (declare-function dired-compress-file "dired-aux" (file)) |
5d527d3bf1fa
(dired-compress-file): Declare.
Glenn Morris <rgm@gnu.org>
parents:
104733
diff
changeset
|
4219 |
28210 | 4220 (defun ange-ftp-dired-compress-file (name) |
104933
5d527d3bf1fa
(dired-compress-file): Declare.
Glenn Morris <rgm@gnu.org>
parents:
104733
diff
changeset
|
4221 "Handler used by `dired-compress-file'." |
28210 | 4222 (let ((parsed (ange-ftp-ftp-name name)) |
4223 conversion-func) | |
4224 (if (and parsed | |
4225 (setq conversion-func | |
4226 (cdr (assq (ange-ftp-host-type (car parsed)) | |
4227 ange-ftp-make-compressed-filename-alist)))) | |
4228 (let* ((decision | |
4229 (save-match-data (funcall conversion-func name))) | |
4230 (compressing (car decision)) | |
4231 (newfile (nth 1 decision))) | |
4232 (if compressing | |
4233 (ange-ftp-compress name newfile) | |
4234 (ange-ftp-uncompress name newfile))) | |
4235 (let (file-name-handler-alist) | |
4236 (dired-compress-file name))))) | |
4237 | |
4238 ;; Copy FILE to this machine, compress it, and copy out to NFILE. | |
4239 (defun ange-ftp-compress (file nfile) | |
4240 (let* ((parsed (ange-ftp-ftp-name file)) | |
4241 (tmp1 (ange-ftp-make-tmp-name (car parsed))) | |
4242 (tmp2 (ange-ftp-make-tmp-name (car parsed))) | |
4243 (abbr (ange-ftp-abbreviate-filename file)) | |
4244 (nabbr (ange-ftp-abbreviate-filename nfile)) | |
4245 (msg1 (format "Getting %s" abbr)) | |
4246 (msg2 (format "Putting %s" nabbr))) | |
4247 (unwind-protect | |
4248 (progn | |
4249 (ange-ftp-copy-file-internal file tmp1 t nil msg1) | |
4250 (and ange-ftp-process-verbose | |
4251 (ange-ftp-message "Compressing %s..." abbr)) | |
4252 (call-process-region (point) | |
4253 (point) | |
4254 shell-file-name | |
4255 nil | |
4256 t | |
4257 nil | |
4258 "-c" | |
4259 (format "compress -f -c < %s > %s" tmp1 tmp2)) | |
4260 (and ange-ftp-process-verbose | |
4261 (ange-ftp-message "Compressing %s...done" abbr)) | |
4262 (if (zerop (buffer-size)) | |
4263 (progn | |
4264 (let (ange-ftp-process-verbose) | |
4265 (delete-file file)) | |
4266 (ange-ftp-copy-file-internal tmp2 nfile t nil msg2)))) | |
4267 (ange-ftp-del-tmp-name tmp1) | |
4268 (ange-ftp-del-tmp-name tmp2)))) | |
30459 | 4269 |
28210 | 4270 ;; Copy FILE to this machine, uncompress it, and copy out to NFILE. |
4271 (defun ange-ftp-uncompress (file nfile) | |
4272 (let* ((parsed (ange-ftp-ftp-name file)) | |
4273 (tmp1 (ange-ftp-make-tmp-name (car parsed))) | |
4274 (tmp2 (ange-ftp-make-tmp-name (car parsed))) | |
4275 (abbr (ange-ftp-abbreviate-filename file)) | |
4276 (nabbr (ange-ftp-abbreviate-filename nfile)) | |
4277 (msg1 (format "Getting %s" abbr)) | |
4278 (msg2 (format "Putting %s" nabbr)) | |
4279 ;; ;; Cheap hack because of problems with binary file transfers from | |
4280 ;; ;; VMS hosts. | |
4281 ;; (gbinary (not (eq 'vms (ange-ftp-host-type (car parsed))))) | |
4282 ) | |
4283 (unwind-protect | |
4284 (progn | |
4285 (ange-ftp-copy-file-internal file tmp1 t nil msg1) | |
4286 (and ange-ftp-process-verbose | |
4287 (ange-ftp-message "Uncompressing %s..." abbr)) | |
4288 (call-process-region (point) | |
4289 (point) | |
4290 shell-file-name | |
4291 nil | |
4292 t | |
4293 nil | |
4294 "-c" | |
4295 (format "uncompress -c < %s > %s" tmp1 tmp2)) | |
4296 (and ange-ftp-process-verbose | |
4297 (ange-ftp-message "Uncompressing %s...done" abbr)) | |
4298 (if (zerop (buffer-size)) | |
4299 (progn | |
4300 (let (ange-ftp-process-verbose) | |
4301 (delete-file file)) | |
4302 (ange-ftp-copy-file-internal tmp2 nfile t nil msg2)))) | |
4303 (ange-ftp-del-tmp-name tmp1) | |
4304 (ange-ftp-del-tmp-name tmp2)))) | |
4305 | |
4306 (defun ange-ftp-find-backup-file-name (fn) | |
4307 ;; Either return the ordinary backup name, etc., | |
4308 ;; or return nil meaning don't make a backup. | |
4309 (if ange-ftp-make-backup-files | |
4310 (ange-ftp-real-find-backup-file-name fn))) | |
4311 | |
4312 ;;; Define the handler for special file names | |
4313 ;;; that causes ange-ftp to be invoked. | |
4314 | |
4315 ;;;###autoload | |
4316 (defun ange-ftp-hook-function (operation &rest args) | |
4317 (let ((fn (get operation 'ange-ftp))) | |
78422
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4318 (if fn |
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4319 ;; Catch also errors in process-filter. |
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4320 (condition-case err |
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4321 (let ((debug-on-error t)) |
5f8e4804505c
* net/ange-ftp.el (ange-ftp-hook-function): Catch also errors in
Michael Albinus <michael.albinus@gmx.de>
parents:
78230
diff
changeset
|
4322 (save-match-data (apply fn args))) |
78423
ca1e15221b34
*** empty log message ***
Michael Albinus <michael.albinus@gmx.de>
parents:
78422
diff
changeset
|
4323 (error (signal (car err) (cdr err)))) |
28210 | 4324 (ange-ftp-run-real-handler operation args)))) |
4325 | |
46349
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4326 ;; The following code is commented out because Tramp now deals with |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4327 ;; Ange-FTP filenames, too. |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4328 |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4329 ;;-;;; This regexp takes care of real ange-ftp file names (with a slash |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4330 ;;-;;; and colon). |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4331 ;;-;;; Don't allow the host name to end in a period--some systems use /.: |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4332 ;;-;;;###autoload |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4333 ;;-(or (assoc "^/[^/:]*[^/:.]:" file-name-handler-alist) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4334 ;;- (setq file-name-handler-alist |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4335 ;;- (cons '("^/[^/:]*[^/:.]:" . ange-ftp-hook-function) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4336 ;;- file-name-handler-alist))) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4337 ;;- |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4338 ;;-;;; This regexp recognizes absolute filenames with only one component, |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4339 ;;-;;; for the sake of hostname completion. |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4340 ;;-;;;###autoload |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4341 ;;-(or (assoc "^/[^/:]*\\'" file-name-handler-alist) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4342 ;;- (setq file-name-handler-alist |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4343 ;;- (cons '("^/[^/:]*\\'" . ange-ftp-completion-hook-function) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4344 ;;- file-name-handler-alist))) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4345 ;;- |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4346 ;;-;;; This regexp recognizes absolute filenames with only one component |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4347 ;;-;;; on Windows, for the sake of hostname completion. |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4348 ;;-;;; NB. Do not mark this as autoload, because it is very common to |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4349 ;;-;;; do completions in the root directory of drives on Windows. |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4350 ;;-(and (memq system-type '(ms-dos windows-nt)) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4351 ;;- (or (assoc "^[a-zA-Z]:/[^/:]*\\'" file-name-handler-alist) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4352 ;;- (setq file-name-handler-alist |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4353 ;;- (cons '("^[a-zA-Z]:/[^/:]*\\'" . |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4354 ;;- ange-ftp-completion-hook-function) |
4f0aafa6b3bf
Do not hook into file-name-handler-alist, this
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
46336
diff
changeset
|
4355 ;;- file-name-handler-alist)))) |
28210 | 4356 |
4357 ;;; The above two forms are sufficient to cause this file to be loaded | |
4358 ;;; if the user ever uses a file name with a colon in it. | |
4359 | |
30459 | 4360 ;;; This sets the mode |
46178
cd546ee24e14
Use add-hook and find-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46143
diff
changeset
|
4361 (add-hook 'find-file-hook 'ange-ftp-set-buffer-mode) |
28210 | 4362 |
4363 ;;; Now say where to find the handlers for particular operations. | |
4364 | |
4365 (put 'file-name-directory 'ange-ftp 'ange-ftp-file-name-directory) | |
4366 (put 'file-name-nondirectory 'ange-ftp 'ange-ftp-file-name-nondirectory) | |
4367 (put 'file-name-as-directory 'ange-ftp 'ange-ftp-file-name-as-directory) | |
4368 (put 'directory-file-name 'ange-ftp 'ange-ftp-directory-file-name) | |
4369 (put 'expand-file-name 'ange-ftp 'ange-ftp-expand-file-name) | |
4370 (put 'make-directory 'ange-ftp 'ange-ftp-make-directory) | |
4371 (put 'delete-directory 'ange-ftp 'ange-ftp-delete-directory) | |
4372 (put 'insert-file-contents 'ange-ftp 'ange-ftp-insert-file-contents) | |
4373 (put 'directory-files 'ange-ftp 'ange-ftp-directory-files) | |
106309
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
4374 (put 'directory-files-and-attributes 'ange-ftp |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
4375 'ange-ftp-directory-files-and-attributes) |
28210 | 4376 (put 'file-directory-p 'ange-ftp 'ange-ftp-file-directory-p) |
4377 (put 'file-writable-p 'ange-ftp 'ange-ftp-file-writable-p) | |
4378 (put 'file-readable-p 'ange-ftp 'ange-ftp-file-readable-p) | |
4379 (put 'file-executable-p 'ange-ftp 'ange-ftp-file-executable-p) | |
4380 (put 'file-symlink-p 'ange-ftp 'ange-ftp-file-symlink-p) | |
4381 (put 'delete-file 'ange-ftp 'ange-ftp-delete-file) | |
4382 (put 'verify-visited-file-modtime 'ange-ftp | |
4383 'ange-ftp-verify-visited-file-modtime) | |
4384 (put 'file-exists-p 'ange-ftp 'ange-ftp-file-exists-p) | |
4385 (put 'write-region 'ange-ftp 'ange-ftp-write-region) | |
4386 (put 'copy-file 'ange-ftp 'ange-ftp-copy-file) | |
4387 (put 'rename-file 'ange-ftp 'ange-ftp-rename-file) | |
4388 (put 'file-attributes 'ange-ftp 'ange-ftp-file-attributes) | |
30481 | 4389 (put 'file-newer-than-file-p 'ange-ftp 'ange-ftp-file-newer-than-file-p) |
28210 | 4390 (put 'file-name-all-completions 'ange-ftp 'ange-ftp-file-name-all-completions) |
4391 (put 'file-name-completion 'ange-ftp 'ange-ftp-file-name-completion) | |
4392 (put 'insert-directory 'ange-ftp 'ange-ftp-insert-directory) | |
4393 (put 'file-local-copy 'ange-ftp 'ange-ftp-file-local-copy) | |
55846
aed680fa845d
(ange-ftp-file-remote-p): New defun.
Michael Albinus <michael.albinus@gmx.de>
parents:
53500
diff
changeset
|
4394 (put 'file-remote-p 'ange-ftp 'ange-ftp-file-remote-p) |
28210 | 4395 (put 'unhandled-file-name-directory 'ange-ftp |
4396 'ange-ftp-unhandled-file-name-directory) | |
4397 (put 'file-name-sans-versions 'ange-ftp 'ange-ftp-file-name-sans-versions) | |
4398 (put 'dired-uncache 'ange-ftp 'ange-ftp-dired-uncache) | |
4399 (put 'dired-compress-file 'ange-ftp 'ange-ftp-dired-compress-file) | |
4400 (put 'load 'ange-ftp 'ange-ftp-load) | |
4401 (put 'find-backup-file-name 'ange-ftp 'ange-ftp-find-backup-file-name) | |
102850
0bb3e7671842
* net/ange-ftp.el (ange-ftp-set-file-modes): New defun. Change
Michael Albinus <michael.albinus@gmx.de>
parents:
102715
diff
changeset
|
4402 (put 'set-file-modes 'ange-ftp 'ange-ftp-set-file-modes) |
28210 | 4403 |
4404 ;; Turn off truename processing to save time. | |
4405 ;; Treat each name as its own truename. | |
4406 (put 'file-truename 'ange-ftp 'identity) | |
4407 | |
83791
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4408 ;; We must return non-nil in order to mask our inability to do the job. |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4409 ;; Otherwise there are errors when applied to the target file during |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4410 ;; copying from a (localhost) Tramp file. |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4411 (put 'set-file-times 'ange-ftp 'ignore) |
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4412 |
28210 | 4413 ;; Turn off RCS/SCCS processing to save time. |
4414 ;; This returns nil for any file name as argument. | |
4415 (put 'vc-registered 'ange-ftp 'null) | |
4416 | |
81758
f03856eb136b
* files.el (file-remote-p): Introduce optional parameter CONNECTED.
Michael Albinus <michael.albinus@gmx.de>
parents:
81639
diff
changeset
|
4417 ;; We can handle process-file in a restricted way (just for chown). |
83791
cf51047dc34c
* net/ange-ftp.el: Add ange-ftp property to 'set-file-modes and
Michael Albinus <michael.albinus@gmx.de>
parents:
82287
diff
changeset
|
4418 ;; Nothing possible for `start-file-process'. |
81639
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
76407
diff
changeset
|
4419 (put 'process-file 'ange-ftp 'ange-ftp-process-file) |
81758
f03856eb136b
* files.el (file-remote-p): Introduce optional parameter CONNECTED.
Michael Albinus <michael.albinus@gmx.de>
parents:
81639
diff
changeset
|
4420 (put 'start-file-process 'ange-ftp 'ignore) |
28210 | 4421 (put 'shell-command 'ange-ftp 'ange-ftp-shell-command) |
4422 | |
4423 ;;; Define ways of getting at unmodified Emacs primitives, | |
4424 ;;; turning off our handler. | |
4425 | |
4426 (defun ange-ftp-run-real-handler (operation args) | |
4427 (let ((inhibit-file-name-handlers | |
4428 (cons 'ange-ftp-hook-function | |
4429 (cons 'ange-ftp-completion-hook-function | |
4430 (and (eq inhibit-file-name-operation operation) | |
4431 inhibit-file-name-handlers)))) | |
4432 (inhibit-file-name-operation operation)) | |
4433 (apply operation args))) | |
4434 | |
4435 (defun ange-ftp-real-file-name-directory (&rest args) | |
4436 (ange-ftp-run-real-handler 'file-name-directory args)) | |
4437 (defun ange-ftp-real-file-name-nondirectory (&rest args) | |
4438 (ange-ftp-run-real-handler 'file-name-nondirectory args)) | |
4439 (defun ange-ftp-real-file-name-as-directory (&rest args) | |
4440 (ange-ftp-run-real-handler 'file-name-as-directory args)) | |
4441 (defun ange-ftp-real-directory-file-name (&rest args) | |
4442 (ange-ftp-run-real-handler 'directory-file-name args)) | |
4443 (defun ange-ftp-real-expand-file-name (&rest args) | |
4444 (ange-ftp-run-real-handler 'expand-file-name args)) | |
4445 (defun ange-ftp-real-make-directory (&rest args) | |
4446 (ange-ftp-run-real-handler 'make-directory args)) | |
4447 (defun ange-ftp-real-delete-directory (&rest args) | |
4448 (ange-ftp-run-real-handler 'delete-directory args)) | |
4449 (defun ange-ftp-real-insert-file-contents (&rest args) | |
4450 (ange-ftp-run-real-handler 'insert-file-contents args)) | |
4451 (defun ange-ftp-real-directory-files (&rest args) | |
4452 (ange-ftp-run-real-handler 'directory-files args)) | |
106309
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
4453 (defun ange-ftp-real-directory-files-and-attributes (&rest args) |
9470a3d1abee
* net/ange-ftp.el (ange-ftp-parse-filename): Use `save-match-data'.
Michael Albinus <michael.albinus@gmx.de>
parents:
105811
diff
changeset
|
4454 (ange-ftp-run-real-handler 'directory-files-and-attributes args)) |
28210 | 4455 (defun ange-ftp-real-file-directory-p (&rest args) |
4456 (ange-ftp-run-real-handler 'file-directory-p args)) | |
4457 (defun ange-ftp-real-file-writable-p (&rest args) | |
4458 (ange-ftp-run-real-handler 'file-writable-p args)) | |
4459 (defun ange-ftp-real-file-readable-p (&rest args) | |
4460 (ange-ftp-run-real-handler 'file-readable-p args)) | |
4461 (defun ange-ftp-real-file-executable-p (&rest args) | |
4462 (ange-ftp-run-real-handler 'file-executable-p args)) | |
4463 (defun ange-ftp-real-file-symlink-p (&rest args) | |
4464 (ange-ftp-run-real-handler 'file-symlink-p args)) | |
4465 (defun ange-ftp-real-delete-file (&rest args) | |
4466 (ange-ftp-run-real-handler 'delete-file args)) | |
4467 (defun ange-ftp-real-verify-visited-file-modtime (&rest args) | |
4468 (ange-ftp-run-real-handler 'verify-visited-file-modtime args)) | |
4469 (defun ange-ftp-real-file-exists-p (&rest args) | |
4470 (ange-ftp-run-real-handler 'file-exists-p args)) | |
4471 (defun ange-ftp-real-write-region (&rest args) | |
4472 (ange-ftp-run-real-handler 'write-region args)) | |
4473 (defun ange-ftp-real-backup-buffer (&rest args) | |
4474 (ange-ftp-run-real-handler 'backup-buffer args)) | |
4475 (defun ange-ftp-real-copy-file (&rest args) | |
4476 (ange-ftp-run-real-handler 'copy-file args)) | |
4477 (defun ange-ftp-real-rename-file (&rest args) | |
4478 (ange-ftp-run-real-handler 'rename-file args)) | |
4479 (defun ange-ftp-real-file-attributes (&rest args) | |
4480 (ange-ftp-run-real-handler 'file-attributes args)) | |
30481 | 4481 (defun ange-ftp-real-file-newer-than-file-p (&rest args) |
4482 (ange-ftp-run-real-handler 'file-newer-than-file-p args)) | |
28210 | 4483 (defun ange-ftp-real-file-name-all-completions (&rest args) |
4484 (ange-ftp-run-real-handler 'file-name-all-completions args)) | |
4485 (defun ange-ftp-real-file-name-completion (&rest args) | |
4486 (ange-ftp-run-real-handler 'file-name-completion args)) | |
4487 (defun ange-ftp-real-insert-directory (&rest args) | |
4488 (ange-ftp-run-real-handler 'insert-directory args)) | |
4489 (defun ange-ftp-real-file-name-sans-versions (&rest args) | |
4490 (ange-ftp-run-real-handler 'file-name-sans-versions args)) | |
4491 (defun ange-ftp-real-shell-command (&rest args) | |
4492 (ange-ftp-run-real-handler 'shell-command args)) | |
4493 (defun ange-ftp-real-load (&rest args) | |
4494 (ange-ftp-run-real-handler 'load args)) | |
4495 (defun ange-ftp-real-find-backup-file-name (&rest args) | |
4496 (ange-ftp-run-real-handler 'find-backup-file-name args)) | |
4497 | |
4498 ;; Here we support using dired on remote hosts. | |
4499 ;; I have turned off the support for using dired on foreign directory formats. | |
4500 ;; That involves too many unclean hooks. | |
30459 | 4501 ;; It would be cleaner to support such operations by |
28210 | 4502 ;; converting the foreign directory format to something dired can understand; |
4503 ;; something close to ls -l output. | |
4504 ;; The logical place to do this is in the functions ange-ftp-parse-...-listing. | |
4505 | |
4506 ;; Some of the old dired hooks would still be needed even if this is done. | |
4507 ;; I have preserved (and modernized) those hooks. | |
4508 ;; So the format conversion should be all that is needed. | |
4509 | |
47575
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
4510 ;; When called from dired, SWITCHES may start with "--dired". |
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
4511 ;; `ange-ftp-ls' handles this. |
4d9f899a5963
* dired.el (dired-insert-directory): Always add "--dired" to to
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
47113
diff
changeset
|
4512 |
28210 | 4513 (defun ange-ftp-insert-directory (file switches &optional wildcard full) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4514 (if (not (ange-ftp-ftp-name (expand-file-name file))) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4515 (ange-ftp-real-insert-directory file switches wildcard full) |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4516 ;; We used to follow symlinks on `file' here. Apparently it was done |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4517 ;; because some FTP servers react to "ls foo" by listing the symlink foo |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4518 ;; rather than the directory it points to. Now that ange-ftp-ls uses |
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4519 ;; "cd foo; ls" instead, this is not necesssary any more. |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4520 (insert |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4521 (cond |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4522 (wildcard |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4523 (let ((default-directory (file-name-directory file))) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4524 (ange-ftp-ls (file-name-nondirectory file) switches nil nil t))) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4525 (full |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4526 (ange-ftp-ls file switches 'parse)) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4527 (t |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4528 ;; If `full' is nil we're going to do `ls' for a single file. |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4529 ;; Problem is that for various reasons, ange-ftp-ls needs to cd and |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4530 ;; then do an ls of current dir, which obviously won't work if we |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4531 ;; want to ls a file. So instead, we get a full listing of the |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4532 ;; parent directory and extract the line corresponding to `file'. |
102225
d79785ea1088
(ange-ftp-insert-directory): Adapt switch manipulation to 2009-02-11
Chong Yidong <cyd@stupidchicken.com>
parents:
100908
diff
changeset
|
4533 (when (string-match "-?d\\'" switches) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4534 ;; Remove "d" which dired added to `switches'. |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4535 (setq switches (substring switches 0 (match-beginning 0)))) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4536 (let* ((dirlist (ange-ftp-ls (or (file-name-directory file) ".") |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4537 switches nil)) |
65791
5121212db622
(ange-ftp-insert-directory): Fix up the search when `file' is absolute.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65790
diff
changeset
|
4538 (filename (file-name-nondirectory (directory-file-name file))) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4539 (case-fold-search nil)) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4540 ;; FIXME: This presumes a particular output format, which is |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4541 ;; basically Unix. |
65791
5121212db622
(ange-ftp-insert-directory): Fix up the search when `file' is absolute.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65790
diff
changeset
|
4542 (if (string-match (concat "^.+[^ ] " (regexp-quote filename) |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4543 "\\( -> .*\\)?[@/*=]?\n") dirlist) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4544 (match-string 0 dirlist) |
107040
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4545 ""))))) |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4546 |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4547 ;; The inserted file could be from somewhere else. |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4548 (when (and (not wildcard) (not full) |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4549 (search-backward |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4550 (if (zerop (length (file-name-nondirectory |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4551 (expand-file-name file)))) |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4552 "." |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4553 (file-name-nondirectory file)) |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4554 nil 'noerror)) |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4555 (replace-match (file-relative-name (expand-file-name file)) t) |
5555e86608c1
* net/ange-ftp.el (ange-ftp-insert-directory): Handle the case,
Michael Albinus <albinus@detlef>
parents:
106815
diff
changeset
|
4556 (goto-char (point-max))))) |
28210 | 4557 |
4558 (defun ange-ftp-dired-uncache (dir) | |
4559 (if (ange-ftp-ftp-name (expand-file-name dir)) | |
4560 (setq ange-ftp-ls-cache-file nil))) | |
4561 | |
4562 (defvar ange-ftp-sans-version-alist nil | |
4563 "Alist of mapping host type into function to remove file version numbers.") | |
4564 | |
4565 (defun ange-ftp-file-name-sans-versions (file keep-backup-version) | |
4566 (let* ((short (ange-ftp-abbreviate-filename file)) | |
4567 (parsed (ange-ftp-ftp-name short)) | |
65762
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4568 (func (if parsed (cdr (assq (ange-ftp-host-type (car parsed)) |
77dd61f8bf51
(ange-ftp-gwp-start): Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65516
diff
changeset
|
4569 ange-ftp-sans-version-alist))))) |
28210 | 4570 (if func (funcall func file keep-backup-version) |
4571 (ange-ftp-real-file-name-sans-versions file keep-backup-version)))) | |
4572 | |
4573 ;; This is the handler for shell-command. | |
4574 (defun ange-ftp-shell-command (command &optional output-buffer error-buffer) | |
4575 (let* ((parsed (ange-ftp-ftp-name default-directory)) | |
4576 (host (nth 0 parsed)) | |
4577 (user (nth 1 parsed)) | |
4578 (name (nth 2 parsed))) | |
4579 (if (not parsed) | |
4580 (ange-ftp-real-shell-command command output-buffer error-buffer) | |
4581 (if (> (length name) 0) ; else it's $HOME | |
4582 (setq command (concat "cd " name "; " command))) | |
42495
09f1b967d12e
(ange-ftp-shell-command): Remove port specification from the hostname.
Pavel Janík <Pavel@Janik.cz>
parents:
42397
diff
changeset
|
4583 ;; Remove port from the hostname |
42740
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4584 (when (string-match "\\(.*\\)#" host) |
50a74884f960
(ange-ftp-root-dir-p): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
42706
diff
changeset
|
4585 (setq host (match-string 1 host))) |
28210 | 4586 (setq command |
4587 (format "%s %s \"%s\"" ; remsh -l USER does not work well | |
4588 ; on a hp-ux machine I tried | |
4589 remote-shell-program host command)) | |
4590 (ange-ftp-message "Remote command '%s' ..." command) | |
4591 ;; Cannot call ange-ftp-real-dired-run-shell-command here as it | |
4592 ;; would prepend "cd default-directory" --- which bombs because | |
4593 ;; default-directory is in ange-ftp syntax for remote file names. | |
4594 (ange-ftp-real-shell-command command output-buffer error-buffer)))) | |
4595 | |
81639
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
76407
diff
changeset
|
4596 ;;; This is the handler for process-file. |
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
76407
diff
changeset
|
4597 (defun ange-ftp-process-file (program infile buffer display &rest arguments) |
28210 | 4598 ;; PROGRAM is always one of those below in the cond in dired.el. |
4599 ;; The ARGUMENTS are (nearly) always files. | |
4600 (if (ange-ftp-ftp-name default-directory) | |
4601 ;; Can't use ange-ftp-dired-host-type here because the current | |
4602 ;; buffer is *dired-check-process output* | |
4603 (condition-case oops | |
105811
18865054beee
(top-level): Don't require dired when compiling.
Glenn Morris <rgm@gnu.org>
parents:
105658
diff
changeset
|
4604 (cond ((equal (or (bound-and-true-p dired-chmod-program) "chmod") |
18865054beee
(top-level): Don't require dired when compiling.
Glenn Morris <rgm@gnu.org>
parents:
105658
diff
changeset
|
4605 program) |
28210 | 4606 (ange-ftp-call-chmod arguments)) |
4607 ;; ((equal "chgrp" program)) | |
4608 ;; ((equal dired-chown-program program)) | |
4609 (t (error "Unknown remote command: %s" program))) | |
4610 (ftp-error (insert (format "%s: %s, %s\n" | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4611 (nth 1 oops) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4612 (nth 2 oops) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4613 (nth 3 oops))) |
28210 | 4614 ;; Caller expects nonzero value to mean failure. |
4615 1) | |
4616 (error (insert (format "%s\n" (nth 1 oops))) | |
4617 1)) | |
81639
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
76407
diff
changeset
|
4618 (apply 'call-process program infile buffer display arguments))) |
28210 | 4619 |
4620 ;; Handle an attempt to run chmod on a remote file | |
4621 ;; by using the ftp chmod command. | |
4622 (defun ange-ftp-call-chmod (args) | |
4623 (if (< (length args) 2) | |
4624 (error "ange-ftp-call-chmod: missing mode and/or filename: %s" args)) | |
4625 (let ((mode (car args)) | |
4626 (rest (cdr args))) | |
4627 (if (equal "--" (car rest)) | |
4628 (setq rest (cdr rest))) | |
84913
db1179979d6b
(ange-ftp-call-chmod, ange-ftp-parse-bs2000-listing):
Juanma Barranquero <lekktu@gmail.com>
parents:
83791
diff
changeset
|
4629 (mapc |
30459 | 4630 (lambda (file) |
4631 (setq file (expand-file-name file)) | |
4632 (let ((parsed (ange-ftp-ftp-name file))) | |
4633 (if parsed | |
4634 (let* ((host (nth 0 parsed)) | |
4635 (user (nth 1 parsed)) | |
4636 (name (ange-ftp-quote-string (nth 2 parsed))) | |
4637 (abbr (ange-ftp-abbreviate-filename file)) | |
4638 (result (ange-ftp-send-cmd host user | |
4639 (list 'chmod mode name) | |
4640 (format "doing chmod %s" | |
4641 abbr)))) | |
4642 (or (car result) | |
102850
0bb3e7671842
* net/ange-ftp.el (ange-ftp-set-file-modes): New defun. Change
Michael Albinus <michael.albinus@gmx.de>
parents:
102715
diff
changeset
|
4643 (ange-ftp-error |
0bb3e7671842
* net/ange-ftp.el (ange-ftp-set-file-modes): New defun. Change
Michael Albinus <michael.albinus@gmx.de>
parents:
102715
diff
changeset
|
4644 host user (concat "CHMOD failed: " (cdr result)))))))) |
28210 | 4645 rest)) |
4646 (setq ange-ftp-ls-cache-file nil) ;Stop confusing Dired. | |
4647 0) | |
102850
0bb3e7671842
* net/ange-ftp.el (ange-ftp-set-file-modes): New defun. Change
Michael Albinus <michael.albinus@gmx.de>
parents:
102715
diff
changeset
|
4648 |
0bb3e7671842
* net/ange-ftp.el (ange-ftp-set-file-modes): New defun. Change
Michael Albinus <michael.albinus@gmx.de>
parents:
102715
diff
changeset
|
4649 (defun ange-ftp-set-file-modes (filename mode) |
0bb3e7671842
* net/ange-ftp.el (ange-ftp-set-file-modes): New defun. Change
Michael Albinus <michael.albinus@gmx.de>
parents:
102715
diff
changeset
|
4650 (ange-ftp-call-chmod (list (format "%o" mode) filename))) |
28210 | 4651 |
64667
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
4652 ;; This is turned off because it has nothing properly to do |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
4653 ;; with dired. It could be reasonable to adapt this to |
04315354635e
(ange-ftp-gateway-fatal-msgs, ange-ftp-pending-error-line): New vars.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64085
diff
changeset
|
4654 ;; replace ange-ftp-copy-file. |
28210 | 4655 |
4656 ;;;;; ------------------------------------------------------------ | |
4657 ;;;;; Noddy support for async copy-file within dired. | |
4658 ;;;;; ------------------------------------------------------------ | |
4659 | |
4660 ;;(defun ange-ftp-dired-copy-file (from to ok-flag &optional cont nowait) | |
4661 ;; "Documented as original." | |
4662 ;; (dired-handle-overwrite to) | |
4663 ;; (ange-ftp-copy-file-internal from to ok-flag dired-copy-preserve-time nil | |
4664 ;; cont nowait)) | |
4665 | |
4666 ;;(defun ange-ftp-dired-do-create-files (op-symbol file-creator operation arg | |
4667 ;; &optional marker-char op1 | |
4668 ;; how-to) | |
4669 ;; "Documented as original." | |
4670 ;; ;; we need to let ange-ftp-dired-create-files know that we indirectly | |
4671 ;; ;; called it rather than somebody else. | |
4672 ;; (let ((ange-ftp-dired-do-create-files t)) ; tell who caller is | |
4673 ;; (ange-ftp-real-dired-do-create-files op-symbol file-creator operation | |
4674 ;; arg marker-char op1 how-to))) | |
4675 | |
4676 ;;(defun ange-ftp-dired-create-files (file-creator operation fn-list name-constructor | |
4677 ;; &optional marker-char) | |
4678 ;; "Documented as original." | |
4679 ;; (if (and (boundp 'ange-ftp-dired-do-create-files) | |
4680 ;; ;; called from ange-ftp-dired-do-create-files? | |
4681 ;; ange-ftp-dired-do-create-files | |
4682 ;; ;; any files worth copying? | |
4683 ;; fn-list | |
4684 ;; ;; we only support async copy-file at the mo. | |
4685 ;; (eq file-creator 'dired-copy-file) | |
4686 ;; ;; it is only worth calling the alternative function for remote files | |
4687 ;; ;; as we tie ourself in recursive knots otherwise. | |
4688 ;; (or (ange-ftp-ftp-name (car fn-list)) | |
4689 ;; ;; we can only call the name constructor for dired-do-create-files | |
4690 ;; ;; since the one for regexps starts prompting here, there and | |
4691 ;; ;; everywhere. | |
4692 ;; (ange-ftp-ftp-name (funcall name-constructor (car fn-list))))) | |
4693 ;; ;; use the process-filter driven routine rather than the iterative one. | |
4694 ;; (ange-ftp-dcf-1 file-creator | |
4695 ;; operation | |
4696 ;; fn-list | |
4697 ;; name-constructor | |
4698 ;; (and (boundp 'target) target) ;dynamically bound | |
4699 ;; marker-char | |
4700 ;; (current-buffer) | |
4701 ;; nil ;overwrite-query | |
4702 ;; nil ;overwrite-backup-query | |
4703 ;; nil ;failures | |
4704 ;; nil ;skipped | |
4705 ;; 0 ;success-count | |
4706 ;; (length fn-list) ;total | |
4707 ;; ) | |
4708 ;; ;; normal case... use the interactive routine... much cheaper. | |
4709 ;; (ange-ftp-real-dired-create-files file-creator operation fn-list | |
4710 ;; name-constructor marker-char))) | |
4711 | |
4712 ;;(defun ange-ftp-dcf-1 (file-creator operation fn-list name-constructor | |
30459 | 4713 ;; target marker-char buffer overwrite-query |
28210 | 4714 ;; overwrite-backup-query failures skipped |
4715 ;; success-count total) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4716 ;; (with-current-buffer buffer |
28210 | 4717 ;; (if (null fn-list) |
4718 ;; (ange-ftp-dcf-3 failures operation total skipped | |
4719 ;; success-count buffer) | |
30459 | 4720 |
28210 | 4721 ;; (let* ((from (car fn-list)) |
4722 ;; (to (funcall name-constructor from))) | |
4723 ;; (if (equal to from) | |
4724 ;; (progn | |
4725 ;; (setq to nil) | |
4726 ;; (dired-log "Cannot %s to same file: %s\n" | |
4727 ;; (downcase operation) from))) | |
4728 ;; (if (not to) | |
4729 ;; (ange-ftp-dcf-1 file-creator | |
4730 ;; operation | |
4731 ;; (cdr fn-list) | |
4732 ;; name-constructor | |
4733 ;; target | |
4734 ;; marker-char | |
4735 ;; buffer | |
4736 ;; overwrite-query | |
4737 ;; overwrite-backup-query | |
4738 ;; failures | |
4739 ;; (cons (dired-make-relative from) skipped) | |
4740 ;; success-count | |
4741 ;; total) | |
4742 ;; (let* ((overwrite (file-exists-p to)) | |
4743 ;; (overwrite-confirmed ; for dired-handle-overwrite | |
4744 ;; (and overwrite | |
4745 ;; (let ((help-form '(format "\ | |
4746 ;;Type SPC or `y' to overwrite file `%s', | |
4747 ;;DEL or `n' to skip to next, | |
4748 ;;ESC or `q' to not overwrite any of the remaining files, | |
4749 ;;`!' to overwrite all remaining files with no more questions." to))) | |
4750 ;; (dired-query 'overwrite-query | |
4751 ;; "Overwrite `%s'?" to)))) | |
4752 ;; ;; must determine if FROM is marked before file-creator | |
4753 ;; ;; gets a chance to delete it (in case of a move). | |
4754 ;; (actual-marker-char | |
4755 ;; (cond ((integerp marker-char) marker-char) | |
4756 ;; (marker-char (dired-file-marker from)) ; slow | |
4757 ;; (t nil)))) | |
4758 ;; (condition-case err | |
4759 ;; (funcall file-creator from to overwrite-confirmed | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4760 ;; (list 'ange-ftp-dcf-2 |
28210 | 4761 ;; nil ;err |
4762 ;; file-creator operation fn-list | |
4763 ;; name-constructor | |
4764 ;; target | |
4765 ;; marker-char actual-marker-char | |
4766 ;; buffer to from | |
4767 ;; overwrite | |
4768 ;; overwrite-confirmed | |
30459 | 4769 ;; overwrite-query |
28210 | 4770 ;; overwrite-backup-query |
4771 ;; failures skipped success-count | |
4772 ;; total) | |
4773 ;; t) | |
4774 ;; (file-error ; FILE-CREATOR aborted | |
4775 ;; (ange-ftp-dcf-2 nil ;result | |
4776 ;; nil ;line | |
4777 ;; err | |
4778 ;; file-creator operation fn-list | |
4779 ;; name-constructor | |
4780 ;; target | |
4781 ;; marker-char actual-marker-char | |
4782 ;; buffer to from | |
4783 ;; overwrite | |
4784 ;; overwrite-confirmed | |
30459 | 4785 ;; overwrite-query |
28210 | 4786 ;; overwrite-backup-query |
4787 ;; failures skipped success-count | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4788 ;; total))))))))) |
28210 | 4789 |
4790 ;;(defun ange-ftp-dcf-2 (result line err | |
4791 ;; file-creator operation fn-list | |
4792 ;; name-constructor | |
4793 ;; target | |
4794 ;; marker-char actual-marker-char | |
4795 ;; buffer to from | |
4796 ;; overwrite | |
4797 ;; overwrite-confirmed | |
30459 | 4798 ;; overwrite-query |
28210 | 4799 ;; overwrite-backup-query |
4800 ;; failures skipped success-count | |
4801 ;; total) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4802 ;; (with-current-buffer buffer |
28210 | 4803 ;; (if (or err (not result)) |
4804 ;; (progn | |
4805 ;; (setq failures (cons (dired-make-relative from) failures)) | |
4806 ;; (dired-log "%s `%s' to `%s' failed:\n%s\n" | |
4807 ;; operation from to (or err line))) | |
4808 ;; (if overwrite | |
4809 ;; ;; If we get here, file-creator hasn't been aborted | |
4810 ;; ;; and the old entry (if any) has to be deleted | |
4811 ;; ;; before adding the new entry. | |
4812 ;; (dired-remove-file to)) | |
4813 ;; (setq success-count (1+ success-count)) | |
4814 ;; (message "%s: %d of %d" operation success-count total) | |
4815 ;; (dired-add-file to actual-marker-char)) | |
30459 | 4816 |
28210 | 4817 ;; (ange-ftp-dcf-1 file-creator operation (cdr fn-list) |
4818 ;; name-constructor | |
4819 ;; target | |
4820 ;; marker-char | |
4821 ;; buffer | |
30459 | 4822 ;; overwrite-query |
28210 | 4823 ;; overwrite-backup-query |
4824 ;; failures skipped success-count | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4825 ;; total))) |
28210 | 4826 |
4827 ;;(defun ange-ftp-dcf-3 (failures operation total skipped success-count | |
4828 ;; buffer) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4829 ;; (with-current-buffer buffer |
28210 | 4830 ;; (cond |
4831 ;; (failures | |
4832 ;; (dired-log-summary | |
4833 ;; (message "%s failed for %d of %d file%s %s" | |
4834 ;; operation (length failures) total | |
4835 ;; (dired-plural-s total) failures))) | |
4836 ;; (skipped | |
4837 ;; (dired-log-summary | |
4838 ;; (message "%s: %d of %d file%s skipped %s" | |
4839 ;; operation (length skipped) total | |
4840 ;; (dired-plural-s total) skipped))) | |
4841 ;; (t | |
4842 ;; (message "%s: %s file%s." | |
4843 ;; operation success-count (dired-plural-s success-count)))) | |
65810
0534e10b621e
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
65791
diff
changeset
|
4844 ;; (dired-move-to-filename))) |
28210 | 4845 |
4846 ;;;; ----------------------------------------------- | |
4847 ;;;; Unix Descriptive Listing (dl) Support | |
4848 ;;;; ----------------------------------------------- | |
4849 | |
4850 ;; This is turned off because nothing uses it currently | |
4851 ;; and because I don't understand what it's supposed to be for. --rms. | |
4852 | |
4853 ;;(defconst ange-ftp-dired-dl-re-dir | |
4854 ;; "^. [^ /]+/[ \n]" | |
4855 ;; "Regular expression to use to search for dl directories.") | |
4856 | |
4857 ;;(or (assq 'unix:dl ange-ftp-dired-re-dir-alist) | |
4858 ;; (setq ange-ftp-dired-re-dir-alist | |
4859 ;; (cons (cons 'unix:dl ange-ftp-dired-dl-re-dir) | |
4860 ;; ange-ftp-dired-re-dir-alist))) | |
4861 | |
4862 ;;(defun ange-ftp-dired-dl-move-to-filename (&optional raise-error eol) | |
4863 ;; "In dired, move to the first character of the filename on this line." | |
4864 ;; ;; This is the Unix dl version. | |
4865 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
4866 ;; (let (case-fold-search) | |
4867 ;; (beginning-of-line) | |
4868 ;; (if (looking-at ". [^ ]+ +\\([0-9]+\\|-\\|=\\) ") | |
4869 ;; (goto-char (+ (point) 2)) | |
4870 ;; (if raise-error | |
4871 ;; (error "No file on this line") | |
4872 ;; nil)))) | |
4873 | |
4874 ;;(or (assq 'unix:dl ange-ftp-dired-move-to-filename-alist) | |
4875 ;; (setq ange-ftp-dired-move-to-filename-alist | |
4876 ;; (cons '(unix:dl . ange-ftp-dired-dl-move-to-filename) | |
4877 ;; ange-ftp-dired-move-to-filename-alist))) | |
4878 | |
4879 ;;(defun ange-ftp-dired-dl-move-to-end-of-filename (&optional no-error eol) | |
4880 ;; ;; Assumes point is at beginning of filename. | |
4881 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
4882 ;; ;; On failure, signals an error or returns nil. | |
4883 ;; ;; This is the Unix dl version. | |
4884 ;; (let ((opoint (point)) | |
4885 ;; case-fold-search hidden) | |
4886 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
4887 ;; (setq hidden (and selective-display | |
4888 ;; (save-excursion | |
4889 ;; (search-forward "\r" eol t)))) | |
4890 ;; (if hidden | |
4891 ;; (if no-error | |
4892 ;; nil | |
4893 ;; (error | |
4894 ;; (substitute-command-keys | |
4895 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide"))) | |
4896 ;; (skip-chars-forward "^ /" eol) | |
4897 ;; (if (eq opoint (point)) | |
4898 ;; (if no-error | |
4899 ;; nil | |
4900 ;; (error "No file on this line")) | |
4901 ;; (point))))) | |
4902 | |
4903 ;;(or (assq 'unix:dl ange-ftp-dired-move-to-end-of-filename-alist) | |
4904 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
4905 ;; (cons '(unix:dl . ange-ftp-dired-dl-move-to-end-of-filename) | |
4906 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
4907 | |
4908 ;;;; ------------------------------------------------------------ | |
4909 ;;;; VOS support (VOS support is probably broken, | |
4910 ;;;; but I don't know anything about VOS.) | |
4911 ;;;; ------------------------------------------------------------ | |
4912 ; | |
4913 ;(defun ange-ftp-fix-name-for-vos (name &optional reverse) | |
4914 ; (setq name (copy-sequence name)) | |
4915 ; (let ((from (if reverse ?\> ?\/)) | |
4916 ; (to (if reverse ?\/ ?\>)) | |
4917 ; (i (1- (length name)))) | |
4918 ; (while (>= i 0) | |
4919 ; (if (= (aref name i) from) | |
4920 ; (aset name i to)) | |
4921 ; (setq i (1- i))) | |
4922 ; name)) | |
4923 ; | |
4924 ;(or (assq 'vos ange-ftp-fix-name-func-alist) | |
4925 ; (setq ange-ftp-fix-name-func-alist | |
4926 ; (cons '(vos . ange-ftp-fix-name-for-vos) | |
4927 ; ange-ftp-fix-name-func-alist))) | |
4928 ; | |
4929 ;(or (memq 'vos ange-ftp-dumb-host-types) | |
4930 ; (setq ange-ftp-dumb-host-types | |
4931 ; (cons 'vos ange-ftp-dumb-host-types))) | |
4932 ; | |
4933 ;(defun ange-ftp-fix-dir-name-for-vos (dir-name) | |
4934 ; (ange-ftp-fix-name-for-vos | |
4935 ; (concat dir-name | |
4936 ; (if (eq ?/ (aref dir-name (1- (length dir-name)))) | |
4937 ; "" "/") | |
4938 ; "*"))) | |
4939 ; | |
4940 ;(or (assq 'vos ange-ftp-fix-dir-name-func-alist) | |
4941 ; (setq ange-ftp-fix-dir-name-func-alist | |
4942 ; (cons '(vos . ange-ftp-fix-dir-name-for-vos) | |
4943 ; ange-ftp-fix-dir-name-func-alist))) | |
4944 ; | |
4945 ;(defvar ange-ftp-vos-host-regexp nil | |
4946 ; "If a host matches this regexp then it is assumed to be running VOS.") | |
4947 ; | |
4948 ;(defun ange-ftp-vos-host (host) | |
4949 ; (and ange-ftp-vos-host-regexp | |
4950 ; (save-match-data | |
4951 ; (string-match ange-ftp-vos-host-regexp host)))) | |
4952 ; | |
4953 ;(defun ange-ftp-parse-vos-listing () | |
4954 ; "Parse the current buffer which is assumed to be in VOS list -all | |
4955 ;format, and return a hashtable as the result." | |
4956 ; (let ((tbl (ange-ftp-make-hashtable)) | |
4957 ; (type-list | |
4958 ; '(("^Files: [0-9]+ +Blocks: [0-9]+\n+" nil 40) | |
4959 ; ("^Dirs: [0-9]+\n+" t 30))) | |
4960 ; type-regexp type-is-dir type-col file) | |
4961 ; (goto-char (point-min)) | |
4962 ; (save-match-data | |
4963 ; (while type-list | |
4964 ; (setq type-regexp (car (car type-list)) | |
4965 ; type-is-dir (nth 1 (car type-list)) | |
4966 ; type-col (nth 2 (car type-list)) | |
4967 ; type-list (cdr type-list)) | |
4968 ; (if (re-search-forward type-regexp nil t) | |
4969 ; (while (eq (char-after (point)) ? ) | |
4970 ; (move-to-column type-col) | |
4971 ; (setq file (buffer-substring (point) | |
4972 ; (progn | |
4973 ; (end-of-line 1) | |
4974 ; (point)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4975 ; (puthash file type-is-dir tbl) |
28210 | 4976 ; (forward-line 1)))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4977 ; (puthash "." 'vosdir tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
4978 ; (puthash ".." 'vosdir tbl)) |
28210 | 4979 ; tbl)) |
4980 ; | |
4981 ;(or (assq 'vos ange-ftp-parse-list-func-alist) | |
4982 ; (setq ange-ftp-parse-list-func-alist | |
4983 ; (cons '(vos . ange-ftp-parse-vos-listing) | |
4984 ; ange-ftp-parse-list-func-alist))) | |
4985 | |
4986 ;;;; ------------------------------------------------------------ | |
4987 ;;;; VMS support. | |
4988 ;;;; ------------------------------------------------------------ | |
4989 | |
4990 ;; Convert NAME from UNIX-ish to VMS. If REVERSE given then convert from VMS | |
4991 ;; to UNIX-ish. | |
4992 (defun ange-ftp-fix-name-for-vms (name &optional reverse) | |
4993 (save-match-data | |
4994 (if reverse | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
4995 (if (string-match "\\`\\([^:]+:\\)?\\(\\[.*\\]\\)?\\([^][]*\\)\\'" name) |
28210 | 4996 (let (drive dir file) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4997 (setq drive (match-string 1 name)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4998 (setq dir (match-string 2 name)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
4999 (setq file (match-string 3 name)) |
28210 | 5000 (and dir |
30481 | 5001 (setq dir (subst-char-in-string |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
5002 ?/ ?. (substring dir 1 -1) t))) |
28210 | 5003 (concat (and drive |
5004 (concat "/" drive "/")) | |
5005 dir (and dir "/") | |
5006 file)) | |
5007 (error "name %s didn't match" name)) | |
5008 (let (drive dir file tmp) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5009 (if (string-match "\\`/[^:]+:/" name) |
28210 | 5010 (setq drive (substring name 1 |
5011 (1- (match-end 0))) | |
5012 name (substring name (match-end 0)))) | |
5013 (setq tmp (file-name-directory name)) | |
5014 (if tmp | |
37813
989feabdf50e
(ange-ftp-fix-name-for-vms): Reverse args of
Gerd Moellmann <gerd@gnu.org>
parents:
37774
diff
changeset
|
5015 (setq dir (subst-char-in-string ?/ ?. (substring tmp 0 -1) t))) |
28210 | 5016 (setq file (file-name-nondirectory name)) |
5017 (concat drive | |
5018 (and dir (concat "[" (if drive nil ".") dir "]")) | |
5019 file))))) | |
5020 | |
5021 ;; (ange-ftp-fix-name-for-vms "/PUB$:/ANONYMOUS/SDSCPUB/NEXT/Readme.txt;1") | |
5022 ;; (ange-ftp-fix-name-for-vms "/PUB$:[ANONYMOUS.SDSCPUB.NEXT]Readme.txt;1" t) | |
5023 | |
5024 (or (assq 'vms ange-ftp-fix-name-func-alist) | |
5025 (setq ange-ftp-fix-name-func-alist | |
5026 (cons '(vms . ange-ftp-fix-name-for-vms) | |
5027 ange-ftp-fix-name-func-alist))) | |
5028 | |
5029 (or (memq 'vms ange-ftp-dumb-host-types) | |
5030 (setq ange-ftp-dumb-host-types | |
5031 (cons 'vms ange-ftp-dumb-host-types))) | |
5032 | |
5033 ;; It is important that this function barf for directories for which we know | |
5034 ;; that we cannot possibly get a directory listing, such as "/" and "/DEV:/". | |
5035 ;; This is because it saves an unnecessary FTP error, or possibly the listing | |
5036 ;; might succeed, but give erroneous info. This last case is particularly | |
5037 ;; likely for OS's (like MTS) for which we need to use a wildcard in order | |
5038 ;; to list a directory. | |
5039 | |
5040 ;; Convert name from UNIX-ish to VMS ready for a DIRectory listing. | |
5041 (defun ange-ftp-fix-dir-name-for-vms (dir-name) | |
5042 ;; Should there be entries for .. -> [-] and . -> [] below. Don't | |
5043 ;; think so, because expand-filename should have already short-circuited | |
5044 ;; them. | |
5045 (cond ((string-equal dir-name "/") | |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38328
diff
changeset
|
5046 (error "Cannot get listing for fictitious \"/\" directory")) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5047 ((string-match "\\`/[-A-Z0-9_$]+:/\\'" dir-name) |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38328
diff
changeset
|
5048 (error "Cannot get listing for device")) |
28210 | 5049 ((ange-ftp-fix-name-for-vms dir-name)))) |
30459 | 5050 |
28210 | 5051 (or (assq 'vms ange-ftp-fix-dir-name-func-alist) |
5052 (setq ange-ftp-fix-dir-name-func-alist | |
5053 (cons '(vms . ange-ftp-fix-dir-name-for-vms) | |
5054 ange-ftp-fix-dir-name-func-alist))) | |
5055 | |
5056 (defvar ange-ftp-vms-host-regexp nil) | |
5057 | |
5058 ;; Return non-nil if HOST is running VMS. | |
5059 (defun ange-ftp-vms-host (host) | |
5060 (and ange-ftp-vms-host-regexp | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
5061 (string-match-p ange-ftp-vms-host-regexp host))) |
28210 | 5062 |
5063 ;; Because some VMS ftp servers convert filenames to lower case | |
5064 ;; we allow a-z in the filename regexp. I'm not too happy about this. | |
5065 | |
5066 (defconst ange-ftp-vms-filename-regexp | |
5067 (concat | |
5068 "\\(\\([_A-Za-z0-9$]?\\|[_A-Za-z0-9$][-_A-Za-z0-9$]*\\)\\." | |
5069 "[-_A-Za-z0-9$]*;+[0-9]*\\)") | |
5070 "Regular expression to match for a valid VMS file name in Dired buffer. | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
5071 Stupid freaking bug! Position of _ and $ shouldn't matter but they do. |
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
5072 Having [A-Z0-9$_] bombs on filename _$$CHANGE_LOG$.TXT$ and $CHANGE_LOG$.TX. |
28210 | 5073 Other orders of $ and _ seem to all work just fine.") |
5074 | |
5075 ;; These parsing functions are as general as possible because the syntax | |
5076 ;; of ftp listings from VMS hosts is a bit erratic. What saves us is that | |
5077 ;; the VMS filename syntax is so rigid. If they bomb on a listing in the | |
5078 ;; standard VMS Multinet format, then this is a bug. If they bomb on a listing | |
5079 ;; from vms.weird.net, then too bad. | |
5080 | |
5081 ;; Extract the next filename from a VMS dired-like listing. | |
5082 (defun ange-ftp-parse-vms-filename () | |
5083 (if (re-search-forward | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5084 ange-ftp-vms-filename-regexp |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5085 nil t) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5086 (match-string 0))) |
28210 | 5087 |
5088 ;; Parse the current buffer which is assumed to be in MultiNet FTP dir | |
5089 ;; format, and return a hashtable as the result. | |
5090 (defun ange-ftp-parse-vms-listing () | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5091 (let ((tbl (make-hash-table :test 'equal)) |
28210 | 5092 file) |
5093 (goto-char (point-min)) | |
5094 (save-match-data | |
5095 (while (setq file (ange-ftp-parse-vms-filename)) | |
5096 (if (string-match "\\.\\(DIR\\|dir\\);[0-9]+" file) | |
5097 ;; deal with directories | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5098 (puthash (substring file 0 (match-beginning 0)) t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5099 (puthash file nil tbl) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5100 (if (string-match ";[0-9]+\\'" file) ; deal with extension |
28210 | 5101 ;; sans extension |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5102 (puthash (substring file 0 (match-beginning 0)) nil tbl))) |
28210 | 5103 (forward-line 1)) |
5104 ;; Would like to look for a "Total" line, or a "Directory" line to | |
5105 ;; make sure that the listing isn't complete garbage before putting | |
5106 ;; in "." and "..", but we can't even count on all VAX's giving us | |
5107 ;; either of these. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5108 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5109 (puthash ".." t tbl)) |
28210 | 5110 tbl)) |
5111 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5112 (add-to-list 'ange-ftp-parse-list-func-alist |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5113 '(vms . ange-ftp-parse-vms-listing)) |
28210 | 5114 |
5115 ;; This version only deletes file entries which have | |
5116 ;; explicit version numbers, because that is all VMS allows. | |
5117 | |
5118 ;; Can the following two functions be speeded up using file | |
5119 ;; completion functions? | |
5120 | |
5121 (defun ange-ftp-vms-delete-file-entry (name &optional dir-p) | |
5122 (if dir-p | |
5123 (ange-ftp-internal-delete-file-entry name t) | |
5124 (save-match-data | |
5125 (let ((file (ange-ftp-get-file-part name))) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5126 (if (string-match ";[0-9]+\\'" file) |
30459 | 5127 ;; In VMS you can't delete a file without an explicit |
28210 | 5128 ;; version number, or wild-card (e.g. FOO;*) |
5129 ;; For now, we give up on wildcards. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5130 (let ((files (gethash (file-name-directory name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5131 ange-ftp-files-hashtable))) |
28210 | 5132 (if files |
5133 (let* ((root (substring file 0 | |
5134 (match-beginning 0))) | |
5135 (regexp (concat "^" | |
5136 (regexp-quote root) | |
5137 ";[0-9]+$")) | |
5138 versions) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5139 (remhash file files) |
28210 | 5140 ;; Now we need to check if there are any |
5141 ;; versions left. If not, then delete the | |
5142 ;; root entry. | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5143 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5144 (lambda (key val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5145 (and (string-match regexp key) |
29587
bcdfb27c5ea4
(ange-ftp-vms-delete-file-entry)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28892
diff
changeset
|
5146 (setq versions t))) |
28210 | 5147 files) |
5148 (or versions | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5149 (remhash root files)))))))))) |
28210 | 5150 |
5151 (or (assq 'vms ange-ftp-delete-file-entry-alist) | |
5152 (setq ange-ftp-delete-file-entry-alist | |
5153 (cons '(vms . ange-ftp-vms-delete-file-entry) | |
5154 ange-ftp-delete-file-entry-alist))) | |
5155 | |
5156 (defun ange-ftp-vms-add-file-entry (name &optional dir-p) | |
5157 (if dir-p | |
5158 (ange-ftp-internal-add-file-entry name t) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5159 (let ((files (gethash (file-name-directory name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5160 ange-ftp-files-hashtable))) |
28210 | 5161 (if files |
5162 (let ((file (ange-ftp-get-file-part name))) | |
5163 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5164 (if (string-match ";[0-9]+\\'" file) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5165 (puthash (substring file 0 (match-beginning 0)) nil files) |
28210 | 5166 ;; Need to figure out what version of the file |
5167 ;; is being added. | |
5168 (let ((regexp (concat "^" | |
5169 (regexp-quote file) | |
5170 ";\\([0-9]+\\)$")) | |
5171 (version 0)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5172 (maphash |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5173 (lambda (name val) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5174 (and (string-match regexp name) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5175 (setq version |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5176 (max version |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
59996
diff
changeset
|
5177 (string-to-number (match-string 1 name)))))) |
28210 | 5178 files) |
5179 (setq version (1+ version)) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5180 (puthash |
28210 | 5181 (concat file ";" (int-to-string version)) |
5182 nil files)))) | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5183 (puthash file nil files)))))) |
28210 | 5184 |
5185 (or (assq 'vms ange-ftp-add-file-entry-alist) | |
5186 (setq ange-ftp-add-file-entry-alist | |
5187 (cons '(vms . ange-ftp-vms-add-file-entry) | |
5188 ange-ftp-add-file-entry-alist))) | |
5189 | |
5190 | |
5191 (defun ange-ftp-add-vms-host (host) | |
5192 "Mark HOST as the name of a machine running VMS." | |
5193 (interactive | |
5194 (list (read-string "Host: " | |
5195 (let ((name (or (buffer-file-name) default-directory))) | |
5196 (and name (car (ange-ftp-ftp-name name))))))) | |
5197 (if (not (ange-ftp-vms-host host)) | |
5198 (setq ange-ftp-vms-host-regexp | |
5199 (concat "^" (regexp-quote host) "$" | |
5200 (and ange-ftp-vms-host-regexp "\\|") | |
5201 ange-ftp-vms-host-regexp) | |
5202 ange-ftp-host-cache nil))) | |
5203 | |
5204 | |
5205 (defun ange-ftp-vms-file-name-as-directory (name) | |
5206 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5207 (if (string-match "\\.\\(DIR\\|dir\\)\\(;[0-9]+\\)?\\'" name) |
28210 | 5208 (setq name (substring name 0 (match-beginning 0)))) |
5209 (ange-ftp-real-file-name-as-directory name))) | |
5210 | |
5211 (or (assq 'vms ange-ftp-file-name-as-directory-alist) | |
5212 (setq ange-ftp-file-name-as-directory-alist | |
5213 (cons '(vms . ange-ftp-vms-file-name-as-directory) | |
5214 ange-ftp-file-name-as-directory-alist))) | |
5215 | |
5216 ;;; Tree dired support: | |
5217 | |
5218 ;; For this code I have borrowed liberally from Sebastian Kremer's | |
5219 ;; dired-vms.el | |
5220 | |
5221 | |
5222 ;;;; These regexps must be anchored to beginning of line. | |
5223 ;;;; Beware that the ftpd may put the device in front of the filename. | |
5224 | |
5225 ;;(defconst ange-ftp-dired-vms-re-exe "^. [^ \t.]+\\.\\(EXE\\|exe\\)[; ]" | |
5226 ;; "Regular expression to use to search for VMS executable files.") | |
5227 | |
5228 ;;(defconst ange-ftp-dired-vms-re-dir "^. [^ \t.]+\\.\\(DIR\\|dir\\)[; ]" | |
5229 ;; "Regular expression to use to search for VMS directories.") | |
5230 | |
5231 ;;(or (assq 'vms ange-ftp-dired-re-exe-alist) | |
5232 ;; (setq ange-ftp-dired-re-exe-alist | |
5233 ;; (cons (cons 'vms ange-ftp-dired-vms-re-exe) | |
5234 ;; ange-ftp-dired-re-exe-alist))) | |
5235 | |
5236 ;;(or (assq 'vms ange-ftp-dired-re-dir-alist) | |
5237 ;; (setq ange-ftp-dired-re-dir-alist | |
5238 ;; (cons (cons 'vms ange-ftp-dired-vms-re-dir) | |
5239 ;; ange-ftp-dired-re-dir-alist))) | |
5240 | |
5241 ;;(defun ange-ftp-dired-vms-insert-headerline (dir) | |
5242 ;; ;; VMS inserts a headerline. I would prefer the headerline | |
5243 ;; ;; to be in ange-ftp format. This version tries to | |
5244 ;; ;; be careful, because we can't count on a headerline | |
5245 ;; ;; over ftp, and we wouldn't want to delete anything | |
5246 ;; ;; important. | |
5247 ;; (save-excursion | |
5248 ;; (if (looking-at "^ wildcard ") | |
5249 ;; (forward-line 1)) | |
5250 ;; (if (looking-at "^[ \n\t]*[^\n]+\\][ \t]*\n") | |
5251 ;; (delete-region (point) (match-end 0)))) | |
5252 ;; (ange-ftp-real-dired-insert-headerline dir)) | |
5253 | |
5254 ;;(or (assq 'vms ange-ftp-dired-insert-headerline-alist) | |
5255 ;; (setq ange-ftp-dired-insert-headerline-alist | |
5256 ;; (cons '(vms . ange-ftp-dired-vms-insert-headerline) | |
5257 ;; ange-ftp-dired-insert-headerline-alist))) | |
5258 | |
5259 ;;(defun ange-ftp-dired-vms-move-to-filename (&optional raise-error eol) | |
5260 ;; "In dired, move to first char of filename on this line. | |
5261 ;;Returns position (point) or nil if no filename on this line." | |
5262 ;; ;; This is the VMS version. | |
5263 ;; (let (case-fold-search) | |
5264 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5265 ;; (beginning-of-line) | |
5266 ;; (if (re-search-forward ange-ftp-vms-filename-regexp eol t) | |
5267 ;; (goto-char (match-beginning 1)) | |
5268 ;; (if raise-error | |
5269 ;; (error "No file on this line") | |
5270 ;; nil)))) | |
5271 | |
5272 ;;(or (assq 'vms ange-ftp-dired-move-to-filename-alist) | |
5273 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5274 ;; (cons '(vms . ange-ftp-dired-vms-move-to-filename) | |
5275 ;; ange-ftp-dired-move-to-filename-alist))) | |
5276 | |
5277 ;;(defun ange-ftp-dired-vms-move-to-end-of-filename (&optional no-error eol) | |
5278 ;; ;; Assumes point is at beginning of filename. | |
5279 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5280 ;; ;; case-fold-search must be nil, at least for VMS. | |
5281 ;; ;; On failure, signals an error or returns nil. | |
5282 ;; ;; This is the VMS version. | |
5283 ;; (let (opoint hidden case-fold-search) | |
5284 ;; (setq opoint (point)) | |
5285 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
5286 ;; (setq hidden (and selective-display | |
5287 ;; (save-excursion (search-forward "\r" eol t)))) | |
5288 ;; (if hidden | |
5289 ;; nil | |
5290 ;; (re-search-forward ange-ftp-vms-filename-regexp eol t)) | |
5291 ;; (or no-error | |
5292 ;; (not (eq opoint (point))) | |
5293 ;; (error | |
5294 ;; (if hidden | |
5295 ;; (substitute-command-keys | |
5296 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide") | |
5297 ;; "No file on this line"))) | |
5298 ;; (if (eq opoint (point)) | |
5299 ;; nil | |
5300 ;; (point)))) | |
5301 | |
5302 ;;(or (assq 'vms ange-ftp-dired-move-to-end-of-filename-alist) | |
5303 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5304 ;; (cons '(vms . ange-ftp-dired-vms-move-to-end-of-filename) | |
5305 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5306 | |
5307 ;;(defun ange-ftp-dired-vms-between-files () | |
5308 ;; (save-excursion | |
5309 ;; (beginning-of-line) | |
5310 ;; (or (equal (following-char) 10) ; newline | |
5311 ;; (equal (following-char) 9) ; tab | |
5312 ;; (progn (forward-char 2) | |
5313 ;; (or (looking-at "Total of") | |
5314 ;; (equal (following-char) 32)))))) | |
5315 | |
5316 ;;(or (assq 'vms ange-ftp-dired-between-files-alist) | |
5317 ;; (setq ange-ftp-dired-between-files-alist | |
5318 ;; (cons '(vms . ange-ftp-dired-vms-between-files) | |
5319 ;; ange-ftp-dired-between-files-alist))) | |
5320 | |
5321 ;; Beware! In VMS filenames must be of the form "FILE.TYPE". | |
5322 ;; Therefore, we cannot just append a ".Z" to filenames for | |
5323 ;; compressed files. Instead, we turn "FILE.TYPE" into | |
5324 ;; "FILE.TYPE-Z". Hope that this is a reasonable thing to do. | |
5325 | |
5326 (defun ange-ftp-vms-make-compressed-filename (name &optional reverse) | |
5327 (cond | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5328 ((string-match "-Z;[0-9]+\\'" name) |
28210 | 5329 (list nil (substring name 0 (match-beginning 0)))) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5330 ((string-match ";[0-9]+\\'" name) |
28210 | 5331 (list nil (substring name 0 (match-beginning 0)))) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5332 ((string-match "-Z\\'" name) |
28210 | 5333 (list nil (substring name 0 -2))) |
5334 (t | |
5335 (list t | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5336 (if (string-match ";[0-9]+\\'" name) |
28210 | 5337 (concat (substring name 0 (match-beginning 0)) |
5338 "-Z") | |
5339 (concat name "-Z")))))) | |
5340 | |
5341 (or (assq 'vms ange-ftp-make-compressed-filename-alist) | |
5342 (setq ange-ftp-make-compressed-filename-alist | |
5343 (cons '(vms . ange-ftp-vms-make-compressed-filename) | |
5344 ange-ftp-make-compressed-filename-alist))) | |
5345 | |
5346 ;;;; When the filename is too long, VMS will use two lines to list a file | |
5347 ;;;; (damn them!) This will confuse dired. To solve this, need to convince | |
5348 ;;;; Sebastian to use a function dired-go-to-end-of-file-line, instead of | |
5349 ;;;; (forward-line 1). This would require a number of changes to dired.el. | |
5350 ;;;; If dired gets confused, revert-buffer will fix it. | |
5351 | |
5352 ;;(defun ange-ftp-dired-vms-ls-trim () | |
5353 ;; (goto-char (point-min)) | |
5354 ;; (let ((case-fold-search nil)) | |
5355 ;; (re-search-forward ange-ftp-vms-filename-regexp)) | |
5356 ;; (beginning-of-line) | |
5357 ;; (delete-region (point-min) (point)) | |
5358 ;; (forward-line 1) | |
5359 ;; (delete-region (point) (point-max))) | |
5360 | |
5361 | |
5362 ;;(or (assq 'vms ange-ftp-dired-ls-trim-alist) | |
5363 ;; (setq ange-ftp-dired-ls-trim-alist | |
5364 ;; (cons '(vms . ange-ftp-dired-vms-ls-trim) | |
30459 | 5365 ;; ange-ftp-dired-ls-trim-alist))) |
28210 | 5366 |
5367 (defun ange-ftp-vms-sans-version (name &rest args) | |
5368 (save-match-data | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5369 (if (string-match ";[0-9]+\\'" name) |
28210 | 5370 (substring name 0 (match-beginning 0)) |
5371 name))) | |
5372 | |
5373 (or (assq 'vms ange-ftp-sans-version-alist) | |
5374 (setq ange-ftp-sans-version-alist | |
5375 (cons '(vms . ange-ftp-vms-sans-version) | |
5376 ange-ftp-sans-version-alist))) | |
5377 | |
5378 ;;(defvar ange-ftp-file-version-alist) | |
5379 | |
5380 ;;;;; The vms version of clean-directory has 2 more optional args | |
5381 ;;;;; than the usual dired version. This is so that it can be used by | |
5382 ;;;;; ange-ftp-dired-vms-flag-backup-files. | |
5383 | |
5384 ;;(defun ange-ftp-dired-vms-clean-directory (keep &optional marker msg) | |
5385 ;; "Flag numerical backups for deletion. | |
5386 ;;Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest. | |
5387 ;;Positive prefix arg KEEP overrides `dired-kept-versions'; | |
5388 ;;Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive. | |
5389 | |
5390 ;;To clear the flags on these files, you can use \\[dired-flag-backup-files] | |
5391 ;;with a prefix argument." | |
5392 ;;; (interactive "P") ; Never actually called interactively. | |
5393 ;; (setq keep (max 1 (if keep (prefix-numeric-value keep) dired-kept-versions))) | |
5394 ;; (let ((early-retention (if (< keep 0) (- keep) kept-old-versions)) | |
5395 ;; ;; late-retention must NEVER be allowed to be less than 1 in VMS! | |
5396 ;; ;; This could wipe ALL copies of the file. | |
5397 ;; (late-retention (max 1 (if (<= keep 0) dired-kept-versions keep))) | |
5398 ;; (action (or msg "Cleaning")) | |
5399 ;; (ange-ftp-trample-marker (or marker dired-del-marker)) | |
5400 ;; (ange-ftp-file-version-alist ())) | |
5401 ;; (message (concat action | |
5402 ;; " numerical backups (keeping %d late, %d old)...") | |
5403 ;; late-retention early-retention) | |
5404 ;; ;; Look at each file. | |
5405 ;; ;; If the file has numeric backup versions, | |
5406 ;; ;; put on ange-ftp-file-version-alist an element of the form | |
5407 ;; ;; (FILENAME . VERSION-NUMBER-LIST) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5408 ;; (dired-map-dired-file-lines 'ange-ftp-dired-vms-collect-file-versions) |
28210 | 5409 ;; ;; Sort each VERSION-NUMBER-LIST, |
5410 ;; ;; and remove the versions not to be deleted. | |
5411 ;; (let ((fval ange-ftp-file-version-alist)) | |
5412 ;; (while fval | |
5413 ;; (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<))) | |
5414 ;; (v-count (length sorted-v-list))) | |
5415 ;; (if (> v-count (+ early-retention late-retention)) | |
5416 ;; (rplacd (nthcdr early-retention sorted-v-list) | |
5417 ;; (nthcdr (- v-count late-retention) | |
5418 ;; sorted-v-list))) | |
5419 ;; (rplacd (car fval) | |
5420 ;; (cdr sorted-v-list))) | |
5421 ;; (setq fval (cdr fval)))) | |
5422 ;; ;; Look at each file. If it is a numeric backup file, | |
5423 ;; ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion. | |
5424 ;; (dired-map-dired-file-lines | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5425 ;; 'ange-ftp-dired-vms-trample-file-versions mark) |
28210 | 5426 ;; (message (concat action " numerical backups...done")))) |
5427 | |
5428 ;;(or (assq 'vms ange-ftp-dired-clean-directory-alist) | |
5429 ;; (setq ange-ftp-dired-clean-directory-alist | |
5430 ;; (cons '(vms . ange-ftp-dired-vms-clean-directory) | |
5431 ;; ange-ftp-dired-clean-directory-alist))) | |
5432 | |
5433 ;;(defun ange-ftp-dired-vms-collect-file-versions (fn) | |
5434 ;; ;; "If it looks like file FN has versions, return a list of the versions. | |
5435 ;; ;;That is a list of strings which are file names. | |
5436 ;; ;;The caller may want to flag some of these files for deletion." | |
5437 ;;(let ((name (nth 2 (ange-ftp-ftp-name fn)))) | |
5438 ;; (if (string-match ";[0-9]+$" name) | |
5439 ;; (let* ((name (substring name 0 (match-beginning 0))) | |
5440 ;; (fn (ange-ftp-replace-name-component fn name))) | |
5441 ;; (if (not (assq fn ange-ftp-file-version-alist)) | |
5442 ;; (let* ((base-versions | |
5443 ;; (concat (file-name-nondirectory name) ";")) | |
5444 ;; (bv-length (length base-versions)) | |
5445 ;; (possibilities (file-name-all-completions | |
5446 ;; base-versions | |
5447 ;; (file-name-directory fn))) | |
5448 ;; (versions (mapcar | |
5449 ;; '(lambda (arg) | |
5450 ;; (if (and (string-match | |
5451 ;; "[0-9]+$" arg bv-length) | |
5452 ;; (= (match-beginning 0) bv-length)) | |
5453 ;; (string-to-int (substring arg bv-length)) | |
5454 ;; 0)) | |
5455 ;; possibilities))) | |
5456 ;; (if versions | |
5457 ;; (setq | |
5458 ;; ange-ftp-file-version-alist | |
5459 ;; (cons (cons fn versions) | |
5460 ;; ange-ftp-file-version-alist))))))))) | |
5461 | |
5462 ;;(defun ange-ftp-dired-vms-trample-file-versions (fn) | |
5463 ;; (let* ((start-vn (string-match ";[0-9]+$" fn)) | |
5464 ;; base-version-list) | |
5465 ;; (and start-vn | |
5466 ;; (setq base-version-list ; there was a base version to which | |
5467 ;; (assoc (substring fn 0 start-vn) ; this looks like a | |
5468 ;; ange-ftp-file-version-alist)) ; subversion | |
5469 ;; (not (memq (string-to-int (substring fn (1+ start-vn))) | |
5470 ;; base-version-list)) ; this one doesn't make the cut | |
5471 ;; (progn (beginning-of-line) | |
5472 ;; (delete-char 1) | |
5473 ;; (insert ange-ftp-trample-marker))))) | |
5474 | |
5475 ;;(defun ange-ftp-dired-vms-flag-backup-files (&optional unflag-p) | |
5476 ;; (let ((dired-kept-versions 1) | |
5477 ;; (kept-old-versions 0) | |
5478 ;; marker msg) | |
5479 ;; (if unflag-p | |
5480 ;; (setq marker ?\040 msg "Unflagging") | |
5481 ;; (setq marker dired-del-marker msg "Cleaning")) | |
5482 ;; (ange-ftp-dired-vms-clean-directory nil marker msg))) | |
5483 | |
5484 ;;(or (assq 'vms ange-ftp-dired-flag-backup-files-alist) | |
5485 ;; (setq ange-ftp-dired-flag-backup-files-alist | |
5486 ;; (cons '(vms . ange-ftp-dired-vms-flag-backup-files) | |
5487 ;; ange-ftp-dired-flag-backup-files-alist))) | |
5488 | |
5489 ;;(defun ange-ftp-dired-vms-backup-diff (&optional switches) | |
5490 ;; (let ((file (dired-get-filename 'no-dir)) | |
5491 ;; bak) | |
5492 ;; (if (and (string-match ";[0-9]+$" file) | |
5493 ;; ;; Find most recent previous version. | |
5494 ;; (let ((root (substring file 0 (match-beginning 0))) | |
5495 ;; (ver | |
5496 ;; (string-to-int (substring file (1+ (match-beginning 0))))) | |
5497 ;; found) | |
5498 ;; (setq ver (1- ver)) | |
5499 ;; (while (and (> ver 0) (not found)) | |
5500 ;; (setq bak (concat root ";" (int-to-string ver))) | |
5501 ;; (and (file-exists-p bak) (setq found t)) | |
5502 ;; (setq ver (1- ver))) | |
5503 ;; found)) | |
5504 ;; (if switches | |
5505 ;; (diff (expand-file-name bak) (expand-file-name file) switches) | |
5506 ;; (diff (expand-file-name bak) (expand-file-name file))) | |
5507 ;; (error "No previous version found for %s" file)))) | |
5508 | |
5509 ;;(or (assq 'vms ange-ftp-dired-backup-diff-alist) | |
5510 ;; (setq ange-ftp-dired-backup-diff-alist | |
5511 ;; (cons '(vms . ange-ftp-dired-vms-backup-diff) | |
5512 ;; ange-ftp-dired-backup-diff-alist))) | |
5513 | |
5514 | |
5515 ;;;; ------------------------------------------------------------ | |
5516 ;;;; MTS support | |
5517 ;;;; ------------------------------------------------------------ | |
5518 | |
5519 | |
5520 ;; Convert NAME from UNIX-ish to MTS. If REVERSE given then convert from | |
5521 ;; MTS to UNIX-ish. | |
5522 (defun ange-ftp-fix-name-for-mts (name &optional reverse) | |
5523 (save-match-data | |
5524 (if reverse | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5525 (if (string-match "\\`\\([^:]+:\\)?\\(.*\\)\\'" name) |
28210 | 5526 (let (acct file) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5527 (setq acct (match-string 1 name)) |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5528 (setq file (match-string 2 name)) |
28210 | 5529 (concat (and acct (concat "/" acct "/")) |
5530 file)) | |
5531 (error "name %s didn't match" name)) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5532 (if (string-match "\\`/\\([^:]+:\\)/\\(.*\\)\\'" name) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5533 (concat (match-string 1 name) (match-string 2 name)) |
28210 | 5534 ;; Let's hope that mts will recognize it anyway. |
5535 name)))) | |
5536 | |
5537 (or (assq 'mts ange-ftp-fix-name-func-alist) | |
5538 (setq ange-ftp-fix-name-func-alist | |
5539 (cons '(mts . ange-ftp-fix-name-for-mts) | |
5540 ange-ftp-fix-name-func-alist))) | |
5541 | |
5542 ;; Convert name from UNIX-ish to MTS ready for a DIRectory listing. | |
5543 ;; Remember that there are no directories in MTS. | |
5544 (defun ange-ftp-fix-dir-name-for-mts (dir-name) | |
5545 (if (string-equal dir-name "/") | |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38328
diff
changeset
|
5546 (error "Cannot get listing for fictitious \"/\" directory") |
28210 | 5547 (let ((dir-name (ange-ftp-fix-name-for-mts dir-name))) |
5548 (cond | |
5549 ((string-equal dir-name "") | |
5550 "?") | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5551 ((string-match ":\\'" dir-name) |
28210 | 5552 (concat dir-name "?")) |
5553 (dir-name))))) ; It's just a single file. | |
5554 | |
5555 (or (assq 'mts ange-ftp-fix-dir-name-func-alist) | |
5556 (setq ange-ftp-fix-dir-name-func-alist | |
5557 (cons '(mts . ange-ftp-fix-dir-name-for-mts) | |
5558 ange-ftp-fix-dir-name-func-alist))) | |
5559 | |
5560 (or (memq 'mts ange-ftp-dumb-host-types) | |
5561 (setq ange-ftp-dumb-host-types | |
5562 (cons 'mts ange-ftp-dumb-host-types))) | |
5563 | |
5564 (defvar ange-ftp-mts-host-regexp nil) | |
5565 | |
5566 ;; Return non-nil if HOST is running MTS. | |
5567 (defun ange-ftp-mts-host (host) | |
5568 (and ange-ftp-mts-host-regexp | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
5569 (string-match-p ange-ftp-mts-host-regexp host))) |
28210 | 5570 |
5571 ;; Parse the current buffer which is assumed to be in mts ftp dir format. | |
5572 (defun ange-ftp-parse-mts-listing () | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5573 (let ((tbl (make-hash-table :test 'equal))) |
28210 | 5574 (goto-char (point-min)) |
5575 (save-match-data | |
66325
fda96ff4c7e5
* files.el (directory-listing-before-filename-regexp): New
Michael Albinus <michael.albinus@gmx.de>
parents:
66256
diff
changeset
|
5576 (while (re-search-forward directory-listing-before-filename-regexp nil t) |
28210 | 5577 (end-of-line) |
5578 (skip-chars-backward " ") | |
5579 (let ((end (point))) | |
5580 (skip-chars-backward "-A-Z0-9_.!") | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5581 (puthash (buffer-substring (point) end) nil tbl)) |
28210 | 5582 (forward-line 1))) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5583 ;; Don't need to bother with .. |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5584 (puthash "." t tbl) |
28210 | 5585 tbl)) |
5586 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5587 (add-to-list 'ange-ftp-parse-list-func-alist |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5588 '(mts . ange-ftp-parse-mts-listing)) |
28210 | 5589 |
5590 (defun ange-ftp-add-mts-host (host) | |
5591 "Mark HOST as the name of a machine running MTS." | |
5592 (interactive | |
5593 (list (read-string "Host: " | |
5594 (let ((name (or (buffer-file-name) default-directory))) | |
5595 (and name (car (ange-ftp-ftp-name name))))))) | |
5596 (if (not (ange-ftp-mts-host host)) | |
5597 (setq ange-ftp-mts-host-regexp | |
5598 (concat "^" (regexp-quote host) "$" | |
5599 (and ange-ftp-mts-host-regexp "\\|") | |
5600 ange-ftp-mts-host-regexp) | |
5601 ange-ftp-host-cache nil))) | |
5602 | |
5603 ;;; Tree dired support: | |
5604 | |
5605 ;;;; There aren't too many systems left that use MTS. This dired support will | |
5606 ;;;; work for the implementation of ftp on mtsg.ubc.ca. I hope other mts systems | |
5607 ;;;; implement ftp in the same way. If not, it might be necessary to make the | |
5608 ;;;; following more flexible. | |
5609 | |
5610 ;;(defun ange-ftp-dired-mts-move-to-filename (&optional raise-error eol) | |
5611 ;; "In dired, move to first char of filename on this line. | |
5612 ;;Returns position (point) or nil if no filename on this line." | |
5613 ;; ;; This is the MTS version. | |
5614 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5615 ;; (beginning-of-line) | |
5616 ;; (if (re-search-forward | |
5617 ;; ange-ftp-date-regexp eol t) | |
5618 ;; (progn | |
5619 ;; (skip-chars-forward " ") ; Eat blanks after date | |
5620 ;; (skip-chars-forward "0-9:" eol) ; Eat time or year | |
5621 ;; (skip-chars-forward " " eol) ; one space before filename | |
5622 ;; ;; When listing an account other than the users own account it appends | |
5623 ;; ;; ACCT: to the beginning of the filename. Skip over this. | |
5624 ;; (and (looking-at "[A-Z0-9_.]+:") | |
5625 ;; (goto-char (match-end 0))) | |
5626 ;; (point)) | |
5627 ;; (if raise-error | |
5628 ;; (error "No file on this line") | |
5629 ;; nil))) | |
5630 | |
5631 ;;(or (assq 'mts ange-ftp-dired-move-to-filename-alist) | |
5632 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5633 ;; (cons '(mts . ange-ftp-dired-mts-move-to-filename) | |
5634 ;; ange-ftp-dired-move-to-filename-alist))) | |
5635 | |
5636 ;;(defun ange-ftp-dired-mts-move-to-end-of-filename (&optional no-error eol) | |
5637 ;; ;; Assumes point is at beginning of filename. | |
5638 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5639 ;; ;; On failure, signals an error or returns nil. | |
5640 ;; ;; This is the MTS version. | |
5641 ;; (let (opoint hidden case-fold-search) | |
5642 ;; (setq opoint (point) | |
5643 ;; eol (save-excursion (end-of-line) (point)) | |
5644 ;; hidden (and selective-display | |
5645 ;; (save-excursion (search-forward "\r" eol t)))) | |
5646 ;; (if hidden | |
5647 ;; nil | |
5648 ;; (skip-chars-forward "-A-Z0-9._!" eol)) | |
5649 ;; (or no-error | |
5650 ;; (not (eq opoint (point))) | |
5651 ;; (error | |
5652 ;; (if hidden | |
5653 ;; (substitute-command-keys | |
5654 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide") | |
5655 ;; "No file on this line"))) | |
5656 ;; (if (eq opoint (point)) | |
5657 ;; nil | |
5658 ;; (point)))) | |
5659 | |
5660 ;;(or (assq 'mts ange-ftp-dired-move-to-end-of-filename-alist) | |
5661 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5662 ;; (cons '(mts . ange-ftp-dired-mts-move-to-end-of-filename) | |
5663 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5664 | |
5665 ;;;; ------------------------------------------------------------ | |
5666 ;;;; CMS support | |
5667 ;;;; ------------------------------------------------------------ | |
5668 | |
5669 ;; Since CMS doesn't have any full file name syntax, we have to fudge | |
5670 ;; things with cd's. We actually send too many cd's, but it's dangerous | |
5671 ;; to try to remember the current minidisk, because if the connection | |
5672 ;; is closed and needs to be reopened, we will find ourselves back in | |
5673 ;; the default minidisk. This is fairly likely since CMS ftp servers | |
5674 ;; usually close the connection after 5 minutes of inactivity. | |
5675 | |
5676 ;; Have I got the filename character set right? | |
5677 | |
5678 (defun ange-ftp-fix-name-for-cms (name &optional reverse) | |
5679 (save-match-data | |
5680 (if reverse | |
5681 ;; Since we only convert output from a pwd in this direction, | |
5682 ;; we'll assume that it's a minidisk, and make it into a | |
5683 ;; directory file name. Note that the expand-dir-hashtable | |
5684 ;; stores directories without the trailing /. Is this | |
5685 ;; consistent? | |
5686 (concat "/" name) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5687 (if (string-match "\\`/\\([-A-Z0-9$*._]+\\)/\\([-A-Z0-9$._]+\\)?\\'" |
28210 | 5688 name) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5689 (let ((minidisk (match-string 1 name))) |
28210 | 5690 (if (match-beginning 2) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5691 (let ((file (match-string 2 name)) |
28210 | 5692 (cmd (concat "cd " minidisk)) |
5693 | |
5694 ;; Note that host and user are bound in the call | |
5695 ;; to ange-ftp-send-cmd | |
5696 (proc (ange-ftp-get-process ange-ftp-this-host | |
5697 ange-ftp-this-user))) | |
5698 | |
5699 ;; Must use ange-ftp-raw-send-cmd here to avoid | |
5700 ;; an infinite loop. | |
5701 (if (car (ange-ftp-raw-send-cmd proc cmd ange-ftp-this-msg)) | |
5702 file | |
5703 ;; failed... try ONCE more. | |
5704 (setq proc (ange-ftp-get-process ange-ftp-this-host | |
5705 ange-ftp-this-user)) | |
5706 (let ((result (ange-ftp-raw-send-cmd proc cmd | |
5707 ange-ftp-this-msg))) | |
5708 (if (car result) | |
5709 file | |
5710 ;; failed. give up. | |
5711 (ange-ftp-error ange-ftp-this-host ange-ftp-this-user | |
5712 (format "cd to minidisk %s failed: %s" | |
5713 minidisk (cdr result))))))) | |
5714 ;; return the minidisk | |
5715 minidisk)) | |
5716 (error "Invalid CMS filename"))))) | |
5717 | |
5718 (or (assq 'cms ange-ftp-fix-name-func-alist) | |
5719 (setq ange-ftp-fix-name-func-alist | |
5720 (cons '(cms . ange-ftp-fix-name-for-cms) | |
5721 ange-ftp-fix-name-func-alist))) | |
5722 | |
5723 (or (memq 'cms ange-ftp-dumb-host-types) | |
5724 (setq ange-ftp-dumb-host-types | |
5725 (cons 'cms ange-ftp-dumb-host-types))) | |
5726 | |
5727 ;; Convert name from UNIX-ish to CMS ready for a DIRectory listing. | |
5728 (defun ange-ftp-fix-dir-name-for-cms (dir-name) | |
5729 (cond | |
5730 ((string-equal "/" dir-name) | |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38328
diff
changeset
|
5731 (error "Cannot get listing for fictitious \"/\" directory")) |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5732 ((string-match "\\`/\\([-A-Z0-9$*._]+\\)/\\([-A-Z0-9$._]+\\)?\\'" dir-name) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5733 (let* ((minidisk (match-string 1 dir-name)) |
28210 | 5734 ;; host and user are bound in the call to ange-ftp-send-cmd |
5735 (proc (ange-ftp-get-process ange-ftp-this-host ange-ftp-this-user)) | |
5736 (cmd (concat "cd " minidisk)) | |
5737 (file (if (match-beginning 2) | |
5738 ;; it's a single file | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5739 (match-string 2 dir-name) |
28210 | 5740 ;; use the wild-card |
5741 "*"))) | |
5742 (if (car (ange-ftp-raw-send-cmd proc cmd)) | |
5743 file | |
5744 ;; try again... | |
5745 (setq proc (ange-ftp-get-process ange-ftp-this-host | |
5746 ange-ftp-this-user)) | |
5747 (let ((result (ange-ftp-raw-send-cmd proc cmd))) | |
5748 (if (car result) | |
5749 file | |
5750 ;; give up | |
5751 (ange-ftp-error ange-ftp-this-host ange-ftp-this-user | |
5752 (format "cd to minidisk %s failed: %s" | |
5753 minidisk (cdr result)))))))) | |
5754 (t (error "Invalid CMS file name")))) | |
5755 | |
5756 (or (assq 'cms ange-ftp-fix-dir-name-func-alist) | |
5757 (setq ange-ftp-fix-dir-name-func-alist | |
5758 (cons '(cms . ange-ftp-fix-dir-name-for-cms) | |
5759 ange-ftp-fix-dir-name-func-alist))) | |
5760 | |
5761 (defvar ange-ftp-cms-host-regexp nil | |
5762 "Regular expression to match hosts running the CMS operating system.") | |
5763 | |
5764 ;; Return non-nil if HOST is running CMS. | |
5765 (defun ange-ftp-cms-host (host) | |
5766 (and ange-ftp-cms-host-regexp | |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
5767 (string-match-p ange-ftp-cms-host-regexp host))) |
28210 | 5768 |
5769 (defun ange-ftp-add-cms-host (host) | |
5770 "Mark HOST as the name of a CMS host." | |
5771 (interactive | |
5772 (list (read-string "Host: " | |
5773 (let ((name (or (buffer-file-name) default-directory))) | |
5774 (and name (car (ange-ftp-ftp-name name))))))) | |
5775 (if (not (ange-ftp-cms-host host)) | |
5776 (setq ange-ftp-cms-host-regexp | |
5777 (concat "^" (regexp-quote host) "$" | |
5778 (and ange-ftp-cms-host-regexp "\\|") | |
5779 ange-ftp-cms-host-regexp) | |
5780 ange-ftp-host-cache nil))) | |
5781 | |
5782 (defun ange-ftp-parse-cms-listing () | |
5783 ;; Parse the current buffer which is assumed to be a CMS directory listing. | |
5784 ;; If we succeed in getting a listing, then we will assume that the minidisk | |
5785 ;; exists. file is bound by the call to ange-ftp-ls. This doesn't work | |
5786 ;; because ange-ftp doesn't know that the root hashtable has only part of | |
5787 ;; the info. It will assume that if a minidisk isn't in it, then it doesn't | |
5788 ;; exist. It would be nice if completion worked for minidisks, as we | |
5789 ;; discover them. | |
5790 ; (let* ((dir-file (directory-file-name file)) | |
5791 ; (root (file-name-directory dir-file)) | |
5792 ; (minidisk (ange-ftp-get-file-part dir-file)) | |
5793 ; (root-tbl (ange-ftp-get-hash-entry root ange-ftp-files-hashtable))) | |
5794 ; (if root-tbl | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5795 ; (puthash minidisk t root-tbl) |
28210 | 5796 ; (setq root-tbl (ange-ftp-make-hashtable)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5797 ; (puthash minidisk t root-tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5798 ; (puthash "." t root-tbl) |
28210 | 5799 ; (ange-ftp-set-files root root-tbl))) |
5800 ;; Now do the usual parsing | |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5801 (let ((tbl (make-hash-table :test 'equal))) |
28210 | 5802 (goto-char (point-min)) |
5803 (save-match-data | |
5804 (while | |
5805 (re-search-forward | |
5806 "^\\([-A-Z0-9$_]+\\) +\\([-A-Z0-9$_]+\\) +[VF] +[0-9]+ " nil t) | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5807 (puthash (concat (match-string 1) "." (match-string 2)) nil tbl) |
28210 | 5808 (forward-line 1)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
5809 (puthash "." t tbl)) |
28210 | 5810 tbl)) |
5811 | |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5812 (add-to-list 'ange-ftp-parse-list-func-alist |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5813 '(cms . ange-ftp-parse-cms-listing)) |
30459 | 5814 |
28210 | 5815 ;;;;; Tree dired support: |
5816 | |
5817 ;;(defconst ange-ftp-dired-cms-re-exe | |
5818 ;; "^. [-A-Z0-9$_]+ +EXEC " | |
5819 ;; "Regular expression to use to search for CMS executables.") | |
5820 | |
5821 ;;(or (assq 'cms ange-ftp-dired-re-exe-alist) | |
5822 ;; (setq ange-ftp-dired-re-exe-alist | |
5823 ;; (cons (cons 'cms ange-ftp-dired-cms-re-exe) | |
5824 ;; ange-ftp-dired-re-exe-alist))) | |
5825 | |
5826 | |
5827 ;;(defun ange-ftp-dired-cms-insert-headerline (dir) | |
5828 ;; ;; CMS has no total line, so we insert a blank line for | |
5829 ;; ;; aesthetics. | |
5830 ;; (insert "\n") | |
5831 ;; (forward-char -1) | |
5832 ;; (ange-ftp-real-dired-insert-headerline dir)) | |
5833 | |
5834 ;;(or (assq 'cms ange-ftp-dired-insert-headerline-alist) | |
5835 ;; (setq ange-ftp-dired-insert-headerline-alist | |
5836 ;; (cons '(cms . ange-ftp-dired-cms-insert-headerline) | |
5837 ;; ange-ftp-dired-insert-headerline-alist))) | |
5838 | |
5839 ;;(defun ange-ftp-dired-cms-move-to-filename (&optional raise-error eol) | |
5840 ;; "In dired, move to the first char of filename on this line." | |
5841 ;; ;; This is the CMS version. | |
5842 ;; (or eol (setq eol (progn (end-of-line) (point)))) | |
5843 ;; (let (case-fold-search) | |
5844 ;; (beginning-of-line) | |
5845 ;; (if (re-search-forward " [-A-Z0-9$_]+ +[-A-Z0-9$_]+ +[VF] +[0-9]+ " eol t) | |
5846 ;; (goto-char (1+ (match-beginning 0))) | |
5847 ;; (if raise-error | |
5848 ;; (error "No file on this line") | |
5849 ;; nil)))) | |
5850 | |
5851 ;;(or (assq 'cms ange-ftp-dired-move-to-filename-alist) | |
5852 ;; (setq ange-ftp-dired-move-to-filename-alist | |
5853 ;; (cons '(cms . ange-ftp-dired-cms-move-to-filename) | |
5854 ;; ange-ftp-dired-move-to-filename-alist))) | |
5855 | |
5856 ;;(defun ange-ftp-dired-cms-move-to-end-of-filename (&optional no-error eol) | |
5857 ;; ;; Assumes point is at beginning of filename. | |
5858 ;; ;; So, it should be called only after (dired-move-to-filename t). | |
5859 ;; ;; case-fold-search must be nil, at least for VMS. | |
5860 ;; ;; On failure, signals an error or returns nil. | |
5861 ;; ;; This is the CMS version. | |
5862 ;; (let ((opoint (point)) | |
5863 ;; case-fold-search hidden) | |
5864 ;; (or eol (setq eol (save-excursion (end-of-line) (point)))) | |
5865 ;; (setq hidden (and selective-display | |
5866 ;; (save-excursion | |
5867 ;; (search-forward "\r" eol t)))) | |
5868 ;; (if hidden | |
5869 ;; (if no-error | |
5870 ;; nil | |
5871 ;; (error | |
5872 ;; (substitute-command-keys | |
5873 ;; "File line is hidden, type \\[dired-hide-subdir] to unhide"))) | |
5874 ;; (skip-chars-forward "-A-Z0-9$_" eol) | |
5875 ;; (skip-chars-forward " " eol) | |
5876 ;; (skip-chars-forward "-A-Z0-9$_" eol) | |
5877 ;; (if (eq opoint (point)) | |
5878 ;; (if no-error | |
5879 ;; nil | |
5880 ;; (error "No file on this line")) | |
5881 ;; (point))))) | |
5882 | |
5883 ;;(or (assq 'cms ange-ftp-dired-move-to-end-of-filename-alist) | |
5884 ;; (setq ange-ftp-dired-move-to-end-of-filename-alist | |
5885 ;; (cons '(cms . ange-ftp-dired-cms-move-to-end-of-filename) | |
5886 ;; ange-ftp-dired-move-to-end-of-filename-alist))) | |
5887 | |
5888 (defun ange-ftp-cms-make-compressed-filename (name &optional reverse) | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
5889 (if (string-match "-Z\\'" name) |
28210 | 5890 (list nil (substring name 0 -2)) |
5891 (list t (concat name "-Z")))) | |
5892 | |
5893 (or (assq 'cms ange-ftp-make-compressed-filename-alist) | |
5894 (setq ange-ftp-make-compressed-filename-alist | |
5895 (cons '(cms . ange-ftp-cms-make-compressed-filename) | |
5896 ange-ftp-make-compressed-filename-alist))) | |
5897 | |
5898 ;;(defun ange-ftp-dired-cms-get-filename (&optional localp no-error-if-not-filep) | |
5899 ;; (let ((name (ange-ftp-real-dired-get-filename localp no-error-if-not-filep))) | |
5900 ;; (and name | |
5901 ;; (if (string-match "^\\([^ ]+\\) +\\([^ ]+\\)$" name) | |
5902 ;; (concat (substring name 0 (match-end 1)) | |
5903 ;; "." | |
5904 ;; (substring name (match-beginning 2) (match-end 2))) | |
5905 ;; name)))) | |
5906 | |
5907 ;;(or (assq 'cms ange-ftp-dired-get-filename-alist) | |
5908 ;; (setq ange-ftp-dired-get-filename-alist | |
5909 ;; (cons '(cms . ange-ftp-dired-cms-get-filename) | |
5910 ;; ange-ftp-dired-get-filename-alist))) | |
5911 | |
5912 ;;;; ------------------------------------------------------------ | |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5913 ;;;; BS2000 support |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5914 ;;;; ------------------------------------------------------------ |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5915 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5916 ;; There seems to be an error with regexps. '-' has to be the first |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5917 ;; character inside of the square brackets. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5918 (defconst ange-ftp-bs2000-short-filename-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5919 "[-A-Z0-9$#@.]*[A-Z][-A-Z0-9$#@.]*" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5920 "Regular expression to match for a valid short BS2000 file name.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5921 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5922 (defconst ange-ftp-bs2000-fix-name-regexp-reverse |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5923 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5924 "^\\(" ange-ftp-bs2000-filename-pubset-regexp "\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5925 "\\(" ange-ftp-bs2000-filename-username-regexp "\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5926 "\\(" ange-ftp-bs2000-short-filename-regexp "\\)?") |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
5927 "Regular expression used in `ange-ftp-fix-name-for-bs2000'.") |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5928 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5929 (defconst ange-ftp-bs2000-fix-name-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5930 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5931 "/?\\(" ange-ftp-bs2000-filename-pubset-regexp "/\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5932 "\\(\\$[A-Z0-9]*/\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5933 "\\(" ange-ftp-bs2000-short-filename-regexp "\\)?") |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
5934 "Regular expression used in `ange-ftp-fix-name-for-bs2000'.") |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5935 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5936 (defcustom ange-ftp-bs2000-special-prefix |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5937 "X" |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
5938 "Prefix used for filenames starting with '#' or '@'." |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5939 :group 'ange-ftp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5940 :type 'string) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5941 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5942 ;; Convert NAME from UNIX-ish to BS2000. If REVERSE given then convert from |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5943 ;; BS2000 to UNIX-ish. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5944 (defun ange-ftp-fix-name-for-bs2000 (name &optional reverse) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5945 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5946 (if reverse |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5947 (if (string-match |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5948 ange-ftp-bs2000-fix-name-regexp-reverse |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5949 name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5950 (let ((pubset (if (match-beginning 1) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5951 (substring name 0 (match-end 1)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5952 (userid (if (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5953 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5954 (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5955 (1- (match-end 2))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5956 (filename (if (match-beginning 3) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5957 (substring name (match-beginning 3))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5958 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5959 "/" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5960 ;; we have to insert "_/" here to prevent expand-file-name to |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5961 ;; interpret BS2000 pubsets as the special escape prefix: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5962 (and pubset (concat "_/" pubset "/")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5963 (and userid (concat userid "/")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5964 filename)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5965 (error "name %s didn't match" name)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5966 ;; and here we (maybe) have to remove the inserted "_/" 'cause |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5967 ;; of our prevention of the special escape prefix above: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5968 (if (string-match (concat "^/_/") name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5969 (setq name (substring name 2))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5970 (if (string-match |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5971 ange-ftp-bs2000-fix-name-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5972 name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5973 (let ((pubset (if (match-beginning 1) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5974 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5975 (match-beginning 1) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5976 (1- (match-end 1))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5977 (userid (if (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5978 (substring name |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5979 (match-beginning 2) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5980 (1- (match-end 2))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5981 (filename (if (match-beginning 3) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5982 (substring name (match-beginning 3))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5983 (if (and (boundp 'filename) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5984 (stringp filename) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5985 (string-match "[#@].+" filename)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5986 (setq filename (concat ange-ftp-bs2000-special-prefix |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5987 (substring filename 1)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5988 (upcase |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5989 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5990 pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5991 (and userid (concat userid ".")) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5992 ;; change every '/' in filename to a '.', normally not neccessary |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5993 (and filename |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
5994 (subst-char-in-string ?/ ?. filename))))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5995 ;; Let's hope that BS2000 recognize this anyway: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5996 name)))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5997 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5998 (or (assq 'bs2000 ange-ftp-fix-name-func-alist) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
5999 (setq ange-ftp-fix-name-func-alist |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6000 (cons '(bs2000 . ange-ftp-fix-name-for-bs2000) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6001 ange-ftp-fix-name-func-alist))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6002 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6003 ;; Convert name from UNIX-ish to BS2000 ready for a DIRectory listing. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6004 ;; Remember that there are no directories in BS2000. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6005 (defun ange-ftp-fix-dir-name-for-bs2000 (dir-name) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6006 (if (string-equal dir-name "/") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6007 "*" ;; Don't use an empty string here! |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6008 (ange-ftp-fix-name-for-bs2000 dir-name))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6009 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6010 (or (assq 'bs2000 ange-ftp-fix-dir-name-func-alist) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6011 (setq ange-ftp-fix-dir-name-func-alist |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6012 (cons '(bs2000 . ange-ftp-fix-dir-name-for-bs2000) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6013 ange-ftp-fix-dir-name-func-alist))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6014 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6015 (or (memq 'bs2000 ange-ftp-dumb-host-types) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6016 (setq ange-ftp-dumb-host-types |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6017 (cons 'bs2000 ange-ftp-dumb-host-types))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6018 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6019 (defvar ange-ftp-bs2000-host-regexp nil) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6020 (defvar ange-ftp-bs2000-posix-host-regexp nil) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6021 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6022 ;; Return non-nil if HOST is running BS2000. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6023 (defun ange-ftp-bs2000-host (host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6024 (and ange-ftp-bs2000-host-regexp |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
6025 (string-match-p ange-ftp-bs2000-host-regexp host))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6026 ;; Return non-nil if HOST is running BS2000 with POSIX subsystem. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6027 (defun ange-ftp-bs2000-posix-host (host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6028 (and ange-ftp-bs2000-posix-host-regexp |
99602
c94ec53df9d8
* net/ange-ftp.el (ange-ftp-multi-msgs, ange-ftp-good-msgs)
Juanma Barranquero <lekktu@gmail.com>
parents:
98390
diff
changeset
|
6029 (string-match-p ange-ftp-bs2000-posix-host-regexp host))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6030 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6031 (defun ange-ftp-add-bs2000-host (host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6032 "Mark HOST as the name of a machine running BS2000." |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6033 (interactive |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6034 (list (read-string "Host: " |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6035 (let ((name (or (buffer-file-name) default-directory))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6036 (and name (car (ange-ftp-ftp-name name))))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6037 (if (not (ange-ftp-bs2000-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6038 (setq ange-ftp-bs2000-host-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6039 (concat "^" (regexp-quote host) "$" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6040 (and ange-ftp-bs2000-host-regexp "\\|") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6041 ange-ftp-bs2000-host-regexp) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6042 ange-ftp-host-cache nil))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6043 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6044 (defun ange-ftp-add-bs2000-posix-host (host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6045 "Mark HOST as the name of a machine running BS2000 with POSIX subsystem." |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6046 (interactive |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6047 (list (read-string "Host: " |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6048 (let ((name (or (buffer-file-name) default-directory))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6049 (and name (car (ange-ftp-ftp-name name))))))) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6050 (if (not (ange-ftp-bs2000-posix-host host)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6051 (setq ange-ftp-bs2000-posix-host-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6052 (concat "^" (regexp-quote host) "$" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6053 (and ange-ftp-bs2000-posix-host-regexp "\\|") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6054 ange-ftp-bs2000-posix-host-regexp) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6055 ange-ftp-host-cache nil)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6056 ;; Install CD hook to cd to posix on connecting: |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6057 (add-hook 'ange-ftp-process-startup-hook 'ange-ftp-bs2000-cd-to-posix) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6058 host) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6059 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6060 (defconst ange-ftp-bs2000-filename-regexp |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6061 (concat |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6062 "\\(" ange-ftp-bs2000-filename-prefix-regexp "\\)?" |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6063 "\\(" ange-ftp-bs2000-short-filename-regexp "\\)") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6064 "Regular expression to match for a valid BS2000 file name.") |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6065 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6066 (defcustom ange-ftp-bs2000-additional-pubsets |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6067 nil |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6068 "*List of additional pubsets available to all users." |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6069 :group 'ange-ftp |
44953
edd77d3b9898
(ange-ftp-passive-host-alist)
Richard M. Stallman <rms@gnu.org>
parents:
43187
diff
changeset
|
6070 :type '(repeat string)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6071 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6072 ;; These parsing functions are as general as possible because the syntax |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6073 ;; of ftp listings from BS2000 hosts is a bit erratic. What saves us is that |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6074 ;; the BS2000 filename syntax is so rigid. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6075 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6076 ;; Extract the next filename from a BS2000 dired-like listing. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6077 (defun ange-ftp-parse-bs2000-filename () |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6078 (if (re-search-forward ange-ftp-bs2000-filename-regexp nil t) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6079 (match-string 2))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6080 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6081 ;; Parse the current buffer which is assumed to be in (some) BS2000 FTP dir |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6082 ;; format, and return a hashtable as the result. |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6083 (defun ange-ftp-parse-bs2000-listing () |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6084 (let ((tbl (make-hash-table :test 'equal)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6085 pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6086 file) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6087 ;; get current pubset |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6088 (goto-char (point-min)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6089 (if (re-search-forward ange-ftp-bs2000-filename-pubset-regexp nil t) |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6090 (setq pubset (match-string 0))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6091 ;; add files to hashtable |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6092 (goto-char (point-min)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6093 (save-match-data |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6094 (while (setq file (ange-ftp-parse-bs2000-filename)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6095 (puthash file nil tbl))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6096 ;; add . and .. |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6097 (puthash "." t tbl) |
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6098 (puthash ".." t tbl) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6099 ;; add all additional pubsets, if not listing one of them |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6100 (if (not (member pubset ange-ftp-bs2000-additional-pubsets)) |
84913
db1179979d6b
(ange-ftp-call-chmod, ange-ftp-parse-bs2000-listing):
Juanma Barranquero <lekktu@gmail.com>
parents:
83791
diff
changeset
|
6101 (mapc (lambda (pubset) (puthash pubset t tbl)) |
db1179979d6b
(ange-ftp-call-chmod, ange-ftp-parse-bs2000-listing):
Juanma Barranquero <lekktu@gmail.com>
parents:
83791
diff
changeset
|
6102 ange-ftp-bs2000-additional-pubsets)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6103 tbl)) |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6104 |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6105 (add-to-list 'ange-ftp-parse-list-func-alist |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6106 '(bs2000 . ange-ftp-parse-bs2000-listing)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6107 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6108 (defun ange-ftp-bs2000-cd-to-posix () |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6109 "cd to POSIX subsystem if the current host matches |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6110 `ange-ftp-bs2000-posix-host-regexp'. All BS2000 hosts with POSIX subsystem |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6111 MUST BE EXPLICITLY SET with `ange-ftp-add-bs2000-posix-host' for they cannot |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6112 be recognized automatically (they are all valid BS2000 hosts too)." |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6113 (if (and ange-ftp-this-host (ange-ftp-bs2000-posix-host ange-ftp-this-host)) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6114 (progn |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6115 ;; change to POSIX: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6116 ; (ange-ftp-raw-send-cmd proc "cd %POSIX") |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6117 (ange-ftp-cd ange-ftp-this-host ange-ftp-this-user "%POSIX") |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6118 ;; put new home directory in the expand-dir hashtable. |
47113
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6119 ;; `ange-ftp-this-host' and `ange-ftp-this-user' are bound in |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6120 ;; ange-ftp-get-process. |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6121 (puthash (concat ange-ftp-this-host "/" ange-ftp-this-user "/~") |
72b3185698c4
Use match-string and drop useless `function's.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47068
diff
changeset
|
6122 (car (ange-ftp-get-pwd ange-ftp-this-host ange-ftp-this-user)) |
46355
2ecef3663b04
Use hash-tables.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46349
diff
changeset
|
6123 ange-ftp-expand-dir-hashtable)))) |
42861
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6124 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6125 ;; Not available yet: |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6126 ;; ange-ftp-bs2000-delete-file-entry |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6127 ;; ange-ftp-bs2000-add-file-entry |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6128 ;; ange-ftp-bs2000-file-name-as-directory |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6129 ;; ange-ftp-bs2000-make-compressed-filename |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6130 ;; ange-ftp-bs2000-file-name-sans-versions |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6131 |
3ee90bcdf67d
Added support for BS2000, and for raw ftp
Richard M. Stallman <rms@gnu.org>
parents:
42801
diff
changeset
|
6132 ;;;; ------------------------------------------------------------ |
28210 | 6133 ;;;; Finally provide package. |
6134 ;;;; ------------------------------------------------------------ | |
6135 | |
6136 (provide 'ange-ftp) | |
6137 | |
64906
63dd464bce2d
Use \\` and \\' instead of ^ and $ in regexps.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64862
diff
changeset
|
6138 ;; arch-tag: 2987ef88-cb56-4ec1-87a9-79132572e316 |
28210 | 6139 ;;; ange-ftp.el ends here |