unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* File names with spaces and tramp/ftp
@ 2008-02-06 22:17 Lennart Borgman (gmail)
  2008-02-11 15:39 ` Michael Albinus
  0 siblings, 1 reply; 6+ messages in thread
From: Lennart Borgman (gmail) @ 2008-02-06 22:17 UTC (permalink / raw)
  To: Emacs Devel, Michael Albinus

There is a problem in tramp/ftp with file names that contains spaces, at 
least on w32. I do not know if it is possible to cure this and how to do it.

Currently I check for spaces in the local file name and replace the file 
name with the short version. I guess that is only possible on w32. 
Perhaps there is a better solution?




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: File names with spaces and tramp/ftp
  2008-02-06 22:17 File names with spaces and tramp/ftp Lennart Borgman (gmail)
@ 2008-02-11 15:39 ` Michael Albinus
  2008-02-11 20:18   ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Albinus @ 2008-02-11 15:39 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:

Hi Lennart,

sorry for the delay; it's always a problem for me to catch a w32
machine for testing.

> There is a problem in tramp/ftp with file names that contains spaces,
> at least on w32. I do not know if it is possible to cure this and how
> to do it.

I can reproduce it here. Tested with GNU Emacs 22.1 and the default
"ftp.exe" binary found in "c:\WINDOWS\system32\", the machine runs
"Windows XP SP2".

My test case is copying the local file "u:\file name with spaces" to
the remote directory "/tmp".

The first problem is that ange-ftp does not encode the local file name
when passing to the "put" command. It uses the command

  put u:/file name with spaces /tmp/file\ name\ with\ spaces

The result is an empty file "name" on the FTP server. But even
encoding the local file name like this does not work:

  put u:/file\ name\ with\ spaces /tmp/file\ name\ with\ spaces

results in an empty file "name\" on the remote server. Note that with
an FTP client on a GNU/Linux machine, this runs OK.

A sufficient encoding seems to be using double quotes:

  put "u:/file name with spaces" "/tmp/file name with spaces"

gives the expected results.

I could change ange-ftp to this encoding style of file names; but I am
anxious: it could break ange-ftp on other systems, where double quotes
might not be supported. No idea whether double quote encoding works
with all possible combinations of FTP clients and servers.

Maybe the best would be a user option to decide the kind of quoting
file names? Or is it already sufficient just to encode with double
quotes, when the local host is w32? What do people think?

Best regards, Michael.

PS: As far as I see, Tramp is not involved.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: File names with spaces and tramp/ftp
  2008-02-11 15:39 ` Michael Albinus
@ 2008-02-11 20:18   ` Eli Zaretskii
  2008-02-12  3:16     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2008-02-11 20:18 UTC (permalink / raw)
  To: Michael Albinus; +Cc: lennart.borgman, emacs-devel

> From: Michael Albinus <michael.albinus@gmx.de>
> Date: Mon, 11 Feb 2008 16:39:28 +0100
> Cc: Emacs Devel <emacs-devel@gnu.org>
> 
> A sufficient encoding seems to be using double quotes:
> 
>   put "u:/file name with spaces" "/tmp/file name with spaces"
> 
> gives the expected results.
> 
> I could change ange-ftp to this encoding style of file names; but I am
> anxious: it could break ange-ftp on other systems, where double quotes
> might not be supported.

Does it help to use shell-quote-argument?




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: File names with spaces and tramp/ftp
  2008-02-11 20:18   ` Eli Zaretskii
@ 2008-02-12  3:16     ` Stefan Monnier
  2008-02-12 13:00       ` Michael Albinus
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2008-02-12  3:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: lennart.borgman, Michael Albinus, emacs-devel

>> A sufficient encoding seems to be using double quotes:
>> 
>> put "u:/file name with spaces" "/tmp/file name with spaces"
>> 
>> gives the expected results.
>> 
>> I could change ange-ftp to this encoding style of file names; but I am
>> anxious: it could break ange-ftp on other systems, where double quotes
>> might not be supported.

> Does it help to use shell-quote-argument?

I doubt it: the FTP command is not passed through a shell.
In some cases it may work, of course.


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: File names with spaces and tramp/ftp
  2008-02-12  3:16     ` Stefan Monnier
@ 2008-02-12 13:00       ` Michael Albinus
  2008-02-12 19:58         ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Albinus @ 2008-02-12 13:00 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Eli Zaretskii, lennart.borgman, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1269 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> I could change ange-ftp to this encoding style of file names; but I am
>>> anxious: it could break ange-ftp on other systems, where double quotes
>>> might not be supported.
>
>> Does it help to use shell-quote-argument?
>
> I doubt it: the FTP command is not passed through a shell.
> In some cases it may work, of course.

But it is a good approximation. Under GNU/Linux, we have

  (shell-quote-argument "file name with spaces 'and \"quotes")
    => "file\\ name\\ with\\ spaces\\ \\'and\\ \\\"quotes"

W32 systems do 

  (shell-quote-argument "file name with spaces 'and \"quotes")
    => "\"file name with spaces 'and \\\"quotes\""

Both quotations work with stock FTP clients except the quotation of
"\"" on W32 systems: it shall be "\"\" instead of "\\\"". But this
could be adapted, and "\"" isn't so usual on W32 file names. Btw, I
could not create the file "~/file name with spaces 'and \"quotes" on
W32 in Emacs; this worked only with Emacs under GNU/Linux.

Lennart (et al), could you, please, test whether the appended patch
works for you for file names with spaces? And that there isn't any
other regression?

The patch is towards ange-ftp.el in the trunk.

>         Stefan

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1557 bytes --]

*** /usr/local/src/emacs/lisp/net/ange-ftp.el.~1~	Wed Feb  6 20:49:56 2008
--- /usr/local/src/emacs/lisp/net/ange-ftp.el	Tue Feb 12 13:46:33 2008
***************
*** 1523,1541 ****
  
  (defun ange-ftp-quote-string (string)
    "Quote any characters in STRING that may confuse the ftp process."
!   (apply 'concat
! 	 (mapcar (lambda (char)
! 		   ;; This is said to be wrong; ftp is said to
! 		   ;; need quoting only for ", and that by doubling it.
! 		   ;; But experiment says this kind of quoting is correct
! 		   ;; when talking to ftp on GNU/Linux systems.
! 		   (if (or (<= char ? )
! 			   (> char ?\~)
! 			   (= char ?\")
! 			   (= char ?\\))
! 		       (vector ?\\ char)
! 		     (vector char)))
! 		 string)))
  
  (defun ange-ftp-barf-if-not-directory (directory)
    (or (file-directory-p directory)
--- 1523,1529 ----
  
  (defun ange-ftp-quote-string (string)
    "Quote any characters in STRING that may confuse the ftp process."
!   (when (stringp string) (shell-quote-argument string)))
  
  (defun ange-ftp-barf-if-not-directory (directory)
    (or (file-directory-p directory)
***************
*** 3766,3772 ****
  	    (ange-ftp-send-cmd
  	     t-host
  	     t-user
! 	     (list 'put (or temp2 filename) t-name)
  	     (or msg
  		 (if (and temp2 f-parsed)
  		     (format "Putting %s" newname)
--- 3754,3760 ----
  	    (ange-ftp-send-cmd
  	     t-host
  	     t-user
! 	     (list 'put (or temp2 (ange-ftp-quote-string filename)) t-name)
  	     (or msg
  		 (if (and temp2 f-parsed)
  		     (format "Putting %s" newname)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: File names with spaces and tramp/ftp
  2008-02-12 13:00       ` Michael Albinus
@ 2008-02-12 19:58         ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2008-02-12 19:58 UTC (permalink / raw)
  To: Michael Albinus; +Cc: lennart.borgman, monnier, emacs-devel

> Cc: Eli Zaretskii <eliz@gnu.org>, lennart.borgman@gmail.com,
>         emacs-devel@gnu.org
> From: Michael Albinus <michael.albinus@gmx.de>
> Date: Tue, 12 Feb 2008 14:00:48 +0100
> 
> But it is a good approximation. Under GNU/Linux, we have
> 
>   (shell-quote-argument "file name with spaces 'and \"quotes")
>     => "file\\ name\\ with\\ spaces\\ \\'and\\ \\\"quotes"
> 
> W32 systems do 
> 
>   (shell-quote-argument "file name with spaces 'and \"quotes")
>     => "\"file name with spaces 'and \\\"quotes\""
> 
> Both quotations work with stock FTP clients except the quotation of
> "\"" on W32 systems: it shall be "\"\" instead of "\\\"".

This case is not important to handle, since Windows file names cannot
include qoute characters " anyway, as you have discovered:

> Btw, I
> could not create the file "~/file name with spaces 'and \"quotes" on
> W32 in Emacs; this worked only with Emacs under GNU/Linux.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-02-12 19:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-06 22:17 File names with spaces and tramp/ftp Lennart Borgman (gmail)
2008-02-11 15:39 ` Michael Albinus
2008-02-11 20:18   ` Eli Zaretskii
2008-02-12  3:16     ` Stefan Monnier
2008-02-12 13:00       ` Michael Albinus
2008-02-12 19:58         ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).