home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / ncftp / part03 < prev    next >
Encoding:
Text File  |  1993-11-02  |  61.0 KB  |  2,368 lines

  1. Newsgroups: comp.sources.misc
  2. From: mgleason@cse.unl.edu (Mike Gleason)
  3. Subject: v40i078:  ncftp - Alternative User Interface for FTP, v1.6, Part03/06
  4. Message-ID: <1993Nov2.232348.6380@sparky.sterling.com>
  5. X-Md4-Signature: e61de168560bd974970fb040dc3b4380
  6. Keywords: ncftp
  7. Sender: kent@sparky.sterling.com (Kent Landfield)
  8. Organization: NCEMRSoft
  9. Date: Tue, 2 Nov 1993 23:23:48 GMT
  10. Approved: kent@sparky.sterling.com
  11.  
  12. Submitted-by: mgleason@cse.unl.edu (Mike Gleason)
  13. Posting-number: Volume 40, Issue 78
  14. Archive-name: ncftp/part03
  15. Environment: UNIX, ANSI-C, !SVR4
  16. Supersedes: ncftp: Volume 39, Issue 53-57
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then feed it
  20. # into a shell via "sh file" or similar.  To overwrite existing files,
  21. # type "sh file -c".
  22. # Contents:  Makefile getpass.h ncftp.1 open.c
  23. # Wrapped by kent@sparky on Mon Nov  1 16:19:17 1993
  24. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 3 (of 6)."'
  27. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'Makefile'\"
  29. else
  30.   echo shar: Extracting \"'Makefile'\" \(6637 characters\)
  31.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  32. X# Makefile for ncftp
  33. X# 
  34. X# Major sections delimited by a dash lines.  If several lines set the same
  35. X# make variable, you can choose between the commented #samples, or just
  36. X# type what you want manually.
  37. X#--------------------------------------------------------------------------
  38. X
  39. X
  40. X# System dependent definitions.  See the README, part B.
  41. X#--------------------------------------------------------------------------
  42. XSDEFS = 
  43. X
  44. X
  45. X# Program definitions.  See the README, part C.
  46. X#--------------------------------------------------------------------------
  47. XPDEFS =
  48. X#PDEFS = -DGETLINE
  49. X#PDEFS = -DREADLINE -DCURSES
  50. X#PDEFS = -DSOCKS
  51. X#PDEFS = -DDEBUG -DDB_ERRS
  52. X
  53. X
  54. X# Choose your compiler and flags below.  Make sure you use an ANSI compiler
  55. X# that handles new style function declarations and prototypes (gcc should).
  56. X#--------------------------------------------------------------------------
  57. XCC = cc
  58. X#CC = gcc
  59. X
  60. X#CFLAGS = -O
  61. XCFLAGS = -O2
  62. X#CFLAGS = -g
  63. X
  64. XLFLAGS = -s
  65. X#LFLAGS =
  66. X
  67. X
  68. X# Additional libraries and/or object files.
  69. X# 
  70. X# For each library, add -lLIBNAME to the LIBS line below, for a library
  71. X#   named libLIBNAME.a.
  72. X#
  73. X# For each object file, just add the pathname of the object file.
  74. X#
  75. X# Some may need any of -lsocket, -lnet, -linet, -lintl, or -lnsl. 
  76. X# You'll need -lcurses or -ltermcap if CURSES is defined.
  77. X# You'll need -lreadline AND either -lcurses or -ltermcap if you
  78. X#   want to use the GNU Readline library.
  79. X# You'll need -lgetline (compile it as a library) if you want to use
  80. X#   getline.
  81. X# If your system is running Yellow Pages, you'll need to add the library
  82. X#   that has the YP/NIS version of getpwuid() in it (Important!)
  83. X# You'll need to know where the Rconnect.o object file is if you want
  84. X#   to use Socks.
  85. X#--------------------------------------------------------------------------
  86. XLIBS =
  87. X#LIBS = -ldbmalloc
  88. X#LIBS = -lgetline
  89. X#LIBS = -lreadline -lcurses
  90. X#LIBS = ../lib/Rconnect.o
  91. X#LIBS = -lnet -lnsl -lsocket -lcurses
  92. X
  93. X
  94. X# If the libraries are in a non-standard directory, or you if want to use
  95. X# getline or readline and they aren't installed system-wide, add the
  96. X# extra directories to look in here, using -L's.
  97. X#--------------------------------------------------------------------------
  98. XLIBDIRS =
  99. X#LIBDIRS = -L../getline
  100. X#LIBDIRS = -L../readline
  101. X
  102. X
  103. X# Additional headers.
  104. X#
  105. X# If you defined READLINE or GETLINE, you have to tell where it's header
  106. X# file can be found.
  107. X#
  108. X# For READLINE, provide a path which would find <readline/readline.h>,
  109. X#   so you would put the parent directory of the readline directory below.
  110. X#   If you had '/usr/local/readline/readline.h' you would use
  111. X#   -I/usr/local.
  112. X#
  113. X# For GETLINE, a little different. Just supply a path that would find
  114. X#   <getline.h>.  If you had '/usr/local/getline/getline.h' you would use
  115. X#   -I/usr/local/getline.
  116. X#--------------------------------------------------------------------------
  117. XHDRDIRS =
  118. X#HDRDIRS = -I../getline
  119. X#HDRDIRS = -I..
  120. X
  121. X
  122. X# If you want to 'make install,' edit these variables, otherwise don't
  123. X# worry about it.
  124. X# To install MAN style pages, set MANDIR to the proper location.
  125. X# To install CATMAN style pages, set CATMANDIR, NROFF, and PACK to the proper
  126. X# locations.
  127. X# To inhibit the installation of either, unset MANDIR/CATMANDIR.
  128. X#--------------------------------------------------------------------------
  129. XBINDIR = /usr/lbin
  130. XMANDIR = /usr/man/man1
  131. X#MANDIR = 
  132. XCATMANDIR = /usr/catman/LOCAL/g1
  133. X#CATMANDIR =
  134. XNROFF    = /usr/ucb/nroff
  135. XPACK    = pack
  136. XTEST    = test
  137. XRM = rm -f
  138. XCP = cp
  139. X
  140. X
  141. X#************************************************
  142. X#*** SHOULD NOT NEED TO EDIT BELOW THIS POINT ***
  143. X#************************************************
  144. X
  145. XDEFS = $(PDEFS) $(SDEFS)
  146. XMK = $(CC) $(CFLAGS) $(DEFS) $(HDRDIRS) $(LFLAGS) $(LIBDIRS) $(LIBS)
  147. XSRCS = cmds.c cmdtab.c ftp.c ftprc.c getpass.c glob.c main.c open.c set.c \
  148. Xtips.c util.c
  149. X  
  150. XHEADERS = cmds.h copyright.h defaults.h ftp.h ftprc.h getpass.h glob.h \
  151. Xmain.h open.h set.h sys.h util.h
  152. X   
  153. XOBJS = cmds.o cmdtab.o ftp.o ftprc.o getpass.o glob.o main.o open.o set.o \
  154. Xtips.o util.o
  155. X
  156. XNAME = ncftp
  157. XMAN = ncftp.1
  158. XCATMAN = ncftp.z
  159. XALL = $(SRCS) $(HEADERS) patchlevel.h Blurb README Makefile $(MAN) \
  160. Xv2_Note
  161. X
  162. XC_COMPILE = $(CC) $(CFLAGS) $(DEFS) $(HDRDIRS)
  163. XC_COMPILE2 = $(CC) $(CFLAGS) $(DEFS) -DMK='"$(MK)"' $(HDRDIRS)
  164. X
  165. Xall: $(NAME) done
  166. X
  167. X$(NAME): $(OBJS)
  168. X    $(CC) $(LFLAGS) $(LIBDIRS) $(OBJS)  -o $(NAME) $(LIBS)
  169. X
  170. Xinstall: $(NAME)
  171. X    $(CP) $(NAME) $(BINDIR)/$(NAME)
  172. X    @if $(TEST) -n '$(MANDIR)'; then \
  173. X        $(MAKE) install_man ; else true ;  fi
  174. X    @if $(TEST) -n '$(CATMANDIR)'; then \
  175. X        $(MAKE) install_catman ; else true ;  fi
  176. X
  177. Xinstall_man: 
  178. X    $(CP) $(MAN)  $(MANDIR)/$(MAN)
  179. X
  180. Xinstall_catman:  $(CATMAN)
  181. X    $(CP) $(CATMAN)  $(CATMANDIR)/$(CATMAN)
  182. X
  183. Xuninstall:
  184. X    $(RM) $(BINDIR)/$(NAME)
  185. X    $(RM) $(MANDIR)/$(MAN)
  186. X    $(RM) $(CATMANDIR)/$(CATMAN)
  187. X
  188. X$(CATMAN): $(MAN)
  189. X    rm -f tmp
  190. X    $(NROFF) -man -Tlp $(MAN) > tmp
  191. X    $(PACK) -f tmp
  192. X    mv tmp.z $(CATMAN)
  193. X
  194. Xcmds.o:
  195. X    $(C_COMPILE2) cmds.c -c
  196. X
  197. X.c.o:
  198. X    $(C_COMPILE) -c $<
  199. X
  200. Xdone: $(NAME)
  201. X    -@ls -l $(NAME)
  202. X    -@echo 'Done.'
  203. X
  204. Xclean:
  205. X    rm -f $(OBJS) $(NAME)
  206. X
  207. X# Dependencies:
  208. Xcmds.o: cmds.c 
  209. Xcmds.o: sys.h 
  210. Xcmds.o: util.h 
  211. Xcmds.o: cmds.h 
  212. Xcmds.o: main.h 
  213. Xcmds.o: ftp.h 
  214. Xcmds.o: ftprc.h 
  215. Xcmds.o: getpass.h 
  216. Xcmds.o: glob.h 
  217. Xcmds.o: open.h 
  218. Xcmds.o: set.h 
  219. Xcmds.o: defaults.h 
  220. Xcmds.o: copyright.h 
  221. Xcmdtab.o: cmdtab.c 
  222. Xcmdtab.o: sys.h 
  223. Xcmdtab.o: util.h 
  224. Xcmdtab.o: cmds.h 
  225. Xcmdtab.o: main.h 
  226. Xcmdtab.o: ftp.h 
  227. Xcmdtab.o: ftprc.h 
  228. Xcmdtab.o: glob.h 
  229. Xcmdtab.o: open.h 
  230. Xcmdtab.o: set.h 
  231. Xcmdtab.o: copyright.h 
  232. Xftp.o: ftp.c 
  233. Xftp.o: sys.h 
  234. Xftp.o: util.h 
  235. Xftp.o: ftp.h 
  236. Xftp.o: cmds.h 
  237. Xftp.o: main.h 
  238. Xftp.o: ftprc.h 
  239. Xftp.o: getpass.h 
  240. Xftp.o: defaults.h 
  241. Xftp.o: copyright.h 
  242. Xftprc.o: ftprc.c 
  243. Xftprc.o: sys.h 
  244. Xftprc.o: util.h 
  245. Xftprc.o: ftprc.h 
  246. Xftprc.o: main.h 
  247. Xftprc.o: cmds.h 
  248. Xftprc.o: set.h 
  249. Xftprc.o: defaults.h 
  250. Xftprc.o: copyright.h 
  251. Xgetpass.o: getpass.c 
  252. Xgetpass.o: sys.h 
  253. Xgetpass.o: util.h 
  254. Xgetpass.o: cmds.h 
  255. Xgetpass.o: getpass.h 
  256. Xgetpass.o: copyright.h 
  257. Xglob.o: glob.c 
  258. Xglob.o: sys.h 
  259. Xglob.o: util.h 
  260. Xglob.o: glob.h 
  261. Xglob.o: cmds.h 
  262. Xglob.o: copyright.h 
  263. Xmain.o: main.c 
  264. Xmain.o: sys.h 
  265. Xmain.o: util.h 
  266. Xmain.o: cmds.h 
  267. Xmain.o: main.h 
  268. Xmain.o: ftp.h 
  269. Xmain.o: ftprc.h 
  270. Xmain.o: open.h 
  271. Xmain.o: set.h 
  272. Xmain.o: defaults.h 
  273. Xmain.o: copyright.h 
  274. Xopen.o: open.c 
  275. Xopen.o: sys.h 
  276. Xopen.o: util.h 
  277. Xopen.o: open.h 
  278. Xopen.o: cmds.h 
  279. Xopen.o: ftp.h 
  280. Xopen.o: ftprc.h 
  281. Xopen.o: main.h 
  282. Xopen.o: defaults.h 
  283. Xopen.o: copyright.h 
  284. Xset.o: set.c 
  285. Xset.o: sys.h 
  286. Xset.o: util.h 
  287. Xset.o: cmds.h 
  288. Xset.o: main.h 
  289. Xset.o: set.h 
  290. Xset.o: defaults.h 
  291. Xset.o: copyright.h 
  292. Xtips.o: tips.c 
  293. Xtips.o: sys.h 
  294. Xtips.o: util.h 
  295. Xutil.o: util.c 
  296. Xutil.o: sys.h 
  297. Xutil.o: util.h 
  298. Xutil.o: cmds.h 
  299. Xutil.o: main.h 
  300. Xutil.o: ftp.h 
  301. Xutil.o: ftprc.h 
  302. Xutil.o: defaults.h 
  303. Xutil.o: copyright.h 
  304. END_OF_FILE
  305.   if test 6637 -ne `wc -c <'Makefile'`; then
  306.     echo shar: \"'Makefile'\" unpacked with wrong size!
  307.   fi
  308.   # end of 'Makefile'
  309. fi
  310. if test -f 'getpass.h' -a "${1}" != "-c" ; then 
  311.   echo shar: Will not clobber existing file \"'getpass.h'\"
  312. else
  313.   echo shar: Extracting \"'getpass.h'\" \(278 characters\)
  314.   sed "s/^X//" >'getpass.h' <<'END_OF_FILE'
  315. X/* Getpass.h */
  316. X
  317. X#ifndef _getpass_h_
  318. X#define _getpass_h_
  319. X
  320. X/*  $RCSfile: getpass.h,v $
  321. X *  $Revision: 14020.11 $
  322. X *  $Date: 93/05/21 05:45:36 $
  323. X */
  324. X
  325. X#define kMaxPassLen 127
  326. X
  327. Xchar *Getpass(char *prompt);
  328. Xvoid echo(FILE *fp, int on);
  329. X
  330. X#endif    /* _getpass_h_ */
  331. X
  332. X/* eof Getpass.h */
  333. END_OF_FILE
  334.   if test 278 -ne `wc -c <'getpass.h'`; then
  335.     echo shar: \"'getpass.h'\" unpacked with wrong size!
  336.   fi
  337.   # end of 'getpass.h'
  338. fi
  339. if test -f 'ncftp.1' -a "${1}" != "-c" ; then 
  340.   echo shar: Will not clobber existing file \"'ncftp.1'\"
  341. else
  342.   echo shar: Extracting \"'ncftp.1'\" \(33759 characters\)
  343.   sed "s/^X//" >'ncftp.1' <<'END_OF_FILE'
  344. X.\"-------
  345. X.\" Man page portability notes
  346. X.\"
  347. X.\" These are some notes on conventions to maintain for greatest
  348. X.\" portability of this man page to various other versions of
  349. X.\" nroff.
  350. X.\"
  351. X.\" When you want a \ to appear in the output, use \e in the man page.
  352. X.\" (NOTE this comes up in the rc grammar, where to print out '\n' the
  353. X.\" man page must contain '\en'.)
  354. X.\"
  355. X.\" Evidently not all versions of nroff allow the omission of the
  356. X.\" terminal " on a macro argument.  Thus what could be written
  357. X.\"
  358. X.\" .Cr "exec >[2] err.out
  359. X.\"
  360. X.\" in true nroffs must be written
  361. X.\"
  362. X.\" .Cr "exec >[2] err.out"
  363. X.\"
  364. X.\" instead.
  365. X.\"
  366. X.\" Use symbolic font names (e.g. R, I, B) instead of the standard
  367. X.\" font positions 1, 2, 3.  Note that for Xf to work the standard
  368. X.\" font names must be single characters.
  369. X.\"
  370. X.\" Note that sentences should end at the end of a line.  nroff and
  371. X.\" troff will supply the correct intersentence spacing, but only if
  372. X.\" the sentences end at the end of a line.  Explicit spaces, if given,
  373. X.\" are apparently honored and the normal intersentence spacing is
  374. X.\" supressed.
  375. X.\"
  376. X.\" DaviD W. Sanderson
  377. X.\"-------
  378. X.\" Dd    distance to space vertically before a "display"
  379. X.\" These are what n/troff use for interparagraph distance
  380. X.\"-------
  381. X.if t .nr Dd .4v
  382. X.if n .nr Dd 1v
  383. X.\"-------
  384. X.\" Sp    space down the interparagraph distance
  385. X.\"-------
  386. X.de Sp
  387. X.sp \\n(Ddu
  388. X..
  389. X.\"-------
  390. X.\" Ds    begin a display, indented .5 inches from the surrounding text.
  391. X.\"
  392. X.\" Note that uses of Ds and De may NOT be nested.
  393. X.\"-------
  394. X.de Ds
  395. X.Sp
  396. X.in +0.5i
  397. X.nf
  398. X..
  399. X.\"-------
  400. X.\" De    end a display (no trailing vertical spacing)
  401. X.\"-------
  402. X.de De
  403. X.fi
  404. X.in
  405. X..
  406. X.TH NcFTP 1 "" NCEMRSoft
  407. X.\"-------
  408. X.SH "NAME"
  409. X.\"-------
  410. XNcFTP \(em Internet file transfer program
  411. X.\"-------
  412. X.SH "SYNOPSIS"
  413. X.\"-------
  414. X.B ncftp
  415. X.RI [ "program options" ]
  416. X.RI [[ "open options" ]
  417. X.IR hostname [\c
  418. X.B :\c
  419. X.IR pathname ]]
  420. X.\"-------
  421. X.SH "DESCRIPTION"
  422. X.\"-------
  423. X.I NcFTP
  424. Xis a user interface to the Internet standard
  425. X.IR "File Transfer Protocol" .
  426. XThis program allows a user to transfer files to and from a remote network
  427. Xsite, and offers additional features that are not found in the standard
  428. Xinterface,
  429. X.IR ftp .
  430. X.\"-------
  431. X.SH "FEATURES"
  432. X.\"-------
  433. XProgram options will be explained later in this document.
  434. XLet's get down to business and go over the features
  435. Xthat make this program worthwhile.
  436. X.PP
  437. XHere is the list of section headers; I have my $MANPAGER environment
  438. Xvariable set to use
  439. X.RB `` "less \-i" ''
  440. Xso that I can skip to the section I
  441. Xwant (otherwise,
  442. X.BI / regex
  443. Xcommands to the pager won't match the section
  444. Xheaders because of the formatting codes;
  445. Xthe
  446. X.RB `` \-i ''
  447. Xcan search through the formatting codes)
  448. X.Ds
  449. XEstablishing the remote connection
  450. XFormat of the RC file
  451. XThe Recent-sites file
  452. XRedialing a busy remote site
  453. XSupplying a sitename from your shell's command line
  454. XUsing Colon-mode
  455. XUsing FTP-cat and FTP-more mode
  456. XSupplying a port number with the open command
  457. XDisplaying and changing program variables
  458. XProgram variables
  459. XListing a remote directory
  460. XViewing a remote directory with your pager
  461. XRedisplaying the last directory listing
  462. XFetching files from the remote host
  463. XViewing a remote file with your pager
  464. XCreating a message file on the remote host
  465. XLooking up site names and addresses
  466. XChecking the configuration of the program
  467. XUsing the command shell
  468. XCustomizing the prompt
  469. XKeeping a log of your file transfers
  470. XProgram options
  471. XA sample RC file
  472. X.De
  473. X.\"-------
  474. X.SH "Establishing the remote connection"
  475. X.\"-------
  476. XJust opening a connection to a remote server was inconvenient enough in the
  477. Xstock
  478. X.I ftp
  479. Xprogram to justify writing this program.
  480. XHere at
  481. X.IR NCEMRSoft ,
  482. Xwe want to do our business as quickly and painlessly as possible.
  483. XWe'd
  484. Xrather save time and wear and tear on our metacarpals than bother typing
  485. Xentire site names, usernames, and email addresses masquerading as passwords,
  486. Xand setting binary mode.
  487. X.PP
  488. XWe made all connections anonymous by default, and we automatically send our
  489. Xemail address for the password on those connections.
  490. XWe allowed for site
  491. Xnames to be abbreviated.
  492. X.PP
  493. XFor each commonly accessed site, you can put an entry in your program
  494. Xpreferences file (let's call it the ``ncftprc file'' or ``RC file'' for short).
  495. XTo open the site, from the command shell all you do is type:
  496. X.Ds
  497. Xopen wuarchive.wustl.edu
  498. X.De
  499. X.PP
  500. Xor
  501. X.Ds
  502. Xo wuarchive.wustl.edu
  503. X.De
  504. X.PP
  505. XAs promised, you can abbreviate that further.
  506. XJust use any abbreviation that
  507. Xwould match only the site you had in mind.
  508. XFor the previous example, you
  509. Xcould try:
  510. X.Ds
  511. Xo wuarc
  512. Xo wustl
  513. Xo stl
  514. Xo wu
  515. X.De
  516. X.PP
  517. XAny of those abbreviations would open wuarchive.wustl.edu anonymously,
  518. Xsending your anon-password (usually set to your email address) as the
  519. Xpassword.
  520. XKeep in mind that the program tries opening the first site
  521. Xthat matches the abbreviation you supplied.
  522. XSo:
  523. X.Ds
  524. Xo w
  525. X.De
  526. X.PP
  527. Xmight match a site named bowser.nintendo.jp if that site appeared before
  528. Xyour entry for wuarchive.wustl.edu.
  529. X.PP
  530. XMost of the time we open remote sites anonymously, but
  531. Xthere are times where you need to specifically open a site with an actual
  532. Xusername and password.
  533. XLet's say my partner, Phil Dietz, wants to FTP
  534. Xsomething out of my account.
  535. XPerhaps he wants to fetch the latest version
  536. Xof the source code to
  537. X.I NcFTP
  538. Xso he can optimize something or add a new feature behind my back.
  539. XSince the
  540. Xprogram opens remote sites anonymously by default (actually, you can change
  541. Xthis behavior; more on that later), he would have to specify a flag to the
  542. X.I open
  543. Xcommand so he can supply my username and password.
  544. XHe would try:
  545. X.Ds
  546. Xo \-u sphygmomanometer.unl.edu
  547. X.De
  548. X.PP
  549. Xor, more likely:
  550. X.Ds
  551. Xo \-u sph
  552. X.De
  553. X.PP
  554. XThen the program would prompt him for a username (login, whatever) and a
  555. Xpassword:
  556. X.Ds
  557. XLogin Name (pdietz): mgleason
  558. XPassword: ********
  559. X.De
  560. X.PP
  561. XIf he got it right, he could raid my stuff.
  562. XIf not, he'd probably drop
  563. Xme an email asking me to quit changing my password so often.
  564. X.PP
  565. XThere are even times where you want to FTP from your own account, like if
  566. Xyou are debugging an FTP client you wrote.
  567. XAt this prompt:
  568. X.Ds
  569. XLogin Name (mgleason):
  570. X.De
  571. X.PP
  572. XI could just hit return to tell the program that I want ``mgleason'' as my
  573. Xusername, then I would enter my password.
  574. X.\"-------
  575. X.SH "Format of the RC file"
  576. X.\"-------
  577. XThis release of the program is somewhat compatible with the stock
  578. X.I ftp
  579. Xprogram's
  580. X.B ".netrc"
  581. Xfile.
  582. XHowever, I can promise you that in the near future the program will
  583. Xuse a new format, so don't invest too much time in it.
  584. X.PP
  585. XThe RC file can be named
  586. X.RB `` ncftprc '',
  587. X.RB `` netrc '',
  588. Xor
  589. X.RB `` .ncftprc '',
  590. Xbut it is usually named
  591. X.RB `` .netrc ''
  592. Xso it can be used with the stock
  593. X.I ftp
  594. Xprogram.
  595. X.I NcFTP
  596. Xlooks in the current working directory for any of those files, and then in
  597. Xyour home directory, and after that it gives up (which is OK, because RC
  598. Xfiles aren't mandatory).
  599. X.PP
  600. XThe file usually starts with
  601. X.I #set
  602. Xand
  603. X.I #unset
  604. Xcommands that do things
  605. Xto the programs variables.
  606. XThe reason for the ``#'' is so the stock
  607. X.I ftp
  608. Xprogram will think they are comments.
  609. XYou might have this appearing as
  610. Xthe first few lines in your RC file (I'll explain later):
  611. X.Ds
  612. X#set debug 1
  613. X#set pager "less \-EMi"
  614. X#unset startup\-msg
  615. X.De
  616. X.PP
  617. XAfter those, you put in machine entries for each of your favorite sites.
  618. XLet's put in an entry for wuarchive.wustl.edu.
  619. XFirst you would put:
  620. X.Ds
  621. Xmachine wuarchive.wustl.edu
  622. X.De
  623. X.PP
  624. XThen you could put in your username, password, and account if you like:
  625. X.Ds
  626. Xuser anonymous
  627. Xpassword \-mgleason@cse.unl.edu
  628. Xaccount wuarc.does.not.use.accounts
  629. X.De
  630. X.PP
  631. XFollowing that, you would add the startup macro that is run
  632. Xeach time you connect to wuarchive.
  633. XYou must start it with this line:
  634. X.Ds
  635. Xmacdef init
  636. X.De
  637. X.PP
  638. XThen put in the commands you want to do:
  639. X.Ds
  640. Xcd /graphics/gif
  641. Xls \-lt
  642. X.De
  643. X.PP
  644. XAfter that, you end the macro with a blank line (important!).
  645. XThe finished machine entry would look like the following.
  646. XTo make the transition to the impending new format less painful,
  647. XI recommend you adhere to this format:
  648. X.ta 6m +6m
  649. X.Ds
  650. Xmachine wuarchive.wustl.edu
  651. X    user anonymous
  652. X    password \-mgleason@cse.unl.edu
  653. X    account wuarc.does.not.use.accounts
  654. X    macdef init
  655. X        cd /graphics/gif
  656. X        ls \-lt
  657. X.RI \t( "mandatory blank line to end the macro" )
  658. X.De
  659. X.PP
  660. XOf course, if all you want to do is open wuarchive anonymously, you
  661. Xneedn't bother with the ``user'', ``password'', and ``account'' lines.
  662. XYou may want to put them in if you plan on using the stock
  663. X.I ftp
  664. Xprogram, though.
  665. XTry something like this:
  666. X.ta 6m +6m
  667. X.Ds
  668. Xmachine wuarchive.wustl.edu
  669. X    macdef init
  670. X        cd /graphics/gif
  671. X        ls \-lt
  672. X.RI \t( "mandatory blank line to end the macro" )
  673. X.De
  674. X.PP
  675. XYou can tell the program to not run the startup macro if you supply
  676. X.B "\-i"
  677. Xto the
  678. X.I open
  679. Xcommand.
  680. X.PP
  681. XReally, you should only bother adding entries for sites that you want to
  682. Xrun startup macros upon connection.
  683. XThe next section explains why.
  684. X.\"-------
  685. X.SH "The Recent-sites file"
  686. X.\"-------
  687. XEach time you open a site, the program saves the name of the site and the
  688. Xlast directory you were in to the
  689. X.I recent-sites file
  690. Xwhich is named
  691. X.B ".ncrecent"
  692. Xand placed in your home directory.
  693. XThe program saves a
  694. Xpredetermined number of these sites in the file, and when it reaches the
  695. Xlimit, it discards the oldest entry so it can add a new one.
  696. X.PP
  697. XYou can just go ahead and use the name of the site you want with the
  698. X.I open
  699. Xcommand if you know it is in the
  700. X.I recent\-file
  701. X(and you can abbreviate the
  702. Xname, just like those in the RC file).
  703. XBut if you cannot remember what the
  704. Xname of the site you want, all you do is run the
  705. X.I open
  706. Xcommand with
  707. Xno site parameter:
  708. X.Ds
  709. Xopen
  710. X.De
  711. X.PP
  712. XThis will pop up a list of the sites in the
  713. X.IR "recent-file" ,
  714. Xand sites in your RC file.
  715. XAt the open prompt, just type the name (or an
  716. Xabbreviation of that name) or the number preceding the site name to open
  717. Xthat site.
  718. XAfter opening the site you wanted, the program sets the remote
  719. Xworking directory to the same one you left in the last time you called.
  720. X.PP
  721. XIf you don't like the idea of having the sites you called stored on disk,
  722. Xyou can turn this feature off using an
  723. X.I unset
  724. Xcommand, explained later.
  725. X.\"-------
  726. X.SH "Redialing a busy remote site"
  727. X.\"-------
  728. XSome remote sites limit the number of leeches, er, anonymous connections
  729. Xat a time to reduce the load on the host computer.
  730. XYou can use the
  731. X.I open
  732. Xcommand's redial feature to keep attempting connections until you get on,
  733. Xalthough that is not a very polite thing to do.
  734. XThe simplest way to do
  735. Xthis would be to just supply the
  736. X.B \-r
  737. Xoption:
  738. X.Ds
  739. Xopen \-r wuarc
  740. X.De
  741. X.PP
  742. XThere are also options you can use to tweak redial.
  743. XThe
  744. X.B \-d
  745. Xflag sets
  746. Xthe delay between dials, and the
  747. X.B \-g
  748. Xflag sets a limit on how many dials
  749. Xshould be attempting before giving up.
  750. XIf you don't supply
  751. X.B \-g
  752. Xthe program will dial a day and forever (which my Number Theory professor,
  753. XDr. Mientka, says is longer than forever and a day)
  754. Xuntil it connects successfully, or until you get sick of waiting and hit the
  755. Xinterrupt key (usually ^C).
  756. X.PP
  757. XThis example dials wuarchive every ten minutes, giving up after twenty
  758. Xattempts.
  759. XNote that the redial delay is specified in seconds:
  760. X.Ds
  761. Xopen \-r \-d 600 \-g 20 wuarc
  762. X.De
  763. X.PP
  764. XPlease be considerate when you use redialing, so you won't tax the network.
  765. XSite administrators can and do get angry when they get flooded with
  766. Xconnections.
  767. X.\"-------
  768. X.SH "Supplying a sitename from your shell's command line"
  769. X.\"-------
  770. XWhen you run the program:
  771. X.Ds
  772. Xncftp
  773. X.De
  774. X.PP
  775. Xby itself does nothing and waits for you to type commands to the program's
  776. Xown shell.
  777. XJust like the stock
  778. X.I ftp
  779. Xprogram, you can supply a site name
  780. Xon the command line:
  781. X.Ds
  782. Xncftp wuarchive.wustl.edu
  783. X.De
  784. X.PP
  785. XYou can also use abbreviations as usual:
  786. X.Ds
  787. Xncftp wuarc
  788. X.De
  789. X.PP
  790. XThis is equivalent to running the program, then issuing an
  791. X.I open
  792. Xcommand to open wuarchive.
  793. X.\"-------
  794. X.SH "Using Colon-mode"
  795. X.\"-------
  796. XThe
  797. X.I open
  798. Xcommand is not a one-trick pony.
  799. XAnother option is what I call
  800. X.IR "colon-mode" .
  801. XThis feature is used (most of the time) from your shell's
  802. Xcommand line.
  803. X.PP
  804. XIn ancient times, way back during the Disco era, you could use a program
  805. Xcalled
  806. X.I tftp
  807. Xto fetch a file using the Internet standard
  808. X.I Trivial File Transfer Protocol.
  809. XYou could use that program to do something like this
  810. Xfrom within its shell:
  811. X.Ds
  812. Xget wuarchive.wustl.edu:/graphics/gif/README
  813. X.De
  814. X.PP
  815. Xand that would call wuarchive and fetch the
  816. X.B README
  817. Xfile.
  818. X.PP
  819. XYou can use this program to do the same thing from your shell's command
  820. Xline:
  821. X.Ds
  822. Xcsh> ncftp wuarchive.wustl.edu:/graphics/gif/README
  823. Xcsh> head README
  824. X.De
  825. X.PP
  826. XThis tells your shell, in this case the ``c-shell'' to run
  827. X.IR NcFTP ,
  828. Xwhich
  829. Xwould open wuarchive, fetch
  830. X.B /graphics/gif/README
  831. Xand write the file
  832. X.B ./README
  833. Xin the current working directory, and then exits.
  834. XThis is nice if you don't
  835. Xwant to browse around the remote site, and you know exactly want you want.
  836. XIt would also come in handy in shell scripts, where you don't want to
  837. Xenter the command shell, and might not want the program to spew output.
  838. X.PP
  839. XYou can use
  840. X.I colon-mode
  841. Xto set the starting remote working directory also:
  842. X.Ds
  843. Xcsh> ncftp wuarchive.wustl.edu:/graphics/gif
  844. X.De
  845. X.PP
  846. XThis would run the program, open wuarchive, and
  847. X.I cd
  848. Xto the gif directory, then run the program's command shell so you can
  849. Xbrowse.
  850. X.PP
  851. X.I Colon-mode
  852. Xis also available from within the program's command shell.
  853. XAt a prompt you can do stuff like this:
  854. X.Ds
  855. Xncftp> open wuarchive.wustl.edu:/graphics/gif/README
  856. Xncftp> o wuarc:/graphics/gif
  857. X.De
  858. X.\"-------
  859. X.SH "Using FTP-cat and FTP-more mode"
  860. X.\"-------
  861. XThere are times where you might not want the program to write a
  862. X.I colon-mode
  863. Xfile in the current working directory, or perhaps you want to pipe the
  864. Xoutput of a remote file into something else.
  865. X.I Colon-mode
  866. Xhas options to
  867. Xdo this.
  868. XIt was inspired by the guy who wrote the
  869. X.I ftpcat
  870. Xperl script.
  871. XThe
  872. X.B \-c
  873. Xoption tells the program to write on the standard
  874. Xoutput stream.
  875. XThe
  876. X.B \-m
  877. Xoption pipes the file into your pager (like
  878. X.IR more ")"
  879. XOf course this won't work if the thing you give
  880. X.I colon-mode
  881. Xis a directory!  This example just dumps a remote file to stdout:
  882. X.Ds
  883. Xcsh> ncftp \-c wuarc:/graphics/gif/README
  884. X\&...
  885. Xcsh>
  886. X.De
  887. X.PP
  888. XThis example redirects a remote file into a different
  889. Xlocation:
  890. X.Ds
  891. Xcsh> ncftp \-c wu:/README > ~pdietz/thesis.tex
  892. X.De
  893. X.PP
  894. XThis one shows how to use a pipeline:
  895. X.Ds
  896. Xcsh> ncftp \-c wuarc:/README | tail | wc \-l
  897. X10
  898. Xcsh>
  899. X.De
  900. X.PP
  901. XThis shows how to page a remote file:
  902. X.Ds
  903. Xcsh> ncftp \-m wuarc:/graphics/gif/README
  904. X\&...
  905. Xcsh>
  906. X.De
  907. X.\"-------
  908. X.SH "Supplying a port number with the open command"
  909. X.\"-------
  910. XThis option just didn't fit anywhere else, so to finish out the open command,
  911. X.B \-p
  912. Xlets you supply a port number if you have to
  913. X.I ftp
  914. Xto a site using an nonstandard port number.
  915. XPersonally, I have yet to use this feature, but it is
  916. Xthere for compatibility with the stock
  917. X.I ftp
  918. Xprogram.
  919. X.\"-------
  920. X.SH "Displaying and changing program variables"
  921. X.\"-------
  922. XNow I'll explain the commands unique to
  923. X.IR NcFTP .
  924. XThe others should perform the
  925. Xsame as they would in the stock
  926. X.I ftp
  927. Xprogram;
  928. Xconsult the man page for it if you want those explained,
  929. Xor use the
  930. X.I help
  931. Xcommand for a brief blurb.
  932. X.PP
  933. XThe
  934. X.I show
  935. Xcommand is used to display program variables and their values.
  936. X.Ds
  937. Xshow all
  938. X.De
  939. X.PP
  940. Xor
  941. X.Ds
  942. Xshow
  943. X.De
  944. X.PP
  945. Xwould display all the variables with their values.
  946. X.Ds
  947. X.RI show " var1 var2 ... varN"
  948. X.De
  949. X.PP
  950. Xwould display each specified variable and its value.
  951. X.PP
  952. XThe
  953. X.I set
  954. Xcommand changes the value of a program variable.
  955. XIts syntax is:
  956. X.Ds
  957. X.RI set " varname value"
  958. X.De
  959. X.PP
  960. XFor Boolean or Integer variables,
  961. X.Ds
  962. X.RI set " varname"
  963. X.De
  964. X.PP
  965. Xwould set the value of the variable
  966. X.I varname
  967. Xto
  968. X.B 1
  969. X.RB ( true ).
  970. X.PP
  971. XThe
  972. X.I unset
  973. Xcommand can be used to set the variable to its default value,
  974. Xor for Boolean and Integer variables, set the value of the variable to
  975. X.B 0
  976. X.RB ( false ).
  977. XFor String variables, you can use this to set the value to an
  978. Xempty string.
  979. X.PP
  980. XYou can use any of those three commands in both the command shell,
  981. Xor in the RC file with a ``#'' prepended.
  982. X.\"-------
  983. X.SH "Program variables"
  984. X.\"-------
  985. XEach variable can be one of the following types:
  986. X.TP
  987. XBoolean:
  988. XCan be
  989. X.RB `` on ''
  990. Xor
  991. X.RB `` off ''
  992. X(you can also use
  993. X.RB `` 1 ''
  994. Xor
  995. X.RB `` 0 '').
  996. X.TP
  997. XInteger:
  998. XCan be any positive or negative number, or
  999. X.BR 0 .
  1000. X.TP
  1001. XString:
  1002. XIs a string of characters.
  1003. XIf the string needs to have a space
  1004. Xin it, make sure you surround the whole string with double quotes in a
  1005. X.I set
  1006. Xcommand.
  1007. X.PP
  1008. XVariables follow.
  1009. XSome variables are explained later in the relevant sections.
  1010. X.TP
  1011. X.IR anon\-open " (Boolean)"
  1012. XTells whether the default login mode is anonymous if
  1013. Xon, or if off, will prompt for a username/password.
  1014. XYou can always override this by using either
  1015. X.B \-a
  1016. Xor
  1017. X.B \-u
  1018. Xwith the
  1019. X.I open
  1020. Xcommand.
  1021. X.TP
  1022. X.IR anon\-password " (String)"
  1023. XSends this as the password when you login anonymously.
  1024. XBy default this is your email address.
  1025. X.TP
  1026. X.IR ansi\-escapes " (Boolean)"
  1027. XIf on, the program can use boldface, underline,
  1028. Xand inverse text.
  1029. X.TP
  1030. X.IR auto\-binary " (Boolean)"
  1031. XIf on, sets the transfer type to binary mode
  1032. Ximmediately after connection.
  1033. X.TP
  1034. X.IR debug " (Integer)"
  1035. XSets the debugging level.
  1036. X.TP
  1037. X.IR gateway\-login " (String)"
  1038. XTells which username to use when logging in to
  1039. Xyour firewall gateway host.
  1040. X.TP
  1041. X.IR gateway\-host " (String)"
  1042. XThe site which is acting as your firewall gateway,
  1043. Xor empty if you aren't using one.
  1044. X.TP
  1045. X.IR local\-dir " (String)"
  1046. XThe current local working directory.
  1047. XI like to set this from my RC file,
  1048. Xso all my files go into my download directory.
  1049. X.TP
  1050. X.IR logfile " (String)"
  1051. XThe name of your personal transfer log, or empty
  1052. Xif you aren't using a transfer log.
  1053. X.TP
  1054. X.IR logsize " (Integer)"
  1055. XThe maximum ceiling of your log file, before the program
  1056. Xremoves old entries.
  1057. X.TP
  1058. X.IR mprompt " (Boolean)"
  1059. XIf on, prompts for each remote file expanded from a
  1060. Xwildcard globbing expression.
  1061. X.TP
  1062. X.IR netrc " (String, Read-only)"
  1063. XTells you the name of the RC file in use.
  1064. X.TP
  1065. X.IR pager " (String)"
  1066. XThe pathname and flags of the program used to display
  1067. Xoutput one screenful at a time.
  1068. XThe default is the value of your $PAGER
  1069. Xenvironment variable.
  1070. X.TP
  1071. X.IR prompt " (String)"
  1072. XThe prompt specification that expands into the prompt.
  1073. X.TP
  1074. X.IR progress\-reports " (Integer)"
  1075. XWhich progress meter to use, or
  1076. X.B 0
  1077. Xif you don't want progress reports during file transfers.
  1078. XSet it to
  1079. X.B 1
  1080. Xfor a simple percentage meter;
  1081. X.B 2
  1082. Xfor a fancy bar graph indicator;
  1083. X.B 3
  1084. Xto print just the number of kilobytes transferred; or
  1085. X.B 4
  1086. Xto print one dot for each 10% transferred, if you
  1087. Xwant to avoid the use of backspaces.  Note that the program
  1088. Xmay use a different meter depending on how cooperative the
  1089. Xremote host is, and what you have the
  1090. X.I ansi\-escapes
  1091. Xvariable set to.
  1092. X.TP
  1093. X.IR recent\-list " (Boolean)"
  1094. XIf on, uses and updates the
  1095. X.I recent\-file.
  1096. X.TP
  1097. X.IR remote\-is\-unix " (Boolean)"
  1098. XSet automatically by the program upon connection,
  1099. Xyou may need to use this in a startup macro if the program guessed
  1100. Xthat a remote site was UNIX when it really is not.
  1101. X.TP
  1102. X.IR startup\-msg " (Boolean)"
  1103. XIf on, prints the opening message and tip.
  1104. X.TP
  1105. X.IR tips " (Boolean)"
  1106. XIf on, prints a tip on how to use the program better each
  1107. Xtime you run the program.
  1108. X.TP
  1109. X.IR type " (String)"
  1110. XThe name of the file transfer mode in use,
  1111. Xsuch as
  1112. X.RB `` binary ''
  1113. Xor
  1114. X.RB `` ascii ''.
  1115. X.TP
  1116. X.IR verbose " (String/Integer)"
  1117. XControls the amount of output spewed by the program.
  1118. XYou can supply either the first character of the name of the
  1119. Xverbosity level, or its number:
  1120. X.RS
  1121. X.TP
  1122. X.IR "Q" "uiet (\-1)"
  1123. XWon't print any output at all, even if an error occurs.
  1124. X.TP
  1125. X.IR "E" "rrors Only (0)"
  1126. XNo output, except when errors occur.
  1127. X.TP
  1128. X.IR "T" "erse (1)"
  1129. XPrints errors, and useful output from the remote host.
  1130. X.TP
  1131. X.IR "V" "erbose (2)"
  1132. XPrints everything, even junk output from the remote end.
  1133. X.RE
  1134. X.\"-------
  1135. X.SH "Listing a remote directory"
  1136. X.\"-------
  1137. XThe
  1138. X.I ls
  1139. Xand
  1140. X.I dir
  1141. Xcommands perform in a similar manner to those of the
  1142. Xstock
  1143. X.I ftp
  1144. Xprogram.
  1145. X.PP
  1146. XThe
  1147. X.I ls
  1148. Xcommand sends the FTP command ``NLST'' for you.
  1149. XThis command has been set so that it defaults
  1150. Xto always listing files in columns (this is the
  1151. X.B \-C
  1152. Xoption given to the UNIX
  1153. X.I ls
  1154. Xcommand) and appending
  1155. Xmetacharacters to each item name (this is the
  1156. X.B \-F
  1157. Xoption), so you can
  1158. Xsee which items are directories, files, links, etcetera.
  1159. XIf you don't want
  1160. Xyour items columnized, you can try using the
  1161. X.B \-1
  1162. Xoption with
  1163. X.I ls
  1164. Xto print one item per line.
  1165. X.PP
  1166. XThe
  1167. X.I dir
  1168. Xcommand sends the FTP command ``LIST'' for you, which instead
  1169. Xof printing just item names, it prints item sizes, owners, dates, and
  1170. Xpermissions as well.
  1171. XThis command is equivalent to
  1172. X.RB `` "ls \-l" ''
  1173. Xon most remote systems.
  1174. X.PP
  1175. XThe usage for both commands is the same.
  1176. XHere is the one for
  1177. X.IR ls :
  1178. X.PP
  1179. X.RS
  1180. X.B ls
  1181. X.RI [ \-flags ]
  1182. X.RI [ "directory and file names" ]
  1183. X.RI [ redirection ]
  1184. X.RE
  1185. X.PP
  1186. XNote that in this program, you can supply both flags and items to list in
  1187. Xthe same command.
  1188. XThe stock version of
  1189. X.I ftp
  1190. Xdoesn't let you do this:
  1191. X.Ds
  1192. Xls \-lrt /info\-mac/help
  1193. X.De
  1194. X.PP
  1195. XAnother thing that the program does which the others should have done is
  1196. Xlet you supply more than one item:
  1197. X.Ds
  1198. Xls \-lrt /info\-mac/help /pub /info\-mac/README
  1199. X.De
  1200. X.PP
  1201. XYou can also redirect the output into a file, or pipe it into something.
  1202. XThis example shows how to list the contents of the current remote directory,
  1203. Xand save the output into a file in the current local directory:
  1204. X.Ds
  1205. Xls \-t >ls.out
  1206. X.De
  1207. X.PP
  1208. XNote that for this to work, there must be no whitespace between the ``>''
  1209. Xand the filename, unlike your shell command line which allows for extra
  1210. Xwhitespace.
  1211. XThis will be (actually, is) fixed in a future version of the
  1212. Xprogram.
  1213. X.PP
  1214. XThese examples show how to use a pipe:
  1215. X.Ds
  1216. Xls \-t |tail
  1217. Xdir \-t "|less \-CM"
  1218. Xls \-t "|tail | wc"
  1219. X.De
  1220. X.PP
  1221. XLike the redirection example, there must be no whitespace between the first
  1222. Xpipe character and the rest of the stuff.
  1223. XThe trick is that it has to
  1224. Xappear as one argument to the commands.
  1225. XThe second and third examples
  1226. Xillustrate the use of double quotes to squeeze extra parameters in.
  1227. XThe second example can be done without all that typing.
  1228. XSee the descriptions of the
  1229. X.I pdir
  1230. Xand
  1231. X.I pls
  1232. Xcommands below.
  1233. X.\"-------
  1234. X.SH "Viewing a remote directory with your pager"
  1235. X.\"-------
  1236. XDidn't you hate it when you listed a remote directory, only to have most of
  1237. Xthe stuff scrolled off your terminal before you could read it?
  1238. XThe
  1239. X.I pls
  1240. Xand
  1241. X.I pdir
  1242. Xcommands take care of this for you.
  1243. XAs you might have guessed,
  1244. Xthey perform exactly like their regular counterparts,
  1245. Xonly you view them with your pager.
  1246. XThe pager to use is controlled by the
  1247. X.I pager
  1248. Xprogram variable.
  1249. X.\"-------
  1250. X.SH "Redisplaying the last directory listing"
  1251. X.\"-------
  1252. XThe program saves the listing into a local buffer,
  1253. Xso if you need to see it again (probably forgot about
  1254. X.IR pdir )
  1255. Xyou can use the
  1256. X.I redir
  1257. Xand
  1258. X.I predir
  1259. Xcommands for this.
  1260. X.\"-------
  1261. X.SH "Fetching files from the remote host"
  1262. X.\"-------
  1263. XThe
  1264. X.I get
  1265. Xand
  1266. X.I mget
  1267. Xretrieve remote files for you.
  1268. XThe usage for
  1269. X.I get
  1270. Xis:
  1271. X.Ds
  1272. Xget remote\-file [local\-file or redirection]
  1273. X.De
  1274. X.PP
  1275. XTo fetch
  1276. X.B /pub/README
  1277. Xand write it as a file named
  1278. X.BR ./junk/readme ,
  1279. Xtry:
  1280. X.Ds
  1281. Xget /pub/README ./junk/readme
  1282. X.De
  1283. X.PP
  1284. XTo fetch
  1285. X.B /pub/README
  1286. Xand write it as
  1287. X.BR ./README ,
  1288. Xjust do:
  1289. X.Ds
  1290. Xget /pub/README
  1291. X.De
  1292. X.PP
  1293. XThis lets you fetch a file using its whole pathname, and write a copy of
  1294. Xit in the current directory, without having to bother with typing a local
  1295. Xfilename.
  1296. XIn the unlikely event that you have write permission to a
  1297. Xdirectory called
  1298. X.B /pub
  1299. Xon your local machine, it would write
  1300. X.RB `` README ''
  1301. Xin that directory.
  1302. X.PP
  1303. XMost of the time the file you want will be in the current remote directory,
  1304. Xso you can just do these:
  1305. X.Ds
  1306. Xget README
  1307. Xget README ./junk/readme
  1308. X.De
  1309. X.PP
  1310. XYou can also use a redirection for
  1311. X.IR get ,
  1312. Xjust like you can with the
  1313. X.IR ls ", " dir ", and " redir
  1314. Xcommands.
  1315. XAs described earlier, you have
  1316. Xto conform to the format below for this release of the program:
  1317. X.Ds
  1318. Xget README >/dev/null
  1319. Xget README |head
  1320. Xget README "|head \-8"
  1321. Xget README "|less \-EMi"
  1322. X.De
  1323. X.PP
  1324. XThe last example is facilitated by the
  1325. X.I page
  1326. Xcommand described later.
  1327. X.PP
  1328. XThe
  1329. X.I get
  1330. Xcommand can also use a wildcard expression in an attempt to
  1331. Xmatch exactly one remote file.
  1332. XI call it ``Poor Man's File Completion.''
  1333. XIf you've done a remote listing, and you decide you want to download a
  1334. Xfile by the name of
  1335. X.RB `` obnoxiouslylongpackagename.tar.Z '',
  1336. Xyou can use
  1337. X``PMFC'' to save some keystrokes.
  1338. XChoose an expression that will only
  1339. Xmatch that one file, then use it with
  1340. X.IR get :
  1341. X.Ds
  1342. Xget obn*.Z a.tar.Z
  1343. X.De
  1344. X.PP
  1345. XIf your pattern was unique,
  1346. X.I get
  1347. Xwill fetch that file only.
  1348. XIf the pattern matched more than one file, the program will bitch and moan.
  1349. X.PP
  1350. XThe
  1351. X.I mget
  1352. Xcommand is used to fetch many files at a time.
  1353. XThe difference between
  1354. X.I get
  1355. Xand
  1356. X.I mget
  1357. Xis that
  1358. X.I get
  1359. Xlets you write only one file,
  1360. Xbut you can put it in a different directory, while
  1361. X.I mget
  1362. Xfetches many files,
  1363. Xalways writing them in the current local directory.
  1364. XThis example fetches several remote files at once:
  1365. X.Ds
  1366. Xmget a.file.Z b.file.Z c.tar d.tar.Z
  1367. X.De
  1368. X.PP
  1369. XThe
  1370. X.I mget
  1371. Xcommand, and its ugly sisters,
  1372. X.I mput
  1373. Xand
  1374. X.I mdelete
  1375. Xlet you use wildcard expressions.
  1376. XI could have done the previous example as:
  1377. X.Ds
  1378. Xmget *.Z c.tar
  1379. X.De
  1380. X.PP
  1381. Xinstead.
  1382. XThe ``m'' commands will verify each file,
  1383. Xif you have the program variable
  1384. X.I mprompt
  1385. Xset.
  1386. X.\"-------
  1387. X.SH "Viewing a remote file with your pager"
  1388. X.\"-------
  1389. XIf you would like to read a file on the remote host without saving a copy
  1390. Xof it on your machine, you can use the
  1391. X.I page
  1392. X(or
  1393. X.I more
  1394. Xif you wish) command:
  1395. X.Ds
  1396. Xpage README
  1397. Xpage obn*README
  1398. Xpage README.Z
  1399. X.De
  1400. X.PP
  1401. XThe second example show that you can use ``PMFC'' like you can for
  1402. X.IR get.
  1403. XThe third example will work also, because if the program knows how to
  1404. Xdecompress the file, it will do so before feeding it to your pager.
  1405. XAs stated earlier,
  1406. Xyou can change the program to use to page by setting the program variable
  1407. X.IR pager.
  1408. X.\"-------
  1409. X.SH "Creating a message file on the remote host"
  1410. X.\"-------
  1411. XUse the
  1412. X.I create
  1413. Xan empty file on the remote site.
  1414. XSometimes it is necessary to leave a note if you can't get in touch
  1415. Xwith the remote site's administrator.
  1416. XFor example if a file is corrupted, you could try:
  1417. X.Ds
  1418. Xcreate Foo.tar_is_corrupt
  1419. X.De
  1420. X.PP
  1421. Xin hopes that the original uploader will replace it.
  1422. X.\"-------
  1423. X.SH "Looking up site names and addresses"
  1424. X.\"-------
  1425. XYou can use the program's builtin
  1426. X.RI mini- nslookup
  1427. Xfacility.
  1428. XIf you wanted to know the site's IP number, but only knew the name you
  1429. Xcould do:
  1430. X.Ds
  1431. Xlookup cse.unl.edu
  1432. X.De
  1433. X.PP
  1434. XThis would spit out IP number for that site, in this case ``129.93.1.12''.
  1435. XIf you needed to know what a site's name was, but only knew the IP number,
  1436. Xtry:
  1437. X.Ds
  1438. Xlookup 129.93.1.12
  1439. X.De
  1440. X.PP
  1441. XThis would spit out the name for that site, in this case ``cse.unl.edu''.
  1442. X.\"-------
  1443. X.SH "Checking the configuration of the program"
  1444. X.\"-------
  1445. XUse the
  1446. X.I version
  1447. Xcommand to print version and compilation information about the program.
  1448. XThis will also tell you which optional features are
  1449. Xcompiled into the program, such as logging to the system log and which
  1450. Xcommand line editor (if any) has been installed.
  1451. X.PP
  1452. XThe author's email address is listed, and if you need to report something,
  1453. Xsend the output of this command along with your message.
  1454. X.\"-------
  1455. X.SH "Using the command shell"
  1456. X.\"-------
  1457. XJust like the stock
  1458. X.I ftp
  1459. Xprogram, you type commands to it until you get
  1460. Xbored and hit either ^D or type the
  1461. X.I quit
  1462. Xcommand.
  1463. X.PP
  1464. XThe program supports links to popular command line editing libraries.
  1465. XIf the person who compiled it went to the effort, you will be able to
  1466. Xedit the command line with arrow keys and other editing commands, and also
  1467. Xscroll up and down in the command line history, usually with the up and
  1468. Xdown arrows.
  1469. XYou can check the
  1470. X.I version
  1471. Xcommand to see if either
  1472. X``GETLINE'' or ``READLINE'' are installed.
  1473. X.\"-------
  1474. X.SH "Customizing the prompt"
  1475. X.\"-------
  1476. XYou can set the shell's prompt string to whatever you like.
  1477. XYou can use several metacharacters that expand into something each prompt.
  1478. XThe
  1479. X.RB `` % ''
  1480. Xflags are passed to
  1481. X.IR strftime (3),
  1482. Xso you can put the date or time in the prompt formatted as you like it:
  1483. X.Ds
  1484. Xset prompt "%I:%M ncftp>"
  1485. X.De
  1486. X.PP
  1487. XThat would insert the current time in the prompt.
  1488. X.PP
  1489. XThe
  1490. X.RB `` @ ''
  1491. Xflags are expanded by the program itself.
  1492. XHere's the list of them.
  1493. X.PP
  1494. XIf you have an ANSI-compatible terminal, or you have the program variable
  1495. X.I ansi\-escapes
  1496. Xset, you can use
  1497. X.BR @B ,
  1498. X.BR @I ,
  1499. Xand
  1500. X.B @U
  1501. Xto turn on boldface,
  1502. Xinverse, and underline text respectively (otherwise they won't insert
  1503. Xanything).
  1504. XYou can also use
  1505. X.B @R
  1506. Xto turn on inverse (reverse) text.
  1507. X.B @P
  1508. Xsets the text back to plain text.
  1509. X.PP
  1510. X.B @D
  1511. XInserts the full path of the current remote directory.
  1512. XThe
  1513. X.B @J
  1514. Xflag is similar except it inserts only the directory name.
  1515. X.PP
  1516. X.B @H
  1517. XInserts the name of the remote host.
  1518. X.B @C
  1519. Xinserts the host and current
  1520. Xdirectory path in
  1521. X.I "colon-mode"
  1522. Xformat, such as
  1523. X``cse.unl.edu:/pub/mgleason'', or ``(not connected)''.
  1524. XThe
  1525. X.B @c
  1526. Xflag is similar, only it will insert ``cse.unl.edu:/pub/mgleason'' and a
  1527. Xnewline if connected, otherwise it prints nothing.
  1528. XThe default prompt uses
  1529. Xthis flag to print a two line prompt when connected and a one line prompt
  1530. Xwhen not connected.
  1531. X.PP
  1532. X.BR @E " or " @!
  1533. Xinserts the event number (how many commands you've typed).
  1534. X.PP
  1535. X.B @M
  1536. Xinserts ``(Mail)\0'' if mail has arrived since running the program.
  1537. X.PP
  1538. X.B @N
  1539. Xinserts a newline character.
  1540. X.\"-------
  1541. X.SH "Keeping a log of your file transfers"
  1542. X.\"-------
  1543. XYou can have the program keep a personal log file.
  1544. XI find it is useful so I can see where I got a certain file,
  1545. Xor what the name of that site was I called two weeks ago.
  1546. X.PP
  1547. XTo use a log, add:
  1548. X.Ds
  1549. X#set logfile ~/.ftplog
  1550. X.De
  1551. X.PP
  1552. X(or whatever you want to name the log) to your RC file.
  1553. XI don't want my log growing too large and using up all my disk space,
  1554. Xso I also have:
  1555. X.Ds
  1556. X#set logsize 10240
  1557. X.De
  1558. X.PP
  1559. Xin my RC file.
  1560. XIf you set the limit on the maximum log size, the program will
  1561. Xkeep the log file at or below that size, discarding old entries.
  1562. X.PP
  1563. XNote that this is different from having SYSLOG appear in the
  1564. X.I version
  1565. Xcommand's output.
  1566. XWhen this is on, your actions are recorded to the system
  1567. Xlog, so your system administrator can make sure you aren't doing anything
  1568. X``bad.''
  1569. X.\"-------
  1570. X.SH "Program options"
  1571. X.\"-------
  1572. XRemember that you can treat the command line like an
  1573. X.I open
  1574. Xcommand,
  1575. Xso all lowercase options are passed to the
  1576. X.I open
  1577. Xcommand, and the
  1578. Xuppercase options are handled by the main program.
  1579. XThe uppercase options
  1580. Xare described below; refer to the
  1581. X.I open
  1582. Xcommand for descriptions of its options.
  1583. X.TP
  1584. X.BI \-D " x"
  1585. Xsets the debugging level to
  1586. X.IR x .
  1587. X.TP
  1588. X.B \-H
  1589. Xruns the
  1590. X.I version
  1591. Xcommand and exits, so you can save the output of
  1592. Xit to use when you need to mail me something.
  1593. X.TP
  1594. X.B \-I
  1595. Xtoggles the mprompt variable; this is provided for compatibility with
  1596. X.RB `` "ftp \-i" ''.
  1597. X.TP
  1598. X.B \-N
  1599. Xdisables reading of the RC file;
  1600. Xthis is provided for compatibility with
  1601. X.RB `` "ftp \-n" ''.
  1602. X.TP
  1603. X.BI \-V " x"
  1604. Xsets verbosity to level
  1605. X.I x
  1606. X.RB ( \-1 ,
  1607. X.BR 0 ,
  1608. X.BR 1 ,
  1609. X.BR 2 )
  1610. Xor
  1611. X.RB ( quiet ,
  1612. X.BR errs ,
  1613. X.BR terse ,
  1614. X.BR verbose ).
  1615. XSee the description of the
  1616. X.I verbose
  1617. Xprogram variable for more information.
  1618. X.PP
  1619. XHere are some example command lines.
  1620. XAgain, see the description of the
  1621. X.I open
  1622. Xcommand (especially
  1623. X.IR "colon-mode" " and " "FTP\-cat mode" ")"
  1624. Xand all its functions for more information.
  1625. X.PP
  1626. XThis just enters the
  1627. X.I NcFTP
  1628. Xcommand shell:
  1629. X.Ds
  1630. Xcsh> ncftp
  1631. X.De
  1632. X.PP
  1633. XThis fetches
  1634. X.B CONTENTS
  1635. Xand then quits:
  1636. X.Ds
  1637. Xcsh> ncftp cse.unl.edu:/pub/mgleason/CONTENTS
  1638. X.De
  1639. X.PP
  1640. XSome others examples, with open options and main program options mixed in:
  1641. X.Ds
  1642. Xcsh> ncftp \-V quiet \-u ftp.unl.edu
  1643. Xcsh> ncftp \-c cse.unl.edu:/pub/mgleason/CONTENTS
  1644. Xcsh> ncftp \-D 2 \-r \-d 120 \-g 10 \-N ftp.unl.edu
  1645. X.De
  1646. X.\"-------
  1647. X.SH "A sample RC file"
  1648. X.\"-------
  1649. XHere is a sample RC file:
  1650. X.ta 6m +6m
  1651. X.Ds
  1652. X#set logfile ~/.ftplog
  1653. X#set progress\-reports 2
  1654. X#set local\-dir /usr/tmp/zz
  1655. X#set prompt "@B@E @UNcFTP@P @B@M@D@P \->"
  1656. X.sp
  1657. Xmachine sumex\-aim.stanford.edu
  1658. X    macdef init
  1659. X        cd /info\-mac
  1660. X        get ./help/recent\-files.txt "|grep \-v '.abs' > sumex"
  1661. X        !less sumex
  1662. X        pwd
  1663. X.sp
  1664. X# This site is in here just so I can use ``apple''
  1665. X# as an abbreviation.
  1666. Xmachine ftp.apple.com
  1667. X.sp
  1668. X# NcFTP will only ask for your password:
  1669. Xmachine cse.unl.edu
  1670. X    login mgleason
  1671. X.sp
  1672. X# You can supply a login and a password:
  1673. Xmachine fake.machine.unl.edu
  1674. X    login mgleason
  1675. X    password mypass
  1676. X    macdef init
  1677. X    cd ./foo/bar
  1678. X.sp
  1679. X# If an antiquated non-UNIX machine doesn't use
  1680. X# the "SYST" command, you may need to unset
  1681. X# remote\-is\-unix, if the remote host complains
  1682. X# about ``ls \-CF''.
  1683. Xmachine some.vms.unl.edu
  1684. X    macdef init
  1685. X    unset remote\-is\-unix
  1686. X.sp
  1687. X.De
  1688. X.\"-------
  1689. X.SH "AUTHORS"
  1690. X.\"-------
  1691. X.I NcFTP
  1692. Xwas written by Mike Gleason,
  1693. X.I NCEMRSoft
  1694. X(mgleason@cse.unl.edu), and based on code by the authors of the
  1695. X.I ftp
  1696. Xfrom the BSD 4.3 distribution.
  1697. X.I NcFTP
  1698. Xis copyrighted 1992, 1993 by NCEMRSoft
  1699. Xand 1985, 1989 by the Regents of California.
  1700. X.PP
  1701. XIdeas and some code contributed by Phil Dietz,
  1702. X.I NCEMRSoft
  1703. X(pdietz@cse.unl.edu).
  1704. XTesting and debugging done by Phil and
  1705. XKok Hon Yin (hkok@cse.unl.edu).
  1706. X.PP
  1707. XExtensive man page formatting work
  1708. Xby DaviD W. Sanderson (dws@ssec.wisc.edu).
  1709. X.\"-------
  1710. X.SH "BUGS"
  1711. X.\"-------
  1712. XCorrect execution of many commands depends upon proper behavior
  1713. Xby the remote server.
  1714. X.PP
  1715. XThe remote server may drop the connection if you take a long time to
  1716. Xpage remote files.
  1717. X.PP
  1718. XTermcap padding is not correctly displayed.
  1719. X.PP
  1720. XThere are no such sites named
  1721. X.I bowser.nintendo.jp
  1722. Xor
  1723. X.IR sphygmomanometer.unl.edu .
  1724. X.\"-------
  1725. X.SH "SEE ALSO"
  1726. X.\"-------
  1727. X.IR strftime (3),
  1728. X.IR ftpd (8),
  1729. X.IR ftp (1),
  1730. X.IR nslookup (1),
  1731. X.IR compress (1),
  1732. X.IR gzip (1),
  1733. X.IR zcat (1),
  1734. X.IR fsp (1),
  1735. X.IR archie (1),
  1736. X.IR tftp (1).
  1737. END_OF_FILE
  1738.   if test 33759 -ne `wc -c <'ncftp.1'`; then
  1739.     echo shar: \"'ncftp.1'\" unpacked with wrong size!
  1740.   fi
  1741.   # end of 'ncftp.1'
  1742. fi
  1743. if test -f 'open.c' -a "${1}" != "-c" ; then 
  1744.   echo shar: Will not clobber existing file \"'open.c'\"
  1745. else
  1746.   echo shar: Extracting \"'open.c'\" \(16566 characters\)
  1747.   sed "s/^X//" >'open.c' <<'END_OF_FILE'
  1748. X/* open.c */
  1749. X
  1750. X/*  $RCSfile: open.c,v $
  1751. X *  $Revision: 1.1 $
  1752. X *  $Date: 93/07/09 11:27:07 $
  1753. X */
  1754. X
  1755. X#include "sys.h"
  1756. X
  1757. X#include <netdb.h>
  1758. X#include <netinet/in.h>
  1759. X#include <arpa/ftp.h>
  1760. X
  1761. X#include <errno.h>
  1762. X
  1763. X#include "util.h"
  1764. X#include "open.h"
  1765. X#include "cmds.h"
  1766. X#include "ftp.h"
  1767. X#include "ftprc.h"
  1768. X#include "main.h"
  1769. X#include "defaults.h"
  1770. X#include "copyright.h"
  1771. X
  1772. X/* open.c globals */
  1773. Xint                    remote_is_unix;        /* TRUE if remote host is unix. */
  1774. Xint                    auto_binary = dAUTOBINARY;
  1775. Xint                    anon_open = dANONOPEN;
  1776. X                                        /* Anonymous logins by default? */
  1777. Xint                    connected = 0;        /* TRUE if connected to server */
  1778. X                                        /* If TRUE, set binary each connection. */
  1779. XHostname            hostname;            /* Name of current host */
  1780. X#ifdef GATEWAY
  1781. Xstring                gateway;            /* node name of firewall gateway */
  1782. Xstring                gate_login;            /* login at firewall gateway */
  1783. X#endif
  1784. X
  1785. X/* open.c externs */
  1786. Xextern char                    *reply_string, *line, *Optarg, *margv[];
  1787. Xextern int                    Optind, margc, verbose, macnum;
  1788. Xextern long                    eventnumber;
  1789. Xextern struct servent        serv;
  1790. Xextern FILE                    *cout;
  1791. Xextern string                anon_password;
  1792. X
  1793. X/* Given a pointer to an OpenOptions (structure containing all variables
  1794. X * that can be set from the command line), this routine makes sure all
  1795. X * the variables have valid values by setting them to their defaults.
  1796. X */
  1797. Xvoid InitOpenOptions(OpenOptions *openopt)
  1798. X{
  1799. X    /* How do you want to open a site if neither -a or -u are given?
  1800. X     * anon_open is true (default to anonymous login), unless
  1801. X     * defaults.h was edited to set dANONOPEN to 0 instead.
  1802. X     */
  1803. X    openopt->openmode = anon_open ? openImplicitAnon : openImplicitUser;
  1804. X
  1805. X    /* Normally you don't want to ignore the entry in your netrc. */
  1806. X    openopt->ignore_rc = 0;
  1807. X
  1808. X    /* Set the default delay if the user specifies redial mode without
  1809. X     * specifying the redial delay.
  1810. X     */
  1811. X    openopt->redial_delay = dREDIALDELAY;
  1812. X
  1813. X    /* Normally, you only want to try once. If you specify redial mode,
  1814. X     * this is changed.
  1815. X     */
  1816. X    openopt->max_dials = 1;
  1817. X    
  1818. X    /* You don't want to cat the file to stdout by default. */
  1819. X    openopt->ftpcat = NO_FTPCAT;
  1820. X
  1821. X    /* Setup the port number to try. */
  1822. X#ifdef dFTP_PORT
  1823. X    /* If dFTP_PORT is defined, we use a different port number by default
  1824. X     * than the one supplied in the servent structure.
  1825. X     */
  1826. X    openopt->port = dFTP_PORT;
  1827. X    /* Make sure the correct byte order is supplied! */
  1828. X    openopt->port = htons(openopt->port);
  1829. X#else
  1830. X    /* Use the port number supplied by the operating system's servent
  1831. X     * structure.
  1832. X     */
  1833. X    openopt->port = serv.s_port;
  1834. X#endif
  1835. X
  1836. X    /* We are not in colon-mode (yet). */
  1837. X    openopt->colonmodepath[0] = 0;
  1838. X
  1839. X    /* Set the hostname to a null string, since there is no default host. */
  1840. X    openopt->hostname[0] = 0;
  1841. X    
  1842. X    /* Set the opening directory path to a null string. */
  1843. X    openopt->cdpath[0] = 0;
  1844. X}    /* InitOpenOptions */
  1845. X
  1846. X
  1847. X
  1848. X
  1849. X/* This is responsible for parsing the command line and setting variables
  1850. X * in the OpenOptions structure according to the user's flags.
  1851. X */
  1852. X
  1853. Xint GetOpenOptions(int argc, char **argv, OpenOptions *openopt)
  1854. X{
  1855. X    int                    opt;
  1856. X    char                *cp;
  1857. X
  1858. X    /* First setup the openopt variables. */
  1859. X    InitOpenOptions(openopt);
  1860. X
  1861. X    /* Tell Getopt() that we want to start over with a new command. */
  1862. X    Getopt_Reset();
  1863. X    while ((opt = Getopt(argc, argv, "aiup:rd:g:cm")) >= 0) {
  1864. X        switch (opt) {        
  1865. X            case 'a':
  1866. X                /* User wants to open anonymously. */
  1867. X                openopt->openmode = openExplicitAnon;
  1868. X                break;
  1869. X                
  1870. X            case 'u':
  1871. X                /* User wants to open with a login and password. */
  1872. X                openopt->openmode = openExplicitUser;
  1873. X                break;
  1874. X                
  1875. X            case 'i':
  1876. X                /* User wants to ignore the entry in the netrc. */
  1877. X                openopt->ignore_rc = 1;
  1878. X                break;
  1879. X                
  1880. X            case 'p':
  1881. X                /* User supplied a port number different from the default
  1882. X                 * ftp port.
  1883. X                 */
  1884. X                openopt->port = atoi(Optarg);
  1885. X                if (openopt->port <= 0) {
  1886. X                    /* Probably never happen, but just in case. */
  1887. X                    (void) printf("%s: bad port number (%s).\n", argv[0], Optarg);
  1888. X                    goto usage;
  1889. X                }
  1890. X                /* Must ensure that the port is in the correct byte order! */
  1891. X                openopt->port = htons(openopt->port);
  1892. X                break;
  1893. X                
  1894. X            case 'd':
  1895. X                /* User supplied a delay (in seconds) that differs from
  1896. X                 * the default.
  1897. X                 */
  1898. X                openopt->redial_delay = atoi(Optarg);
  1899. X                break;
  1900. X                
  1901. X            case 'g':
  1902. X                /* User supplied an upper-bound on the number of redials
  1903. X                 * to try.
  1904. X                 */
  1905. X                openopt->max_dials = atoi(Optarg);
  1906. X                break;
  1907. X
  1908. X            case 'r':
  1909. X                openopt->max_dials = -1;
  1910. X                break;
  1911. X
  1912. X            case 'm':
  1913. X                /* ftpcat mode is only available from your shell command-line,
  1914. X                 * not from the ncftp shell.  Do that yourself with 'more zz'.
  1915. X                 */
  1916. X                if (eventnumber == 0L) {
  1917. X                    /* If eventnumber is zero, then we were called directly
  1918. X                     * from main(), and before the ftp shell has started.
  1919. X                     */
  1920. X                    openopt->ftpcat = FTPMORE;
  1921. X                    /* ftpcat mode is really ftpmore mode. */
  1922. X                    break;
  1923. X                } else {
  1924. X                    fprintf(stderr,
  1925. X"You can only use this form of colon-mode (-m) from your shell command line.\n\
  1926. XTry 'ncftp -m wuarchive.wustl.edu:/README'\n");
  1927. X                    goto usage;
  1928. X                }
  1929. X                break;
  1930. X
  1931. X            case 'c':
  1932. X                /* ftpcat mode is only available from your shell command-line,
  1933. X                 * not from the ncftp shell.  Do that yourself with 'get zz -'.
  1934. X                 */
  1935. X                if (eventnumber == 0L) {
  1936. X                    /* If eventnumber is zero, then we were called directly
  1937. X                     * from main(), and before the ftp shell has started.
  1938. X                     */
  1939. X                    openopt->ftpcat = FTPCAT;
  1940. X                    break;
  1941. X                } else {
  1942. X                    fprintf(stderr,
  1943. X"You can only use ftpcat/colon-mode from your shell command line.\n\
  1944. XTry 'ncftp -c wuarchive.wustl.edu:/README > file.'\n");
  1945. X                    goto usage;
  1946. X                }
  1947. X                break;
  1948. X                
  1949. X            default:
  1950. X            usage:
  1951. X                return USAGE;
  1952. X        }
  1953. X    }
  1954. X
  1955. X    if (argv[Optind] == NULL) {
  1956. X        /* No host was supplied.  Print out the list of sites we know
  1957. X         * about and ask the user for one.
  1958. X         */
  1959. X        PrintSiteList();
  1960. X        (void) Gets("(site to open) ", openopt->hostname, sizeof(openopt->hostname));
  1961. X        /* Make sure the user just didn't hit return, in which case we
  1962. X         * just give up and go home.
  1963. X         */
  1964. X        if (openopt->hostname[0] == 0)
  1965. X            goto usage;
  1966. X    } else {
  1967. X        /* The user gave us a host to open.
  1968. X         *
  1969. X         * First, check to see if they gave us a colon-mode path
  1970. X         * along with the hostname.
  1971. X         */
  1972. X        if ((cp = index(argv[Optind], ':')) != NULL) {
  1973. X            *cp++ = 0;
  1974. X            (void) Strncpy(openopt->colonmodepath, cp);
  1975. X        }    
  1976. X        (void) Strncpy(openopt->hostname, argv[Optind]);
  1977. X    }
  1978. X    return NOERR;
  1979. X}    /* GetOpenOptions */
  1980. X
  1981. X
  1982. X
  1983. X
  1984. X/* This examines the format of the string stored in the hostname
  1985. X * field of the OpenOptions, and sees if has to strip out a colon-mode
  1986. X * pathname (to store in the colonmodepath field).  Since colon-mode
  1987. X * is run quietly (without any output being generated), we init the
  1988. X * login_verbosity variable here to quiet if we are running colon-mode.
  1989. X */
  1990. Xint CheckForColonMode(OpenOptions *openopt, int *login_verbosity)
  1991. X{
  1992. X    /* Usually the user doesn't supply hostname in colon-mode format,
  1993. X     * and wants to interactively browse the remote host, so set the
  1994. X     * login_verbosity to whatever it is set to now.
  1995. X     */
  1996. X    *login_verbosity = verbose;
  1997. X
  1998. X    if (openopt->colonmodepath[0] != 0) {
  1999. X        /* But if the user does use colon-mode, we want to do our business
  2000. X         * and leave, without all the login messages, etc., so set
  2001. X         * login_verbosity to quiet so we won't print anything until
  2002. X         * we finish.  Colon-mode can be specified from the shell command
  2003. X         * line, so we would like to be able to execute ncftp as a one
  2004. X         * line command from the shell without spewing gobs of output.
  2005. X         */
  2006. X        *login_verbosity = V_QUIET;
  2007. X    } else if (openopt->ftpcat != 0) {
  2008. X        /* User specified ftpcat mode, but didn't supply the host:file. */
  2009. X        (void) fprintf(stderr, "You didn't use colon mode correctly.\n\
  2010. XIf you use -c or -m, you need to do something like this:\n\
  2011. X    ncftp -c wuarchive.wustl.edu:/pub/README (to cat this file to stdout).\n");
  2012. X        return USAGE;
  2013. X    }
  2014. X    return NOERR;
  2015. X}    /* CheckForColonMode */
  2016. X
  2017. X
  2018. X
  2019. X
  2020. X/* All this short routine does is to hookup a socket to either the
  2021. X * remote host or the firewall gateway host.
  2022. X */
  2023. Xint HookupToRemote(OpenOptions *openopt)
  2024. X{
  2025. X    int hErr;
  2026. X
  2027. X#ifdef GATEWAY
  2028. X    /* Try connecting to the gateway host. */
  2029. X    if (*gateway) {
  2030. X        hErr = hookup(gateway, openopt->port);
  2031. X        (void) Strncpy(hostname, openopt->hostname);
  2032. X    } else
  2033. X#endif
  2034. X        hErr = hookup(openopt->hostname, openopt->port);
  2035. X    
  2036. X    return hErr;
  2037. X}    /* HookupToRemote */
  2038. X
  2039. X
  2040. X
  2041. X
  2042. Xvoid CheckRemoteSystemType(int force_binary)
  2043. X{
  2044. X    int tmpverbose;
  2045. X    char *cp, c;
  2046. X
  2047. X    /* As of this writing, UNIX is pretty much standard. */
  2048. X    remote_is_unix = 1;
  2049. X
  2050. X    /* Do a SYSTem command quietly. */
  2051. X    tmpverbose = verbose;
  2052. X    verbose = V_QUIET;
  2053. X    if (command("SYST") == COMPLETE) {
  2054. X        if (tmpverbose == V_VERBOSE) {        
  2055. X            /* Find the system type embedded in the reply_string,
  2056. X             * and separate it from the rest of the junk.
  2057. X             */
  2058. X            cp = index(reply_string+4, ' ');
  2059. X            if (cp == NULL)
  2060. X                cp = index(reply_string+4, '\r');
  2061. X            if (cp) {
  2062. X                if (cp[-1] == '.')
  2063. X                    cp--;
  2064. X                c = *cp;
  2065. X                *cp = '\0';
  2066. X            }
  2067. X
  2068. X            (void) printf("Remote system type is %s.\n",
  2069. X                reply_string+4);
  2070. X            if (cp)
  2071. X                *cp = c;
  2072. X        }
  2073. X        remote_is_unix = !strncmp(reply_string + 4, "UNIX", (size_t) 4);
  2074. X    }
  2075. X
  2076. X    /* Set to binary mode if any of the following are true:
  2077. X     * (a) The user has auto-binary set;
  2078. X     * (b) The user is using colon-mode (force_binary);
  2079. X     * (c) The reply-string from SYST said it was UNIX with 8-bit chars.
  2080. X     */
  2081. X    if (auto_binary || force_binary
  2082. X        || !strncmp(reply_string, "215 UNIX Type: L8", (size_t) 17)) {
  2083. X        (void) _settype("binary");
  2084. X        if (tmpverbose > V_TERSE)
  2085. X            (void) printf("Using binary mode to transfer files.\n");
  2086. X    }
  2087. X
  2088. X    /* Print a warning for that (extremely) rare Tenex machine. */
  2089. X    if (tmpverbose >= V_ERRS && 
  2090. X        !strncmp(reply_string, "215 TOPS20", (size_t) 10)) {
  2091. X        (void) _settype("tenex");
  2092. X        (void) printf("Using tenex mode to transfer files.\n");
  2093. X    }
  2094. X    verbose = tmpverbose;
  2095. X}    /* CheckRemoteSystemType */
  2096. X
  2097. X
  2098. X
  2099. X/* This is called if the user opened the host with a file appended to
  2100. X * the host's name, like "wuarchive.wustl.edu:/pub/readme," or
  2101. X * "wuarchive.wustl.edu:/pub."  In the former case, we open wuarchive,
  2102. X * and fetch "readme."  In the latter case, we open wuarchive, then set
  2103. X * the current remote directory to "/pub."  If we are fetching a file,
  2104. X * we can do some other tricks if "ftpcat mode" is enabled.  This mode
  2105. X * must be selected from your shell's command line, and this allows you
  2106. X * to use the program as a one-liner to pipe a remote file into something,
  2107. X * like "ncftp -c wu:/pub/README | wc."  If the user uses ftpcat mode,
  2108. X * the program immediately quits instead of going into it's own command
  2109. X * shell.
  2110. X */
  2111. Xvoid ColonMode(OpenOptions *openopt)
  2112. X{
  2113. X    int tmpverbose;
  2114. X
  2115. X    /* How do we tell if colonmodepath is a file or a directory?
  2116. X     * We first try cd'ing to the path first.  If we can, then it
  2117. X     * was a directory.  If we could not, we'll assume it was a file.
  2118. X     */
  2119. X
  2120. X    /* Shut up, so cd won't print 'foobar: Not a directory.' */
  2121. X    tmpverbose = verbose;
  2122. X    verbose = V_QUIET;
  2123. X
  2124. X    /* If we are using ftpcat|more mode, or we couldn't cd to the
  2125. X     * colon-mode path (then it must be a file to fetch), then
  2126. X     * we need to fetch a file.
  2127. X     */
  2128. X    if (openopt->ftpcat || ! _cd(openopt->colonmodepath)) {
  2129. X        /* We call the appropriate fetching routine, so we have to
  2130. X         * have the argc and argv set up correctly.  To do this,
  2131. X         * we just make an entire command line, then let makeargv()
  2132. X         * convert it to argv/argc.
  2133. X         */
  2134. X        if (openopt->ftpcat == FTPCAT)
  2135. X            (void) sprintf(line, "get %s -", openopt->colonmodepath);
  2136. X        else if (openopt->ftpcat == FTPMORE)
  2137. X            (void) sprintf(line, "more %s", openopt->colonmodepath);
  2138. X        else {
  2139. X            /* Regular colon-mode, where we fetch the file, putting the
  2140. X             * copy in the current local directory.
  2141. X             */
  2142. X            (void) sprintf(line, "mget %s", openopt->colonmodepath);
  2143. X        }
  2144. X        makeargv();
  2145. X
  2146. X        /* Turn on messaging if we aren't catting. */
  2147. X        if (openopt->ftpcat == 0)
  2148. X            verbose = tmpverbose;
  2149. X        
  2150. X        /* get() also handles 'more'. */
  2151. X        if (openopt->ftpcat)
  2152. X            (void) get(margc, margv);
  2153. X        else
  2154. X            (void) mget(margc, margv);
  2155. X
  2156. X        /* If we were invoked from the command line, quit
  2157. X         * after we got this file.
  2158. X         */
  2159. X        if (eventnumber == 0L) {
  2160. X            (void) quit(0, NULL);
  2161. X        }
  2162. X    }
  2163. X    verbose = tmpverbose;
  2164. X}    /* ColonMode */
  2165. X
  2166. X
  2167. X
  2168. X
  2169. X/* Given a properly set up OpenOptions, we try connecting to the site,
  2170. X * redialing if necessary, and do some initialization steps so the user
  2171. X * can send commands.
  2172. X */
  2173. Xint Open(OpenOptions *openopt)
  2174. X{
  2175. X    int                    hErr;
  2176. X    int                    dials;
  2177. X    char                *ruser, *rpass, *racct;
  2178. X    int                    siteInRC;
  2179. X    char                *user, *pass, *acct;    
  2180. X    int                    login_verbosity, oldv;
  2181. X
  2182. X    macnum = 0;     /* Reset macros. */
  2183. X
  2184. X    /* If the hostname supplied is in the form host.name.str:/path/file,
  2185. X     * then colon mode was used, and we need to fix the hostname to be
  2186. X     * just the hostname, copy the /path/file to colonmode path, and init
  2187. X     * the login_verbosity variable.
  2188. X     */
  2189. X    if (CheckForColonMode(openopt, &login_verbosity) == USAGE)
  2190. X        return USAGE;
  2191. X
  2192. X    /* If the hostname supplied was an abbreviation, such as just
  2193. X     * "wu" (wuarchive.wustl.edu), look through the list of sites
  2194. X     * we know about and get the whole name.  We also would like
  2195. X     * the path we want to start out in, if it is available.
  2196. X     */
  2197. X    GetFullSiteName(openopt->hostname, openopt->cdpath);
  2198. X
  2199. X#ifdef GATEWAY
  2200. X    /* Make sure the gateway host name is a full name and not an
  2201. X     * abbreviation.
  2202. X     */
  2203. X    if (*gateway)
  2204. X        GetFullSiteName(gateway, NULL);
  2205. X#endif
  2206. X
  2207. X    ruser = rpass = racct = NULL;
  2208. X    /* This also loads the init macro. */
  2209. X    siteInRC = ruserpass2(openopt->hostname, &ruser, &rpass, &racct);
  2210. X    if (ISANONOPEN(openopt->openmode)) {
  2211. X        user = "anonymous";
  2212. X        pass = anon_password;
  2213. X    } else {
  2214. X        user = NULL;
  2215. X        pass = NULL;
  2216. X    }
  2217. X    acct = NULL;
  2218. X    
  2219. X    if (siteInRC && !openopt->ignore_rc) {
  2220. X        acct = racct;
  2221. X        if (ruser != NULL) {
  2222. X            /* We were given a username.  If we were given explicit
  2223. X             * instructions from the command line, follow those and
  2224. X             * ignore what the RC had.  Otherwise if no -a or -u
  2225. X             * was specified, we use whatever was in the RC.
  2226. X             */
  2227. X            if (ISIMPLICITOPEN(openopt->openmode)) {
  2228. X                user = ruser;
  2229. X                pass = rpass;
  2230. X            }
  2231. X        }        
  2232. X    }
  2233. X
  2234. X    for (
  2235. X            dials = 0;
  2236. X            openopt->max_dials < 0 || dials < openopt->max_dials;
  2237. X            dials++)
  2238. X    {
  2239. X        if (dials > 0) {
  2240. X            /* If this is the second dial or higher, sleep a bit. */
  2241. X            (void) sleep(openopt->redial_delay);
  2242. X            (void) fprintf(stderr, "Retry Number: %d\n", dials + 1);
  2243. X        }
  2244. X
  2245. X        if ((hErr = HookupToRemote(openopt)) == -2)    
  2246. X            /* Recoverable, so we can try re-dialing. */
  2247. X            continue;
  2248. X        else if (hErr == NOERR) {
  2249. X            /* We were hookup'd successfully. */
  2250. X            connected = 1;
  2251. X
  2252. X        oldv = verbose;  verbose = login_verbosity;
  2253. X        
  2254. X#ifdef GATEWAY
  2255. X            if (*gateway) {
  2256. X                if ((Login(
  2257. X                    user,
  2258. X                    pass,
  2259. X                    acct,
  2260. X                    (!openopt->ignore_rc && !openopt->colonmodepath[0])
  2261. X                ) != NOERR) || cout == NULL)
  2262. X                    goto nextdial;        /* error! */
  2263. X            }
  2264. X#endif
  2265. X
  2266. X#ifdef GATEWAY
  2267. X            if (!*gateway) {
  2268. X#endif
  2269. X                /* We don't want to run the init macro for colon-mode. */
  2270. X                if ((Login(
  2271. X                        user,
  2272. X                        pass,
  2273. X                        acct,
  2274. X                        (!openopt->ignore_rc && !openopt->colonmodepath[0])
  2275. X                    ) != NOERR) || cout == NULL)
  2276. X                {
  2277. X                    goto nextdial;        /* error! */
  2278. X                }
  2279. X#ifdef GATEWAY
  2280. X            }
  2281. X#endif
  2282. X
  2283. X            verbose = oldv;
  2284. X
  2285. X            /* We need to check for unix and see if we should set binary
  2286. X             * mode automatically.
  2287. X             */
  2288. X            CheckRemoteSystemType(openopt->colonmodepath[0] != (char)0);
  2289. X
  2290. X            if (openopt->colonmodepath[0]) {
  2291. X                ColonMode(openopt);
  2292. X            } else if (openopt->cdpath[0]) {
  2293. X                /* If we didn't have a colon-mode path, we try setting
  2294. X                 * the current remote directory to cdpath.  cdpath is
  2295. X                 * usually the last directory we were in the previous
  2296. X                 * time we called this site.
  2297. X                 */
  2298. X                (void) _cd(openopt->cdpath);
  2299. X            } else {
  2300. X                /* Freshen 'cwd' variable for the prompt. 
  2301. X                 * We have to do atleast one 'cd' so our variable
  2302. X                 * cwd (which is saved by _cd()) is set to something
  2303. X                 * valid.
  2304. X                 */
  2305. X                (void) _cd(NULL);
  2306. X            }
  2307. X            break;    /* we are connected, so break the redial loop. */
  2308. X            /* end if we are connected */
  2309. X        } else {
  2310. X            /* Irrecoverable error, so don't bother redialing. */
  2311. X            /* The error message should have already been printed
  2312. X             * from Hookup().
  2313. X             */
  2314. X            break;
  2315. X        }
  2316. Xnextdial: continue;    /* Try re-dialing. */
  2317. X    }
  2318. X    return (NOERR);
  2319. X}    /* Open */
  2320. X
  2321. X
  2322. X
  2323. X/* This stub is called by our command parser. */
  2324. Xint cmdOpen(int argc, char **argv)
  2325. X{
  2326. X    OpenOptions            openopt;
  2327. X
  2328. X    /* If there is already a site open, close that one so we can
  2329. X     * open a new one.
  2330. X     */
  2331. X    if (connected && NOT_VQUIET && hostname[0]) {
  2332. X        (void) printf("Closing %s...\n", hostname);
  2333. X        (void) disconnect(0, NULL);
  2334. X    }
  2335. X
  2336. X    if ((GetOpenOptions(argc, argv, &openopt) == USAGE) ||
  2337. X        (Open(&openopt) == USAGE))
  2338. X        return USAGE;
  2339. X    return NOERR;
  2340. X}    /* cmdOpen */
  2341. X
  2342. X/* eof open.c */
  2343. END_OF_FILE
  2344.   if test 16566 -ne `wc -c <'open.c'`; then
  2345.     echo shar: \"'open.c'\" unpacked with wrong size!
  2346.   fi
  2347.   # end of 'open.c'
  2348. fi
  2349. echo shar: End of archive 3 \(of 6\).
  2350. cp /dev/null ark3isdone
  2351. MISSING=""
  2352. for I in 1 2 3 4 5 6 ; do
  2353.     if test ! -f ark${I}isdone ; then
  2354.     MISSING="${MISSING} ${I}"
  2355.     fi
  2356. done
  2357. if test "${MISSING}" = "" ; then
  2358.     echo You have unpacked all 6 archives.
  2359.     rm -f ark[1-9]isdone
  2360. else
  2361.     echo You still must unpack the following archives:
  2362.     echo "        " ${MISSING}
  2363. fi
  2364. exit 0
  2365. exit 0 # Just in case...
  2366.