Function: ange-ftp-file-size

ange-ftp-file-size is a byte-compiled function defined in ange-ftp.el.gz.

Signature

(ange-ftp-file-size FILE &optional ASCII-MODE)

Documentation

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.

Source Code

;; Defined in /usr/src/emacs/lisp/net/ange-ftp.el.gz
(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 (unwind-protect
                  (progn
                    (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)))
    (if (string-match "^213 \\([0-9]+\\)$" line)
	(string-to-number (match-string 1 line))
      -1)))