Automated ftp sessions via ncftp 2.3.0

circa 1997


If you are a regular UNIX user you know that ftp is an example of UNIX at its best. Lots of little arcane commands. Fortunately there is ncftp which makes ftp more powerful and has even MORE arcane commands.

Using ncftp it is possible to do a complete ftp session from the UNIX shell, including sending your username and password and specifying which files to get. This is very useful if you want to automatically ftp some files every day, once a week or whatever. (See cron for more about scheduling events)

getting ncftp source code and ncftp installation

Let me state right away that getting and installing ncftp was one of the single most difficult UNIX installation tasks I have undertaken since I installed Sybase. Finding the damn code for it was tough due to an inordinate number of stale links that come up on my AltaVista search, an inordinate number of ftp servers that wouldn't let me in (I don't think it was because they had too many anonymous users, because usually it says so if that is the case). Anyway, here is ncftp-2.3.0.tar.gz, and ncftp-2.3.0-ELF-bin.tar.gz and the updates are supposed to be found at ftp://ftp.cs.unl.edu/pub/ncftp/

Finally, I had to install ncurses which I downloaded from the GNU archive at MIT (prep.ai.mit.edu) and then I discovered that the auto-configuration for ncftp-2.3.0 didn't work. I had to edit the Config.h file and manually comment out the line

/* Define if you have the  header file.  */
/*#define HAVE_NCURSES_H 1*/
Because I had curses.h, and not ncurses.h, but the configure program for some reason, deteremined that I should have the ncurses.h file.

Doing an automated ftp session with ncftp

This is for people who want set up a shell script that will run with no user interaction and will ftp some files. There are two ways to do this.
  1. Colon Method

    Use the Colon method. In theory (and in documentation) this works. Set up a bookmark using the ncftp "bookmarks" editor. See the man pages for how this works. If you have ncftp working right and can figure out your terminal type, it should be pretty easy. Basically it allows you to enter your username and password for a site and store it in this bookmarks file (warning you're password won'd be stored encrypted)

    Now, suppose you have a bookmark called "Foo". Then you can do something like this.

         ncftp Foo:/dir/file
        
    And ncftp should log you in, and get the file /dir/file and leave it in the current directory. For other options, read the ncftp man pages.

    Because that option didn't work at the site I was trying, I had to come up with another method.

  2. Macros

    Make a file in your .ncftp directory (which ncftp creates and places in your home directory) called macros (unless it already exists) Here are two macros I made.

         macro .open.Foo
               cd  dir
               get file
               endSession
         end
         macro endSession
               close
               quit
         end
         

    The first macro references a bookmark I made called Foo. The .open.Foo macro will be called automatically whenever ncftp connects to the server I named in the Foo bookmark. So the first thing the macro does is to cd to directory "dir" and then it gets file "file" and then it calls the macro "endSession"

    The endSession macro simply closes the connection and forces ncftp to quit, thus returning to the shell which started this whole thing.

    To use this method, from the command line simply say "ncftp Foo"

The end


Return to Gene's Home Page
Return to Gene's Random Unix Crap