unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* ange-ftp-file-size
@ 2009-10-15  3:20 Toru TSUNEYOSHI
  2009-10-15 12:55 ` ange-ftp-file-size Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Toru TSUNEYOSHI @ 2009-10-15  3:20 UTC (permalink / raw
  To: emacs-devel

[-- Attachment #1: Type: Text/Plain, Size: 262 bytes --]

Hello.

Now, ange-ftp-file-attributes doesn't return the file size. It returns
-1.
I wish it returns the size exactly, so I make ange-ftp-file-size.
If no problem, would you like to apply to ange-ftp.el, and modify code
at the size of ange-ftp-file-attributes ?

[-- Attachment #2: ange-ftp-file-size.el --]
[-- Type: Text/Plain, Size: 1205 bytes --]

;; After the style of `ange-ftp-file-modtime'.
;; *** I don't check return code 226 on wu-ftpd. ***

(defun ange-ftp-file-size (file &optional ascii-mode)
  "Return the size of remote file FILE. Return -1 if can't get it.
If ascii-mode is non-nil, return the size with the extra octets that
need to be inserted, one at the end of each line, to provide correct
end-of-line semantics for a transfer using TYPE=A. The default is nil,
so return the size on the remote host exactly. See RFC 3659."
  (let* ((parsed (ange-ftp-ftp-name file))
	 (host (nth 0 parsed))
	 (user (nth 1 parsed))
	 (name (ange-ftp-quote-string (nth 2 parsed)))
	 ;; At least one FTP server (wu-ftpd) can return a "226
	 ;; Transfer complete" before the "213 SIZE".  Let's skip
	 ;; that.
	 (ange-ftp-skip-msgs (concat ange-ftp-skip-msgs "\\|^226"))
         (res (prog2
		  (unless ascii-mode
		    (ange-ftp-set-binary-mode host user))
		  (ange-ftp-send-cmd host user (list 'quote "size" name))
		(unless ascii-mode
		  (ange-ftp-set-ascii-mode host user))))
	 (line (cdr res))
	 (size -1))
    (save-match-data
      (when (string-match "^213 \\([0-9]+\\)$" line)
	(setq size (string-to-number (match-string 1 line)))))
    size))

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

end of thread, other threads:[~2009-10-18  3:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-15  3:20 ange-ftp-file-size Toru TSUNEYOSHI
2009-10-15 12:55 ` ange-ftp-file-size Stefan Monnier
2009-10-16  4:31   ` ange-ftp-file-size Toru TSUNEYOSHI
2009-10-16 15:22     ` ange-ftp-file-size Stefan Monnier
2009-10-17  2:21       ` ange-ftp-file-size Toru TSUNEYOSHI
2009-10-18  2:03         ` ange-ftp-file-size Stefan Monnier
2009-10-18  3:07           ` ange-ftp-file-size Toru TSUNEYOSHI

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