Sailor Family

Home

Sailor At Work

Firefox
Java
Rubik Cube
Toto/4D

Html
Perl
Chinese

Emacs/Cygwin









Drop me a note
Email Web Sailor
Welcome to Web Sailor's Home
Home > Emacs/Cygwin > Using Emacs With Ange-FTP

Using Emacs with Ange-FTP

Emacs allows you to edit a file at a remote host as if the file is resided in your local machine. All you need to do is invoke the find-file command with C-x C-f with a filename looks like the following.

/sailor@ftp.usa.com:/



Setting Up Ange-FTP

By default, Emacs uses the Windows FTP program resided in your C:/windows directory to perform Ange-FTP. You really do not need to do any settings.

For those who insists of using Cygwin FTP, you will need to do this.

(setq ange-ftp-ftp-program-args (list "-i" "-n" "-g" "-v" "--prompt="))
 


Ange-FTP for Dumb Unix Host

Some FTP servers may not support fully the "ls" directory listing command. Under these circumstances, "dir" should be used instead of "ls". These happen to Tripod, Geocities FTP servers. The following statement should solve the problem.

(setq ange-ftp-dumb-unix-host-regexp "^ftp\\.tripod\\.com\\|ftp\\.geocities\\.com$")
 

On Geocities, you should specify the full path that you can access, for example, /sailor@ftp.geocities.com:/sailor/. If you try to open /sailor@ftp.geocities.com:/ only, you will see an error saying "550 Permission denied on server. You are restricted to your account."



Using Ange-FTP From Behind the Firewall

It is possible to ange-ftp access a remote file from behind the firewall. However, you will need to have access to the FTP gateway provided by your company. Usually the following lisp statements will be sufficient.

(setq ange-ftp-local-host-regexp "\\.usa\\.com$\\|\\.[0-9]+\\.[0-9]+$\\|^[^.]*$")
(setq ange-ftp-gateway-host "ftpgate0.usa.com")
(setq ange-ftp-smart-gateway t)


Using Ange-FTP From Behind the Firewall

Some companies have very strict control over FTP access to the internet. They want to track each individual uses FTP to connect to the internet. To connect to the internet, the user need to connect to a FTP gateway which requires authentication. If you run the ftp on a shell, the following is probably what it will look like.

  • % ftp -n ftpgate0.usa.com
  • ftp> user f12345
  • ftp> password : ******
  • ftp> user khngai@ftp.tripod.com
  • ftp> password : ******

Under this circumstance the following lisp statements are required for ange-ftp to work.

(setq ange-ftp-local-host-regexp "\\.usa\\.com$\\|\\.[0-9]+\\.[0-9]+$\\|^[^.]*$")
(setq ange-ftp-gateway-host "ftpgate0.usa.com")
(setq ange-ftp-smart-gateway t)

;; Set the default user name for ange-ftp-gateway-host.
;; You may change it interactively using function ange-ftp-set-passwd.
(ange-ftp-set-user ange-ftp-gateway-host "f12345")

(defun ange-ftp-smart-login (host user pass account proc)
  "05Feb02, sailor. Modified from original ange-ftp-smart-login.
Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT.
PROC is the FTP-client's process.  This routine uses the smart-gateway
host specified in `ange-ftp-gateway-host'."
  (let ((result (ange-ftp-raw-send-cmd
                 proc
                 (format "open %s %s"
                         (ange-ftp-nslookup-host ange-ftp-gateway-host)
                         ange-ftp-smart-gateway-port)
                 (format "Opening FTP connection to %s via %s"
                         host
                         ange-ftp-gateway-host))))
    (or (car result)
        (ange-ftp-error host user
                        (concat "OPEN request failed: "
                                (cdr result))))

    ;; The gateway needs user login and password.
    (let ((gateway-user) (gateway-password) (gateway-command))

      (setq gateway-user (ange-ftp-get-user ange-ftp-gateway-host))

      (if (not (ange-ftp-lookup-passwd ange-ftp-gateway-host gateway-user))
          (setq gateway-password
                (read-passwd
                 (format "passwd for %s@%s: "
                         gateway-user ange-ftp-gateway-host)
                 ))
        (setq gateway-password (ange-ftp-get-passwd ange-ftp-gateway-host gateway-user))
        )

      (setq gateway-command (format "user %s %s" gateway-user gateway-password))

      (setq result (ange-ftp-raw-send-cmd proc gateway-command))

      ;; Need to remove the user name and password in the FTP buffer.
      ;; This is to prevent others from seeing the password.
      (with-current-buffer (ange-ftp-ftp-process-buffer host user)
        (beginning-of-buffer)
        (while (search-forward gateway-command nil t)
          (replace-match "" nil t))
        )

      (or (car result)
          (ange-ftp-error host user
                          (concat "Gateway login failed: "
                                  (cdr result))))

      (ange-ftp-set-passwd ange-ftp-gateway-host gateway-user gateway-password)
      )


    (setq result (ange-ftp-raw-send-cmd
                  proc (format "user \"%s\"@%s %s %s"
                               user
                               (ange-ftp-nslookup-host host)
                               pass
                               account)
                  (format "Logging in as user %s@%s"
                          user host)))
    (or (car result)
        (progn
          (ange-ftp-set-passwd host user nil) ; reset password
          (ange-ftp-set-account host user nil) ; reset account
          (ange-ftp-error host user
                          (concat "USER request failed: "
                                  (cdr result)))))))


Langkawi Sunset