[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Subject: ange-ftp-file-size
Date: Thu, 15 Oct 2009 12:20:16 +0900


Now, ange-ftp-file-attributes doesn't return the file size. It returns
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 ?
;; 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))
      (when (string-match "^213 \\([0-9]+\\)$" line)
        (setq size (string-to-number (match-string 1 line)))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]