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