Browse files

Initial commit

  • Loading branch information...
0 parents commit 4dce2ffb8572d575abbf9e1a5dc652c00ebb822d @codebrainz committed Dec 6, 2010
114 CHANGES
@@ -0,0 +1,114 @@
+The obligatory revision history...
+
+Changes from .... (V3.1) to 12/5/2010 (V3.1.2)
+
+1) Removed Microsoft build stuff and created a simple Makefile.
+2) Removed legacy README files, renamed others.
+3) Removed getopt.c and getopt.h.
+4) No base code changes made.
+
+------------------------------------------------------------------------
+
+Changes from 12/2/97 (V3) to .... (V3.1)
+
+1) Added FtpPwd(), FtpSysType(), FtpCDUp(), FtpSize() and FtpModDate().
+
+2) Fixed bug in FtpClose() - It wasn't waiting for the '226 Transfer
+Complete' since it didn't have access to the control connection. A
+pointer to it is now kept in the data connection.
+
+3) Fixed bug in FtpClose() - The data connection wasn't being freed. This
+could have resulted in memory leaks.
+
+4) Allow runtime selection of connection mode (PORT/PASV) with default set
+at compile time.
+
+5) Added support for a user callback routine which can get called after a
+user specified number of bytes are transferred or after waiting for data
+on a socket for a user specified time period.
+
+6) Add FtpOptions() which allows changing connection options. Options
+include connection mode, callback routine, and parameters regarding when
+the user's callback routine gets called.
+
+7) Added checks to make sure strcpy()/sprintf()/etc. wouldn't write past
+end of buffers.
+
+8) Modified build procedure to create a shared library.
+
+9) Added install option to makefile which installs under /usr/local.
+
+10) Modified qftp to use new interface.
+
+11) Modified qftp to log progress every 10% of file or every time data
+is delayd by 1 second if -v setting is not zero.
+
+12) Modified qftp to use fgets() instead of gets().
+
+------------------------------------------------------------------------
+
+Changes from 3/15/97 to 12/2/97
+
+1) FtpLastResponse() returns NULL if passed a NULL pointer.
+
+2) Added 'const' keyword on appropriate function arguments.
+
+3) First attempt to translate passed host string as an IP address in dot
+ notation by passing it to inet_addr(). If this fails, pass the string
+ to gethostbyname(). Apparently, some versions of gethostbyname() will
+ parse the translation of a dot notation address for you. One user
+ reports he knows of at least one that does not. In any case, it's the
+ right thing to do.
+
+4) Added protection from double inclusion to header file. Also added
+ 'extern "C"' for C++.
+
+5) Made sure qftp was passed two arguments before examining the second
+ one.
+
+6) Made sure all commands to the server were in upper case. I've been
+ told that some servers require this.
+
+7) Attempt to handle login to accounts with no passwords.
+
+8) Added common data transfer routines so that ascii mode transfers would
+ be handled properly in all cases. Also, exposed these routines for
+ user programs to call. There's now FtpAccess() to open a remote file
+ or directory, FtpRead() and FtpWrite() to pass data, and FtpClose() to
+ terminate the data connection.
+
+9) Added 'list' command to qftp to perform a terse directory (names
+ only). This could be piped into another copy of qftp to retrieve the
+ files.
+
+10) ftplib.c and ftplib.h are now covered by the LGPL instead of the GPL.
+ Feel free to send me a complementary copy of anything you develop
+ commercially with my libraries. All other programs are still covered
+ by the GPL.
+
+11) Added ability to specify a different port number than the default by
+ appending a colon and the desired port number to the remote host name
+ (e.g., remote.host.name:500 would connect to port remote.host.name on
+ port 500).
+
+------------------------------------------------------------------------
+
+Changes from 8/31/96 version to 3/15/97 version
+
+1) Added copyright information to sources.
+
+2) Changed from 'port' to 'pasv' which I'm told will allow the routines
+ to work from behind a firewall. It's also a lot simpler and cleaner
+ than all that code to setup and accept a connect from the server.
+
+3) Added delete (ftprm) support to qftp.c.
+
+4) Modified qftp to allow use without a softlink by passing the ftp
+ command as the first argument.
+
+5) Added netbuf argument to all calls to eliminate static storage and
+ allow multiple simultaneous connections.
+
+6) Renamed routines from ftp*() to Ftp*() to avoid problems with existing
+ programs. Added macros in libftp.h to support old interface. Renamed
+ ftpOpen() to FtpConnect().
65 INSTALL
@@ -0,0 +1,65 @@
+FTPLIB INSTALLATION INSTRUCTIONS
+=================================
+
+The compiling and installation is using a simple Makefile and should be
+fairly comfortable for anyone who's used make before. The most basic usage
+would be:
+
+ make && sudo make install
+
+You can use the PREFIX variable to specify where you want to install/remove
+the library and associated files from (ie. /usr, /usr/local, /opt, etc). The
+default prefix is /usr.
+
+--------------------------------------------------------------------------------
+
+To compile the project:
+
+ make
+
+ or
+
+ make PREFIX=/usr # whichever prefix to use
+
+--------------------------------------------------------------------------------
+
+To install the project:
+
+ make install # as root
+
+ or
+
+ make install PREFIX=/usr # possibly as root depending on PREFIX
+
+--------------------------------------------------------------------------------
+
+To uninstall the project:
+
+ make uninstall # as root
+
+ or
+
+ make uninstall PREFIX=/usr # possibly as root depending on PREFIX
+
+--------------------------------------------------------------------------------
+
+The Makefile will install the following files:
+
+ PREFIX/lib/libftp.a
+ The static library
+
+ PREFIX/lib/libftp.so.*
+ The shared library and symlinks
+
+ PREFIX/lib/pkgconfig/ftplib.pc
+ The pkg-config file
+
+ PREFIX/include/ftplib.h
+ The header file
+
+ PREFIX/share/doc/ftplib/*
+ The HTML documentation and other documentation (README, etc)
+
+ PREFIX/bin/qftp
+ The command-line client/test program
+
60 Makefile
@@ -0,0 +1,60 @@
+#
+# Linux makefile for ftplib
+#
+
+PREFIX = /usr
+CFLAGS = -g -Wall
+
+all: libftp.a libftp.so.3.1.2 qftp ftplib.pc
+
+libftp.a: ftplib.o
+ ar rcs libftp.a ftplib.o
+
+libftp.so.3.1.2: ftplib.os
+ gcc $(CFLAGS) -shared -Wl,-soname,libftp.so.3 -o libftp.so.3.1.2 ftplib.os
+
+ftplib.o: ftplib.c
+ gcc $(CFLAGS) -c ftplib.c -o ftplib.o
+
+ftplib.os: ftplib.c
+ gcc $(CFLAGS) -c -fPIC ftplib.c -o ftplib.os
+
+qftp: qftp.c
+ gcc $(CFLAGS) -o qftp qftp.c -L. -lftp
+
+ftplib.pc:
+ @echo "prefix=$(PREFIX)" > ftplib.pc
+ @echo "exec_prefix=$(PREFIX)" >> ftplib.pc
+ @echo "includedir=$(PREFIX)/include" >> ftplib.pc
+ @echo "libdir=$(PREFIX)/lib" >> ftplib.pc
+ @echo "" >> ftplib.pc
+ @echo "Name: ftplib" >> ftplib.pc
+ @echo -n "Description: " >> ftplib.pc
+ @echo -n "ftplib is a set of routines that implement " >> ftplib.pc
+ @echo "the FTP protocol." >> ftplib.pc
+ @echo "Version: 3.1.2" >> ftplib.pc
+ @echo "Cflags: -I$(PREFIX)/include" >> ftplib.pc
+ @echo "Libs: -L$(PREFIX)/lib -lftp" >> ftplib.pc
+ @echo "" >> ftplib.pc
+
+install:
+ install -m 0644 ftplib.h $(PREFIX)/include
+ install -m 0644 ftplib.pc $(PREFIX)/lib/pkgconfig
+ install -m 0644 libftp.a $(PREFIX)/lib
+ install -m 0644 libftp.so.3.1.2 $(PREFIX)/lib
+ ln -sf $(PREFIX)/lib/libftp.so.3.1.2 $(PREFIX)/lib/libftp.so.3
+ ln -sf $(PREFIX)/lib/libftp.so.3.1.2 $(PREFIX)/lib/libftp.so
+ install -m 0755 qftp $(PREFIX)/bin
+ mkdir -p $(PREFIX)/share/doc/ftplib
+ cp -r html $(PREFIX)/share/doc/ftplib
+ cp README* RFC959.txt CHANGES $(PREFIX)/share/doc/ftplib
+
+uninstall:
+ rm -f $(PREFIX)/include/ftplib.h
+ rm -f $(PREFIX)/lib/pkgconfig/ftplib.pc
+ rm -f $(PREFIX)/lib/libftp.{a,so,so.3,so.3.1.2}
+ rm -f $(PREFIX)/bin/qftp
+ rm -r $(PREFIX)/share/doc/ftplib
+
+clean:
+ rm -f ftplib.o ftplib.os libftp.a libftp.so* qftp ftplib.pc
182 README
@@ -0,0 +1,182 @@
+FTP Library Routines Release 3.1
+Thomas Pfau (pfau@cnj.digex.net)
+June 23, 1998
+
+This package implements a callable interface to FTP. The FTP protocol is
+specified in RFC 959. The library has been tested on linux, OpenVMS and
+Windows NT. It should also work without major modification on other
+POSIX systems.
+
+All programs using the library should include ftplib.h.
+
+The routines look at the global variable ftplib_debug to determine how
+much information they should display. Level 1 has been left for user
+programs. Level 2 displays all responses received from the server.
+Level 3 displays all commands sent to the server.
+
+Along with some bug fixes, version 3 also includes support for user
+access to data connections. FtpAccess() allows a user program to open a
+remote file or directory. FtpRead() and FtpWrite() can then be used to
+transfer data. These functions perform the necessary conversions for
+ascii mode transfers if necessary. FtpClose() is used to close this
+connection.
+
+---
+
+The following routines are implemented:
+
+void FtpInit(void);
+
+This routine should be called prior to any other routines. On most
+operating systems, it is a no-op but some others don't implement TCP/IP
+as seamlessly as others (Windows NT).
+
+int FtpConnect(const char *host, netbuf **nControl);
+
+Establishes a connection to the named host. The host name should be
+specified as <host> or <host>:<port> where <host> is a host name or ip
+address and <port> is a service name or port number. The handle for the
+control connection is returned to 'nControl'. This handle can then be
+passed to other routines to control the connection and exchange data.
+Returns success/fail.
+
+int FtpOptions(int opt, long val, netbuf *nControl);
+
+Specifies options for the connection. The available options are:
+ Option Values
+ FTPLIB_CONNMODE sets the command to use to establish
+ data connections. FTPLIB_PASSIVE
+ requests use of PASV; FTPLIB_PORT
+ requests use of PORT.
+ FTPLIB_CALLBACK address of a user callback routine
+ FTPLIB_IDLETIME amount of time in milliseconds to wait
+ on a data socket before calling the
+ user's callback routine
+ FTPLIB_CALLBACKARG argument to pass to user's callback
+ routine
+ FTPLIB_CALLBACKBYTES number of bytes to transfer before
+ calling user's callback routine
+
+int FtpLogin(const char *user, const char *pass, netbuf *nControl);
+
+Logs in using the specified username and password. Returns success/fail.
+
+int FtpSysType(char *buf, int max, netbuf *nControl);
+
+Attempts to parse the system type out of the response from a SYST message
+and return up to 'max' bytes of the result to 'buf'. The entire response
+can be retrieved using FtpLastResponse(). Returns success/fail.
+
+int FtpSize(char *path, int *size, char mode, netbuf *nControl);
+
+Requests the size of the file specified by 'path' transferred in mode
+'mode' and stores it at 'size'. Returns success/fail.
+
+int FtpModDate(char *path, char *buf, int max, netbuf *nControl);
+
+Requests the last modification date of the file specified by 'path' and
+returns up to 'max' bytes of the result to 'buf' in the format
+'YYYYMMDDHHMMSS'. Returns success/fail.
+
+int FtpSite(const char *cmd, netbuf *nControl);
+
+Issues the specified SITE command. See RFC 959 for more information.
+
+int FtpMkdir(const char *path, netbuf *nControl);
+
+Sends a create directory request to the server using the specified path.
+Returns success/fail.
+
+int FtpChdir(const char *path, netbuf *nControl);
+
+Sends a change working directory request to the server using the
+specified path. Returns success/fail.
+
+int FtpCDUp(netbuf *nControl);
+
+Requests a change to the parent directory. Returns sucess/fail.
+
+int FtpRmdir(const char *path, netbuf *nControl);
+
+Sends a remove directory request to the server using the specified path.
+Returns success/fail.
+
+int FtpPwd(char *path, int max, netbuf *nControl);
+
+Requests the current directory from the server and returns up to 'max'
+bytes of the result to 'path'. Returns success/fail.
+
+int FtpNlst(const char *outputfile, const char *path, netbuf *nControl);
+
+Sends an NLST command to the server with the specified path. The
+response to this is a list of file names which will be written to the
+file named in outputfile. If outputfile is specified as NULL, the list
+will be written to stdout.
+
+int FtpDir(const char *outputfile, const char *path, netbuf *nControl);
+
+Sends a LIST command to the server with the specified path. The response
+to this is usually a long format directory listing which will be written
+to the file named in outputfile. If outputfile is specified as NULL, the
+list will be written to stdout.
+
+int FtpGet(const char *outputfile, const char *path, char mode,
+ netbuf *nControl);
+
+Retreives the file specified by path and writes it to the file specified
+in outputfile. Image or ASCII transfer mode can be specified by setting
+mode to FTPLIB_IMAGE or FTPLIB_ASCII, respectively.
+
+int FtpPut(const char *inputfile, const char *path, char mode,
+ netbuf *nControl);
+
+Sends the file specified by inputfile to the server with the name
+specified in path. Image or ASCII transfer mode can be specified by
+setting mode to FTPLIB_IMAGE or FTPLIB_ASCII, respectively.
+
+int FtpRename(const char *src, const char *dst, netbuf *nControl);
+
+Renames the remote file specified by src to the name specified in dst.
+
+int FtpDelete(const char *fnm, netbuf *nControl);
+
+Removes the specified file from the server.
+
+void FtpQuit(void, netbuf *nControl);
+
+Disconnects from the remote server.
+
+char *FtpLastResponse(netbuf *nControl);
+
+Returns a pointer to the buffer containing the last response received
+from the server. Useful for displaying error messages.
+
+int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
+ netbuf **nHandle);
+
+Opens the file or directory specified by 'path' and returns a handle to
+'nHandle'. This handle can then be passed to FtpRead() or FtpWrite() to
+exchange data. To list a directory, set 'typ' to FTPLIB_DIR or
+FTPLIB_DIR_VERBOSE and 'mode' to FTPLIB_ASCII. To transfer files, set
+'mode' to FTPLIB_ASCII for text files or FTPLIB_IMAGE for binary files and
+set 'typ' to FTPLIB_FILE_READ to retreive a file or FTPLIB_FILE_WRITE to
+send a file.
+
+int FtpRead(void *buf, int max, netbuf *nData);
+
+Reads up to 'max' bytes of data from the data connection specified by
+'nData' and stores it in 'buf'. If the connection was opened in ascii
+mode, one line of is returned with the terminating new-line character.
+Otherwise, FtpRead() attempts to fill the buffer.
+
+int FtpWrite(void *buf, int len, netbuf *nData);
+
+Writes 'len' bytes of data from 'buf' to the data connection specified by
+'nData'. If the connection was opened in ascii mode, FtpWrite() performs
+the necessary conversions. Otherwise, FtpWrite() passes the data
+verbatim.
+
+int FtpClose(netbuf *nData);
+
+Closes the data connection specified by 'nData' and frees associated
+resources.
113 README.qftp
@@ -0,0 +1,113 @@
+qftp is a simple program which demonstrates the use of ftplib.
+
+qftp performs directories or file transfers using the ftp protocol based
+on the command it was invoked with and command line arguments. qftp
+should be invoked through a softlink which indicates which operation it
+should perform.
+
+To install, copy qftp to a directory in your path. Execute the following
+commands in that directory:
+
+ ln -s qftp ftpdir
+ ln -s qftp ftpget
+ ln -s qftp ftpsend
+ ln -s qftp ftprm
+ ln -s qftp ftplist
+
+Then, invoke qftp by using the commands ftpdir, ftpget, ftpsend, ftprm or
+ftplist.
+
+qftp processes the command line in order. The first argument should be
+the name of the system you wish to converse with. If you need to specify
+login information, that should be specified next with '-l' and '-p'. On
+UNIX systems, if you specify a username with '-l' and don't specify a
+password with '-p', qftp will prompt for a password. It is a good idea
+to do it this way as it keeps the password off the command line and out
+of 'ps' and other displays.
+
+When working through a proxy firewall, specify the firewall machine's
+name as the host. Specify the real host's name with the -l and -p
+parameters. For example:
+
+ ftpget firewall -l anonymous@real.host.com -p user@myhost.org
+
+The exit status from qftp can be used to determine whether the transfer
+worked or not. Exit status 2 means a command line syntax error. 3
+indicates a failure while attempting to translate the system name into an
+IP address. 4 indicates a failure attempting to connect to the remote
+machine. 5 indicates a login failure. 6 indicates a remote command
+error. 7 indicates a system call error.
+
+The command format is as follows:
+
+ <xxx> host [ -l user [ -p pass ] ]
+ [ [ -v level ]
+ [ -m umask ]
+ [ -r path ]
+ [ -a | -i ]
+ [ file ]
+ ] ...
+
+<xxx> should be replaced with 'ftpget', 'ftpdir', 'ftpsend', 'ftprm' or
+'ftplist'. 'host' is the name of the remote server machine and should
+immediately follow the command.
+
+'-l user' specifies the username to login with. '-p pass' specifies the
+password to use with that username. These should be specified
+immediately after the hostname. On UNIX systems, if a username is
+specified but a password is not, qftp will prompt for a password. If
+neither is specified, an anonymous login is attempted.
+
+'-v level' can be used to set the logging level of the routines. This
+can appear anywhere on the command line and will affect the logging of
+any actions performed on later command line arguments. Non-zero
+values cause qftp to log the actions it performs and display progress.
+Values greater than 1 cause ftplib to display responses received from
+the server. Values greater than 2 cause ftplib to display commands
+sent to the server.
+
+'-r path' can be used to change to a different directory on the server.
+'-m umask' attempts to change the default permissions mask on the server
+by issuing a 'SITE umask' command. This will not work with all servers
+but should work with almost any unix based server.
+
+'-a' and '-i' set ASCII and Image mode, respectively. This will apply to
+all files transfered until another '-a' or '-i' is encountered on the
+command line.
+
+'file' specifies the name of a file to transfer. The specified file name
+will be used on both the local machine and the server. If no files are
+specified for 'ftpget' or 'ftpsend', a list of file names will be read
+from stdin.
+
+Examples
+
+I use ftpsend to upload my web pages to my ISP. I maintain them all on
+my home PC under linux and send either the entire directory tree or just
+modified files with ftpsend.
+
+To send the entire directory tree, I execute the following command from
+my login directory:
+
+ find public_html -print | ftpsend cnj -l pfau -m 022
+
+(connect to system cnj, login as user pfau and prompt for a password, set
+the umask to 022, send files whose names will be read from standard input
+which is generated by the 'find' command which lists all files under my
+public_html directory)
+
+If I modify a file or two, I'll send them from my html directory with the
+following command:
+
+ ftpsend cnj -l pfau -m 022 -r public_html index.html hot.html
+
+(connect to system cnj, login as user pfau and prompt for a password, set
+the umask to 022, change directory to public_html, send files index.html
+and hot.html)
+
+To grab the latest directory listing of the linux area off of sunsite:
+
+ ftpget sunsite.unc.edu -r /pub/Linux ls-lR.gz
+
+(connect to system sunsite.unc.edu, use an anonymous login, switch to
+directory /pub/Linux, get file ls-lR.gz)
3,933 RFC959.txt
3,933 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
1,295 ftplib.c
@@ -0,0 +1,1295 @@
+/***************************************************************************/
+/* */
+/* ftplib.c - callable ftp access routines */
+/* Copyright (C) 1996-2001 Thomas Pfau, pfau@eclipse.net */
+/* 1407 Thomas Ave, North Brunswick, NJ, 08902 */
+/* */
+/* This library is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU Library General Public */
+/* License as published by the Free Software Foundation; either */
+/* version 2 of the License, or (at your option) any later version. */
+/* */
+/* This library is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* Library General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU Library General Public */
+/* License along with this progam; if not, write to the */
+/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
+/* Boston, MA 02111-1307, USA. */
+/* */
+/***************************************************************************/
+
+#if defined(__unix__) || defined(__VMS)
+#include <unistd.h>
+#endif
+#if defined(_WIN32)
+#include <windows.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#if defined(__unix__)
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#elif defined(VMS)
+#include <types.h>
+#include <socket.h>
+#include <in.h>
+#include <netdb.h>
+#include <inet.h>
+#elif defined(_WIN32)
+#include <winsock.h>
+#endif
+
+#define BUILDING_LIBRARY
+#include "ftplib.h"
+
+#if defined(_WIN32)
+#define SETSOCKOPT_OPTVAL_TYPE (const char *)
+#else
+#define SETSOCKOPT_OPTVAL_TYPE (void *)
+#endif
+
+#define FTPLIB_BUFSIZ 8192
+#define ACCEPT_TIMEOUT 30
+
+#define FTPLIB_CONTROL 0
+#define FTPLIB_READ 1
+#define FTPLIB_WRITE 2
+
+#if !defined FTPLIB_DEFMODE
+#define FTPLIB_DEFMODE FTPLIB_PASSIVE
+#endif
+
+struct NetBuf {
+ char *cput,*cget;
+ int handle;
+ int cavail,cleft;
+ char *buf;
+ int dir;
+ netbuf *ctrl;
+ netbuf *data;
+ int cmode;
+ struct timeval idletime;
+ FtpCallback idlecb;
+ void *idlearg;
+ int xfered;
+ int cbbytes;
+ int xfered1;
+ char response[256];
+};
+
+static char *version =
+ "ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau";
+
+GLOBALDEF int ftplib_debug = 0;
+
+#if defined(__unix__) || defined(VMS)
+#define net_read read
+#define net_write write
+#define net_close close
+#elif defined(_WIN32)
+#define net_read(x,y,z) recv(x,y,z,0)
+#define net_write(x,y,z) send(x,y,z,0)
+#define net_close closesocket
+#endif
+
+#if defined(NEED_MEMCCPY)
+/*
+ * VAX C does not supply a memccpy routine so I provide my own
+ */
+void *memccpy(void *dest, const void *src, int c, size_t n)
+{
+ int i=0;
+ const unsigned char *ip=src;
+ unsigned char *op=dest;
+
+ while (i < n)
+ {
+ if ((*op++ = *ip++) == c)
+ break;
+ i++;
+ }
+ if (i == n)
+ return NULL;
+ return op;
+}
+#endif
+#if defined(NEED_STRDUP)
+/*
+ * strdup - return a malloc'ed copy of a string
+ */
+char *strdup(const char *src)
+{
+ int l = strlen(src) + 1;
+ char *dst = malloc(l);
+ if (dst)
+ strcpy(dst,src);
+ return dst;
+}
+#endif
+
+/*
+ * socket_wait - wait for socket to receive or flush data
+ *
+ * return 1 if no user callback, otherwise, return value returned by
+ * user callback
+ */
+static int socket_wait(netbuf *ctl)
+{
+ fd_set fd,*rfd = NULL,*wfd = NULL;
+ struct timeval tv;
+ int rv = 0;
+ if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL))
+ return 1;
+ if (ctl->dir == FTPLIB_WRITE)
+ wfd = &fd;
+ else
+ rfd = &fd;
+ FD_ZERO(&fd);
+ do
+ {
+ FD_SET(ctl->handle,&fd);
+ tv = ctl->idletime;
+ rv = select(ctl->handle+1, rfd, wfd, NULL, &tv);
+ if (rv == -1)
+ {
+ rv = 0;
+ strncpy(ctl->ctrl->response, strerror(errno),
+ sizeof(ctl->ctrl->response));
+ break;
+ }
+ else if (rv > 0)
+ {
+ rv = 1;
+ break;
+ }
+ }
+ while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg)));
+ return rv;
+}
+
+/*
+ * read a line of text
+ *
+ * return -1 on error or bytecount
+ */
+static int readline(char *buf,int max,netbuf *ctl)
+{
+ int x,retval = 0;
+ char *end,*bp=buf;
+ int eof = 0;
+
+ if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ))
+ return -1;
+ if (max == 0)
+ return 0;
+ do
+ {
+ if (ctl->cavail > 0)
+ {
+ x = (max >= ctl->cavail) ? ctl->cavail : max-1;
+ end = memccpy(bp,ctl->cget,'\n',x);
+ if (end != NULL)
+ x = end - bp;
+ retval += x;
+ bp += x;
+ *bp = '\0';
+ max -= x;
+ ctl->cget += x;
+ ctl->cavail -= x;
+ if (end != NULL)
+ {
+ bp -= 2;
+ if (strcmp(bp,"\r\n") == 0)
+ {
+ *bp++ = '\n';
+ *bp++ = '\0';
+ --retval;
+ }
+ break;
+ }
+ }
+ if (max == 1)
+ {
+ *buf = '\0';
+ break;
+ }
+ if (ctl->cput == ctl->cget)
+ {
+ ctl->cput = ctl->cget = ctl->buf;
+ ctl->cavail = 0;
+ ctl->cleft = FTPLIB_BUFSIZ;
+ }
+ if (eof)
+ {
+ if (retval == 0)
+ retval = -1;
+ break;
+ }
+ if (!socket_wait(ctl))
+ return retval;
+ if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1)
+ {
+ perror("read");
+ retval = -1;
+ break;
+ }
+ if (x == 0)
+ eof = 1;
+ ctl->cleft -= x;
+ ctl->cavail += x;
+ ctl->cput += x;
+ }
+ while (1);
+ return retval;
+}
+
+/*
+ * write lines of text
+ *
+ * return -1 on error or bytecount
+ */
+static int writeline(char *buf, int len, netbuf *nData)
+{
+ int x, nb=0, w;
+ char *ubp = buf, *nbp;
+ char lc=0;
+
+ if (nData->dir != FTPLIB_WRITE)
+ return -1;
+ nbp = nData->buf;
+ for (x=0; x < len; x++)
+ {
+ if ((*ubp == '\n') && (lc != '\r'))
+ {
+ if (nb == FTPLIB_BUFSIZ)
+ {
+ if (!socket_wait(nData))
+ return x;
+ w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
+ if (w != FTPLIB_BUFSIZ)
+ {
+ printf("net_write(1) returned %d, errno = %d\n", w, errno);
+ return(-1);
+ }
+ nb = 0;
+ }
+ nbp[nb++] = '\r';
+ }
+ if (nb == FTPLIB_BUFSIZ)
+ {
+ if (!socket_wait(nData))
+ return x;
+ w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
+ if (w != FTPLIB_BUFSIZ)
+ {
+ printf("net_write(2) returned %d, errno = %d\n", w, errno);
+ return(-1);
+ }
+ nb = 0;
+ }
+ nbp[nb++] = lc = *ubp++;
+ }
+ if (nb)
+ {
+ if (!socket_wait(nData))
+ return x;
+ w = net_write(nData->handle, nbp, nb);
+ if (w != nb)
+ {
+ printf("net_write(3) returned %d, errno = %d\n", w, errno);
+ return(-1);
+ }
+ }
+ return len;
+}
+
+/*
+ * read a response from the server
+ *
+ * return 0 if first char doesn't match
+ * return 1 if first char matches
+ */
+static int readresp(char c, netbuf *nControl)
+{
+ char match[5];
+ if (readline(nControl->response,256,nControl) == -1)
+ {
+ perror("Control socket read failed");
+ return 0;
+ }
+ if (ftplib_debug > 1)
+ fprintf(stderr,"%s",nControl->response);
+ if (nControl->response[3] == '-')
+ {
+ strncpy(match,nControl->response,3);
+ match[3] = ' ';
+ match[4] = '\0';
+ do
+ {
+ if (readline(nControl->response,256,nControl) == -1)
+ {
+ perror("Control socket read failed");
+ return 0;
+ }
+ if (ftplib_debug > 1)
+ fprintf(stderr,"%s",nControl->response);
+ }
+ while (strncmp(nControl->response,match,4));
+ }
+ if (nControl->response[0] == c)
+ return 1;
+ return 0;
+}
+
+/*
+ * FtpInit for stupid operating systems that require it (Windows NT)
+ */
+GLOBALDEF void FtpInit(void)
+{
+#if defined(_WIN32)
+ WORD wVersionRequested;
+ WSADATA wsadata;
+ int err;
+ wVersionRequested = MAKEWORD(1,1);
+ if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0)
+ fprintf(stderr,"Network failed to start: %d\n",err);
+#endif
+}
+
+/*
+ * FtpLastResponse - return a pointer to the last response received
+ */
+GLOBALDEF char *FtpLastResponse(netbuf *nControl)
+{
+ if ((nControl) && (nControl->dir == FTPLIB_CONTROL))
+ return nControl->response;
+ return NULL;
+}
+
+/*
+ * FtpConnect - connect to remote server
+ *
+ * return 1 if connected, 0 if not
+ */
+GLOBALDEF int FtpConnect(const char *host, netbuf **nControl)
+{
+ int sControl;
+ struct sockaddr_in sin;
+ struct hostent *phe;
+ struct servent *pse;
+ int on=1;
+ netbuf *ctrl;
+ char *lhost;
+ char *pnum;
+
+ memset(&sin,0,sizeof(sin));
+ sin.sin_family = AF_INET;
+ lhost = strdup(host);
+ pnum = strchr(lhost,':');
+ if (pnum == NULL)
+ {
+#if defined(VMS)
+ sin.sin_port = htons(21);
+#else
+ if ((pse = getservbyname("ftp","tcp")) == NULL)
+ {
+ perror("getservbyname");
+ return 0;
+ }
+ sin.sin_port = pse->s_port;
+#endif
+ }
+ else
+ {
+ *pnum++ = '\0';
+ if (isdigit(*pnum))
+ sin.sin_port = htons((short)atoi(pnum));
+ else
+ {
+ pse = getservbyname(pnum,"tcp");
+ sin.sin_port = pse->s_port;
+ }
+ }
+ if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1)
+ {
+ if ((phe = gethostbyname(lhost)) == NULL)
+ {
+ perror("gethostbyname");
+ return 0;
+ }
+ memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
+ }
+ free(lhost);
+ sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (sControl == -1)
+ {
+ perror("socket");
+ return 0;
+ }
+ if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
+ SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
+ {
+ perror("setsockopt");
+ net_close(sControl);
+ return 0;
+ }
+ if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1)
+ {
+ perror("connect");
+ net_close(sControl);
+ return 0;
+ }
+ ctrl = calloc(1,sizeof(netbuf));
+ if (ctrl == NULL)
+ {
+ perror("calloc");
+ net_close(sControl);
+ return 0;
+ }
+ ctrl->buf = malloc(FTPLIB_BUFSIZ);
+ if (ctrl->buf == NULL)
+ {
+ perror("calloc");
+ net_close(sControl);
+ free(ctrl);
+ return 0;
+ }
+ ctrl->handle = sControl;
+ ctrl->dir = FTPLIB_CONTROL;
+ ctrl->ctrl = NULL;
+ ctrl->cmode = FTPLIB_DEFMODE;
+ ctrl->idlecb = NULL;
+ ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
+ ctrl->idlearg = NULL;
+ ctrl->xfered = 0;
+ ctrl->xfered1 = 0;
+ ctrl->cbbytes = 0;
+ if (readresp('2', ctrl) == 0)
+ {
+ net_close(sControl);
+ free(ctrl->buf);
+ free(ctrl);
+ return 0;
+ }
+ *nControl = ctrl;
+ return 1;
+}
+
+/*
+ * FtpOptions - change connection options
+ *
+ * returns 1 if successful, 0 on error
+ */
+GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
+{
+ int v,rv=0;
+ switch (opt)
+ {
+ case FTPLIB_CONNMODE:
+ v = (int) val;
+ if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT))
+ {
+ nControl->cmode = v;
+ rv = 1;
+ }
+ break;
+ case FTPLIB_CALLBACK:
+ nControl->idlecb = (FtpCallback) val;
+ rv = 1;
+ break;
+ case FTPLIB_IDLETIME:
+ v = (int) val;
+ rv = 1;
+ nControl->idletime.tv_sec = v / 1000;
+ nControl->idletime.tv_usec = (v % 1000) * 1000;
+ break;
+ case FTPLIB_CALLBACKARG:
+ rv = 1;
+ nControl->idlearg = (void *) val;
+ break;
+ case FTPLIB_CALLBACKBYTES:
+ rv = 1;
+ nControl->cbbytes = (int) val;
+ break;
+ }
+ return rv;
+}
+
+/*
+ * FtpSendCmd - send a command and wait for expected response
+ *
+ * return 1 if proper response received, 0 otherwise
+ */
+static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
+{
+ char buf[256];
+ if (nControl->dir != FTPLIB_CONTROL)
+ return 0;
+ if (ftplib_debug > 2)
+ fprintf(stderr,"%s\n",cmd);
+ if ((strlen(cmd) + 3) > sizeof(buf))
+ return 0;
+ sprintf(buf,"%s\r\n",cmd);
+ if (net_write(nControl->handle,buf,strlen(buf)) <= 0)
+ {
+ perror("write");
+ return 0;
+ }
+ return readresp(expresp, nControl);
+}
+
+/*
+ * FtpLogin - log in to remote server
+ *
+ * return 1 if logged in, 0 otherwise
+ */
+GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl)
+{
+ char tempbuf[64];
+
+ if (((strlen(user) + 7) > sizeof(tempbuf)) ||
+ ((strlen(pass) + 7) > sizeof(tempbuf)))
+ return 0;
+ sprintf(tempbuf,"USER %s",user);
+ if (!FtpSendCmd(tempbuf,'3',nControl))
+ {
+ if (nControl->response[0] == '2')
+ return 1;
+ return 0;
+ }
+ sprintf(tempbuf,"PASS %s",pass);
+ return FtpSendCmd(tempbuf,'2',nControl);
+}
+
+/*
+ * FtpOpenPort - set up data connection
+ *
+ * return 1 if successful, 0 otherwise
+ */
+static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
+{
+ int sData;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in in;
+ } sin;
+ struct linger lng = { 0, 0 };
+ unsigned int l;
+ int on=1;
+ netbuf *ctrl;
+ char *cp;
+ unsigned int v[6];
+ char buf[256];
+
+ if (nControl->dir != FTPLIB_CONTROL)
+ return -1;
+ if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE))
+ {
+ sprintf(nControl->response, "Invalid direction %d\n", dir);
+ return -1;
+ }
+ if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE))
+ {
+ sprintf(nControl->response, "Invalid mode %c\n", mode);
+ return -1;
+ }
+ l = sizeof(sin);
+ if (nControl->cmode == FTPLIB_PASSIVE)
+ {
+ memset(&sin, 0, l);
+ sin.in.sin_family = AF_INET;
+ if (!FtpSendCmd("PASV",'2',nControl))
+ return -1;
+ cp = strchr(nControl->response,'(');
+ if (cp == NULL)
+ return -1;
+ cp++;
+ sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]);
+ sin.sa.sa_data[2] = v[2];
+ sin.sa.sa_data[3] = v[3];
+ sin.sa.sa_data[4] = v[4];
+ sin.sa.sa_data[5] = v[5];
+ sin.sa.sa_data[0] = v[0];
+ sin.sa.sa_data[1] = v[1];
+ }
+ else
+ {
+ if (getsockname(nControl->handle, &sin.sa, &l) < 0)
+ {
+ perror("getsockname");
+ return 0;
+ }
+ }
+ sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
+ if (sData == -1)
+ {
+ perror("socket");
+ return -1;
+ }
+ if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR,
+ SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1)
+ {
+ perror("setsockopt");
+ net_close(sData);
+ return -1;
+ }
+ if (setsockopt(sData,SOL_SOCKET,SO_LINGER,
+ SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1)
+ {
+ perror("setsockopt");
+ net_close(sData);
+ return -1;
+ }
+ if (nControl->cmode == FTPLIB_PASSIVE)
+ {
+ if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1)
+ {
+ perror("connect");
+ net_close(sData);
+ return -1;
+ }
+ }
+ else
+ {
+ sin.in.sin_port = 0;
+ if (bind(sData, &sin.sa, sizeof(sin)) == -1)
+ {
+ perror("bind");
+ net_close(sData);
+ return 0;
+ }
+ if (listen(sData, 1) < 0)
+ {
+ perror("listen");
+ net_close(sData);
+ return 0;
+ }
+ if (getsockname(sData, &sin.sa, &l) < 0)
+ return 0;
+ sprintf(buf, "PORT %d,%d,%d,%d,%d,%d",
+ (unsigned char) sin.sa.sa_data[2],
+ (unsigned char) sin.sa.sa_data[3],
+ (unsigned char) sin.sa.sa_data[4],
+ (unsigned char) sin.sa.sa_data[5],
+ (unsigned char) sin.sa.sa_data[0],
+ (unsigned char) sin.sa.sa_data[1]);
+ if (!FtpSendCmd(buf,'2',nControl))
+ {
+ net_close(sData);
+ return 0;
+ }
+ }
+ ctrl = calloc(1,sizeof(netbuf));
+ if (ctrl == NULL)
+ {
+ perror("calloc");
+ net_close(sData);
+ return -1;
+ }
+ if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL))
+ {
+ perror("calloc");
+ net_close(sData);
+ free(ctrl);
+ return -1;
+ }
+ ctrl->handle = sData;
+ ctrl->dir = dir;
+ ctrl->idletime = nControl->idletime;
+ ctrl->idlearg = nControl->idlearg;
+ ctrl->xfered = 0;
+ ctrl->xfered1 = 0;
+ ctrl->cbbytes = nControl->cbbytes;
+ if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes)
+ ctrl->idlecb = nControl->idlecb;
+ else
+ ctrl->idlecb = NULL;
+ *nData = ctrl;
+ return 1;
+}
+
+/*
+ * FtpAcceptConnection - accept connection from server
+ *
+ * return 1 if successful, 0 otherwise
+ */
+static int FtpAcceptConnection(netbuf *nData, netbuf *nControl)
+{
+ int sData;
+ struct sockaddr addr;
+ unsigned int l;
+ int i;
+ struct timeval tv;
+ fd_set mask;
+ int rv;
+
+ FD_ZERO(&mask);
+ FD_SET(nControl->handle, &mask);
+ FD_SET(nData->handle, &mask);
+ tv.tv_usec = 0;
+ tv.tv_sec = ACCEPT_TIMEOUT;
+ i = nControl->handle;
+ if (i < nData->handle)
+ i = nData->handle;
+ i = select(i+1, &mask, NULL, NULL, &tv);
+ if (i == -1)
+ {
+ strncpy(nControl->response, strerror(errno),
+ sizeof(nControl->response));
+ net_close(nData->handle);
+ nData->handle = 0;
+ rv = 0;
+ }
+ else if (i == 0)
+ {
+ strcpy(nControl->response, "timed out waiting for connection");
+ net_close(nData->handle);
+ nData->handle = 0;
+ rv = 0;
+ }
+ else
+ {
+ if (FD_ISSET(nData->handle, &mask))
+ {
+ l = sizeof(addr);
+ sData = accept(nData->handle, &addr, &l);
+ i = errno;
+ net_close(nData->handle);
+ if (sData > 0)
+ {
+ rv = 1;
+ nData->handle = sData;
+ }
+ else
+ {
+ strncpy(nControl->response, strerror(i),
+ sizeof(nControl->response));
+ nData->handle = 0;
+ rv = 0;
+ }
+ }
+ else if (FD_ISSET(nControl->handle, &mask))
+ {
+ net_close(nData->handle);
+ nData->handle = 0;
+ readresp('2', nControl);
+ rv = 0;
+ }
+ }
+ return rv;
+}
+
+/*
+ * FtpAccess - return a handle for a data stream
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
+ netbuf **nData)
+{
+ char buf[256];
+ int dir;
+ if ((path == NULL) &&
+ ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ)))
+ {
+ sprintf(nControl->response,
+ "Missing path argument for file transfer\n");
+ return 0;
+ }
+ sprintf(buf, "TYPE %c", mode);
+ if (!FtpSendCmd(buf, '2', nControl))
+ return 0;
+ switch (typ)
+ {
+ case FTPLIB_DIR:
+ strcpy(buf,"NLST");
+ dir = FTPLIB_READ;
+ break;
+ case FTPLIB_DIR_VERBOSE:
+ strcpy(buf,"LIST");
+ dir = FTPLIB_READ;
+ break;
+ case FTPLIB_FILE_READ:
+ strcpy(buf,"RETR");
+ dir = FTPLIB_READ;
+ break;
+ case FTPLIB_FILE_WRITE:
+ strcpy(buf,"STOR");
+ dir = FTPLIB_WRITE;
+ break;
+ default:
+ sprintf(nControl->response, "Invalid open type %d\n", typ);
+ return 0;
+ }
+ if (path != NULL)
+ {
+ int i = strlen(buf);
+ buf[i++] = ' ';
+ if ((strlen(path) + i) >= sizeof(buf))
+ return 0;
+ strcpy(&buf[i],path);
+ }
+ if (FtpOpenPort(nControl, nData, mode, dir) == -1)
+ return 0;
+ if (!FtpSendCmd(buf, '1', nControl))
+ {
+ FtpClose(*nData);
+ *nData = NULL;
+ return 0;
+ }
+ (*nData)->ctrl = nControl;
+ nControl->data = *nData;
+ if (nControl->cmode == FTPLIB_PORT)
+ {
+ if (!FtpAcceptConnection(*nData,nControl))
+ {
+ FtpClose(*nData);
+ *nData = NULL;
+ nControl->data = NULL;
+ return 0;
+ }
+ }
+ return 1;
+}
+
+/*
+ * FtpRead - read from a data connection
+ */
+GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData)
+{
+ int i;
+ if (nData->dir != FTPLIB_READ)
+ return 0;
+ if (nData->buf)
+ i = readline(buf, max, nData);
+ else
+ {
+ i = socket_wait(nData);
+ if (i != 1)
+ return 0;
+ i = net_read(nData->handle, buf, max);
+ }
+ if (i == -1)
+ return 0;
+ nData->xfered += i;
+ if (nData->idlecb && nData->cbbytes)
+ {
+ nData->xfered1 += i;
+ if (nData->xfered1 > nData->cbbytes)
+ {
+ if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0)
+ return 0;
+ nData->xfered1 = 0;
+ }
+ }
+ return i;
+}
+
+/*
+ * FtpWrite - write to a data connection
+ */
+GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData)
+{
+ int i;
+ if (nData->dir != FTPLIB_WRITE)
+ return 0;
+ if (nData->buf)
+ i = writeline(buf, len, nData);
+ else
+ {
+ socket_wait(nData);
+ i = net_write(nData->handle, buf, len);
+ }
+ if (i == -1)
+ return 0;
+ nData->xfered += i;
+ if (nData->idlecb && nData->cbbytes)
+ {
+ nData->xfered1 += i;
+ if (nData->xfered1 > nData->cbbytes)
+ {
+ nData->idlecb(nData, nData->xfered, nData->idlearg);
+ nData->xfered1 = 0;
+ }
+ }
+ return i;
+}
+
+/*
+ * FtpClose - close a data connection
+ */
+GLOBALDEF int FtpClose(netbuf *nData)
+{
+ netbuf *ctrl;
+ switch (nData->dir)
+ {
+ case FTPLIB_WRITE:
+ /* potential problem - if buffer flush fails, how to notify user? */
+ if (nData->buf != NULL)
+ writeline(NULL, 0, nData);
+ case FTPLIB_READ:
+ if (nData->buf)
+ free(nData->buf);
+ shutdown(nData->handle,2);
+ net_close(nData->handle);
+ ctrl = nData->ctrl;
+ free(nData);
+ if (ctrl)
+ {
+ ctrl->data = NULL;
+ return(readresp('2', ctrl));
+ }
+ return 1;
+ case FTPLIB_CONTROL:
+ if (nData->data)
+ {
+ nData->ctrl = NULL;
+ FtpClose(nData);
+ }
+ net_close(nData->handle);
+ free(nData);
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * FtpSite - send a SITE command
+ *
+ * return 1 if command successful, 0 otherwise
+ */
+GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl)
+{
+ char buf[256];
+
+ if ((strlen(cmd) + 7) > sizeof(buf))
+ return 0;
+ sprintf(buf,"SITE %s",cmd);
+ if (!FtpSendCmd(buf,'2',nControl))
+ return 0;
+ return 1;
+}
+
+/*
+ * FtpSysType - send a SYST command
+ *
+ * Fills in the user buffer with the remote system type. If more
+ * information from the response is required, the user can parse
+ * it out of the response buffer returned by FtpLastResponse().
+ *
+ * return 1 if command successful, 0 otherwise
+ */
+GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl)
+{
+ int l = max;
+ char *b = buf;
+ char *s;
+ if (!FtpSendCmd("SYST",'2',nControl))
+ return 0;
+ s = &nControl->response[4];
+ while ((--l) && (*s != ' '))
+ *b++ = *s++;
+ *b++ = '\0';
+ return 1;
+}
+
+/*
+ * FtpMkdir - create a directory at server
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl)
+{
+ char buf[256];
+
+ if ((strlen(path) + 6) > sizeof(buf))
+ return 0;
+ sprintf(buf,"MKD %s",path);
+ if (!FtpSendCmd(buf,'2', nControl))
+ return 0;
+ return 1;
+}
+
+/*
+ * FtpChdir - change path at remote
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpChdir(const char *path, netbuf *nControl)
+{
+ char buf[256];
+
+ if ((strlen(path) + 6) > sizeof(buf))
+ return 0;
+ sprintf(buf,"CWD %s",path);
+ if (!FtpSendCmd(buf,'2',nControl))
+ return 0;
+ return 1;
+}
+
+/*
+ * FtpCDUp - move to parent directory at remote
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpCDUp(netbuf *nControl)
+{
+ if (!FtpSendCmd("CDUP",'2',nControl))
+ return 0;
+ return 1;
+}
+
+/*
+ * FtpRmdir - remove directory at remote
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl)
+{
+ char buf[256];
+
+ if ((strlen(path) + 6) > sizeof(buf))
+ return 0;
+ sprintf(buf,"RMD %s",path);
+ if (!FtpSendCmd(buf,'2',nControl))
+ return 0;
+ return 1;
+}
+
+/*
+ * FtpPwd - get working directory at remote
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl)
+{
+ int l = max;
+ char *b = path;
+ char *s;
+ if (!FtpSendCmd("PWD",'2',nControl))
+ return 0;
+ s = strchr(nControl->response, '"');
+ if (s == NULL)
+ return 0;
+ s++;
+ while ((--l) && (*s) && (*s != '"'))
+ *b++ = *s++;
+ *b++ = '\0';
+ return 1;
+}
+
+/*
+ * FtpXfer - issue a command and transfer data
+ *
+ * return 1 if successful, 0 otherwise
+ */
+static int FtpXfer(const char *localfile, const char *path,
+ netbuf *nControl, int typ, int mode)
+{
+ int l,c;
+ char *dbuf;
+ FILE *local = NULL;
+ netbuf *nData;
+ int rv=1;
+
+ if (localfile != NULL)
+ {
+ char ac[4] = "w";
+ if (typ == FTPLIB_FILE_WRITE)
+ ac[0] = 'r';
+ if (mode == FTPLIB_IMAGE)
+ ac[1] = 'b';
+ local = fopen(localfile, ac);
+ if (local == NULL)
+ {
+ strncpy(nControl->response, strerror(errno),
+ sizeof(nControl->response));
+ return 0;
+ }
+ }
+ if (local == NULL)
+ local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout;
+ if (!FtpAccess(path, typ, mode, nControl, &nData))
+ return 0;
+ dbuf = malloc(FTPLIB_BUFSIZ);
+ if (typ == FTPLIB_FILE_WRITE)
+ {
+ while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
+ if ((c = FtpWrite(dbuf, l, nData)) < l)
+ {
+ printf("short write: passed %d, wrote %d\n", l, c);
+ rv = 0;
+ break;
+ }
+ }
+ else
+ {
+ while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0)
+ if (fwrite(dbuf, 1, l, local) <= 0)
+ {
+ perror("localfile write");
+ rv = 0;
+ break;
+ }
+ }
+ free(dbuf);
+ fflush(local);
+ if (localfile != NULL)
+ fclose(local);
+ FtpClose(nData);
+ return rv;
+}
+
+/*
+ * FtpNlst - issue an NLST command and write response to output
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpNlst(const char *outputfile, const char *path,
+ netbuf *nControl)
+{
+ return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII);
+}
+
+/*
+ * FtpDir - issue a LIST command and write response to output
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl)
+{
+ return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII);
+}
+
+/*
+ * FtpSize - determine the size of a remote file
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl)
+{
+ char cmd[256];
+ int resp,sz,rv=1;
+
+ if ((strlen(path) + 7) > sizeof(cmd))
+ return 0;
+ sprintf(cmd, "TYPE %c", mode);
+ if (!FtpSendCmd(cmd, '2', nControl))
+ return 0;
+ sprintf(cmd,"SIZE %s",path);
+ if (!FtpSendCmd(cmd,'2',nControl))
+ rv = 0;
+ else
+ {
+ if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2)
+ *size = sz;
+ else
+ rv = 0;
+ }
+ return rv;
+}
+
+/*
+ * FtpModDate - determine the modification date of a remote file
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl)
+{
+ char buf[256];
+ int rv = 1;
+
+ if ((strlen(path) + 7) > sizeof(buf))
+ return 0;
+ sprintf(buf,"MDTM %s",path);
+ if (!FtpSendCmd(buf,'2',nControl))
+ rv = 0;
+ else
+ strncpy(dt, &nControl->response[4], max);
+ return rv;
+}
+
+/*
+ * FtpGet - issue a GET command and write received data to output
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpGet(const char *outputfile, const char *path,
+ char mode, netbuf *nControl)
+{
+ return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode);
+}
+
+/*
+ * FtpPut - issue a PUT command and send data from input
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode,
+ netbuf *nControl)
+{
+ return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode);
+}
+
+/*
+ * FtpRename - rename a file at remote
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl)
+{
+ char cmd[256];
+
+ if (((strlen(src) + 7) > sizeof(cmd)) ||
+ ((strlen(dst) + 7) > sizeof(cmd)))
+ return 0;
+ sprintf(cmd,"RNFR %s",src);
+ if (!FtpSendCmd(cmd,'3',nControl))
+ return 0;
+ sprintf(cmd,"RNTO %s",dst);
+ if (!FtpSendCmd(cmd,'2',nControl))
+ return 0;
+ return 1;
+}
+
+/*
+ * FtpDelete - delete a file at remote
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl)
+{
+ char cmd[256];
+
+ if ((strlen(fnm) + 7) > sizeof(cmd))
+ return 0;
+ sprintf(cmd,"DELE %s",fnm);
+ if (!FtpSendCmd(cmd,'2', nControl))
+ return 0;
+ return 1;
+}
+
+/*
+ * FtpQuit - disconnect from remote
+ *
+ * return 1 if successful, 0 otherwise
+ */
+GLOBALDEF void FtpQuit(netbuf *nControl)
+{
+ if (nControl->dir != FTPLIB_CONTROL)
+ return;
+ FtpSendCmd("QUIT",'2',nControl);
+ net_close(nControl->handle);
+ free(nControl->buf);
+ free(nControl);
+}
125 ftplib.h
@@ -0,0 +1,125 @@
+/***************************************************************************/
+/* */
+/* ftplib.h - header file for callable ftp access routines */
+/* Copyright (C) 1996, 1997 Thomas Pfau, pfau@cnj.digex.net */
+/* 73 Catherine Street, South Bound Brook, NJ, 08880 */
+/* */
+/* This library is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU Library General Public */
+/* License as published by the Free Software Foundation; either */
+/* version 2 of the License, or (at your option) any later version. */
+/* */
+/* This library is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* Library General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU Library General Public */
+/* License along with this progam; if not, write to the */
+/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
+/* Boston, MA 02111-1307, USA. */
+/* */
+/***************************************************************************/
+
+#if !defined(__FTPLIB_H)
+#define __FTPLIB_H
+
+#if defined(__unix__) || defined(VMS)
+#define GLOBALDEF
+#define GLOBALREF extern
+#elif defined(_WIN32)
+#if defined BUILDING_LIBRARY
+#define GLOBALDEF __declspec(dllexport)
+#define GLOBALREF __declspec(dllexport)
+#else
+#define GLOBALREF __declspec(dllimport)
+#endif
+#endif
+
+/* FtpAccess() type codes */
+#define FTPLIB_DIR 1
+#define FTPLIB_DIR_VERBOSE 2
+#define FTPLIB_FILE_READ 3
+#define FTPLIB_FILE_WRITE 4
+
+/* FtpAccess() mode codes */
+#define FTPLIB_ASCII 'A'
+#define FTPLIB_IMAGE 'I'
+#define FTPLIB_TEXT FTPLIB_ASCII
+#define FTPLIB_BINARY FTPLIB_IMAGE
+
+/* connection modes */
+#define FTPLIB_PASSIVE 1
+#define FTPLIB_PORT 2
+
+/* connection option names */
+#define FTPLIB_CONNMODE 1
+#define FTPLIB_CALLBACK 2
+#define FTPLIB_IDLETIME 3
+#define FTPLIB_CALLBACKARG 4
+#define FTPLIB_CALLBACKBYTES 5
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct NetBuf netbuf;
+typedef int (*FtpCallback)(netbuf *nControl, int xfered, void *arg);
+
+/* v1 compatibility stuff */
+#if !defined(_FTPLIB_NO_COMPAT)
+netbuf *DefaultNetbuf;
+
+#define ftplib_lastresp FtpLastResponse(DefaultNetbuf)
+#define ftpInit FtpInit
+#define ftpOpen(x) FtpConnect(x, &DefaultNetbuf)
+#define ftpLogin(x,y) FtpLogin(x, y, DefaultNetbuf)
+#define ftpSite(x) FtpSite(x, DefaultNetbuf)
+#define ftpMkdir(x) FtpMkdir(x, DefaultNetbuf)
+#define ftpChdir(x) FtpChdir(x, DefaultNetbuf)
+#define ftpRmdir(x) FtpRmdir(x, DefaultNetbuf)
+#define ftpNlst(x, y) FtpNlst(x, y, DefaultNetbuf)
+#define ftpDir(x, y) FtpDir(x, y, DefaultNetbuf)
+#define ftpGet(x, y, z) FtpGet(x, y, z, DefaultNetbuf)
+#define ftpPut(x, y, z) FtpPut(x, y, z, DefaultNetbuf)
+#define ftpRename(x, y) FtpRename(x, y, DefaultNetbuf)
+#define ftpDelete(x) FtpDelete(x, DefaultNetbuf)
+#define ftpQuit() FtpQuit(DefaultNetbuf)
+#endif /* (_FTPLIB_NO_COMPAT) */
+/* end v1 compatibility stuff */
+
+GLOBALREF int ftplib_debug;
+GLOBALREF void FtpInit(void);
+GLOBALREF char *FtpLastResponse(netbuf *nControl);
+GLOBALREF int FtpConnect(const char *host, netbuf **nControl);
+GLOBALREF int FtpOptions(int opt, long val, netbuf *nControl);
+GLOBALREF int FtpLogin(const char *user, const char *pass, netbuf *nControl);
+GLOBALREF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
+ netbuf **nData);
+GLOBALREF int FtpRead(void *buf, int max, netbuf *nData);
+GLOBALREF int FtpWrite(void *buf, int len, netbuf *nData);
+GLOBALREF int FtpClose(netbuf *nData);
+GLOBALREF int FtpSite(const char *cmd, netbuf *nControl);
+GLOBALREF int FtpSysType(char *buf, int max, netbuf *nControl);
+GLOBALREF int FtpMkdir(const char *path, netbuf *nControl);
+GLOBALREF int FtpChdir(const char *path, netbuf *nControl);
+GLOBALREF int FtpCDUp(netbuf *nControl);
+GLOBALREF int FtpRmdir(const char *path, netbuf *nControl);
+GLOBALREF int FtpPwd(char *path, int max, netbuf *nControl);
+GLOBALREF int FtpNlst(const char *output, const char *path, netbuf *nControl);
+GLOBALREF int FtpDir(const char *output, const char *path, netbuf *nControl);
+GLOBALREF int FtpSize(const char *path, int *size, char mode, netbuf *nControl);
+GLOBALREF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl);
+GLOBALREF int FtpGet(const char *output, const char *path, char mode,
+ netbuf *nControl);
+GLOBALREF int FtpPut(const char *input, const char *path, char mode,
+ netbuf *nControl);
+GLOBALREF int FtpRename(const char *src, const char *dst, netbuf *nControl);
+GLOBALREF int FtpDelete(const char *fnm, netbuf *nControl);
+GLOBALREF void FtpQuit(netbuf *nControl);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* __FTPLIB_H */
46 html/FtpAccess.html
@@ -0,0 +1,46 @@
+<html>
+<head><title>FtpAccess</title></head>
+<body>
+
+<h1>FtpAccess</h1>
+<p>Open a file or directory on the remote system.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
+ netbuf **nData);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>path</b>
+<dd>Specifies the name of the remote file or directory to open.
+
+<dt><b>typ</b>
+<dd>Specifies the type of transfer to be performed. FTPLIB_DIR performs
+a terse directory. FTPLIB_DIR_VERBOSE performs a verbose directory.
+FTPLIB_FILE_READ opens a remote file for reading. FTPLIB_FILE_WRITE
+creates a remote file and readies it for writing.
+
+<dt><b>mode</b>
+<dd>Specifies the transfer mode as FTPLIB_ASCII or FTPLIB_IMAGE.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+<dt><b>nData</b>
+<dd>Specifies the address to store a pointer to the created data handle.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>FtpAccess() opens a remote file or directory and returns a handle for
+the calling program to use to transfer data.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
29 html/FtpCDUp.html
@@ -0,0 +1,29 @@
+<html>
+<head><title>FtpCDUp</title></head>
+<body>
+
+<h1>FtpCDUp</h1>
+<p>Change to parent directory.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpCDUp(netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>FtpCDUp() sends a CDUP command to the remote server.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
33 html/FtpChdir.html
@@ -0,0 +1,33 @@
+<html>
+<head><title>FtpChdir</title></head>
+<body>
+
+<h1>FtpChdir</h1>
+<p>Change working directory on server.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpChdir(const char *path, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>path</b>
+<dd>Specifies the desired working directory on the server.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <A HREF="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>Sends a change working directory request to the server using the
+specified path.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
30 html/FtpClose.html
@@ -0,0 +1,30 @@
+<html>
+<head><title>FtpClose</title></head>
+<body>
+
+<h1>FtpClose</h1>
+<p>Close a data connection.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpClose(netbuf *nData);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>nData</b>
+<dd>A handle returned by <a href="FtpAccess.html">FtpAccess()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>Closes the data connection specified by 'nData' and frees associated
+resources.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
39 html/FtpConnect.html
@@ -0,0 +1,39 @@
+<html>
+<head><title>FtpConnect</title></head>
+<body>
+
+<h1>FtpConnect</h1>
+<p>Connect to an FTP server.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpConnect(const char *host, netbuf **nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>host</b>
+<dd>The name of the host machine to connect to and optionally an
+alternate port number to use.
+
+<dt><b>nControl</b>
+<dd>The address where the pointer to the newly created control handle should be
+stored.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>FtpConnect() establishes a connection to the FTP server on the
+specified machine and returns a handle which can be used to initiate data
+transfers. The host name should be specified as <host> or <host>:<port>.
+<host> may be either a host name or ip address. <port> may be either a
+service name or a port number.
+
+<h2>RETURN VALUE</h2>
+<p>If the connection to the remote server if successful, FtpConnect()
+returns 1. Otherwise, 0 is returned.
+
+</body>
+</html>
33 html/FtpDelete.html
@@ -0,0 +1,33 @@
+<html>
+<head><title>FtpDelete</title></head>
+<body>
+
+<h1>FtpDelete</h1>
+<p>Removes a file from the remote system.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpDelete(const char *fnm, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>fnm</b>
+<dd>The name of the file which is to be removed.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>Requests that the server remove the specified file from the remote
+file system.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
38 html/FtpDir.html
@@ -0,0 +1,38 @@
+<html>
+<head><title>FtpDir</title></head>
+<body>
+
+<h1>FtpDir</h1>
+<p>Performs a verbose directory.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpDir(const char *outputfile, const char *path, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>outputfile</b>
+<dd>Name of a local file to receive the directory listing.
+
+<dt><b>path</b>
+<dd>File specification to pass to remote 'ls'.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>Sends a LIST command to the server with the specified path. The response
+to this is usually a long format directory listing which will be written
+to the file named in outputfile. If outputfile is specified as NULL, the
+list will be written to stdout.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
38 html/FtpGet.html
@@ -0,0 +1,38 @@
+<html>
+<head><title>FtpGet</title></head>
+<body>
+
+<h1>FtpGet</h1>
+<p>Retreive a file from the remote system.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpGet(const char *output, const char *path, char mode, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>output</b>
+<dd>Name of a local file to receive the contents of the remote file.
+
+<dt><b>path</b>
+<dd>Name of remote file to be retrieved.
+
+<dt><b>mode</b>
+<dd>Specifies the transfer mode as FTPLIB_ASCII or FTPLIB_IMAGE.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>FtpGet() copies the contents of a remote file to a local file.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
24 html/FtpInit.html
@@ -0,0 +1,24 @@
+<html>
+<head><title>FtpInit</title></head>
+<body>
+
+<h1>FtpInit</h1>
+<p>Initialize the library.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+void FtpInit(void);
+</pre>
+
+<h2>PARAMETERS</h2>
+<p>None.
+
+<h2>DESCRIPTION</h2>
+<p>Performs any required initialization for the library.
+
+<h2>RETURN VALUE</h2>
+<p>None.
+
+</body>
+</html>
33 html/FtpLastResponse.html
@@ -0,0 +1,33 @@
+<html>
+<head><title>FtpLastResponse</title></head>
+<body>
+
+<h1>FtpLastResponse</h1>
+<p>Retrieve the last response sent by the server.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+char *FtpLastResponse(netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>nControl</b>
+<dd>A pointer to a control handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>FtpLastResponse() returns a pointer to the last response string sent
+by the server. This can be parsed by the user program to determine more
+information about the last request or can be displayed along with an
+error message.
+
+<h2>RETURN VALUE</h2>
+<p>If nControl is a valid control handle, FtpLastResponse() returns a
+pointer to the last server response string. Otherwise, NULL is returned.
+
+</body>
+</html>
36 html/FtpLogin.html
@@ -0,0 +1,36 @@
+<html>
+<head><title>FtpLogin</title></head>
+<body>
+
+<h1>FtpLogin</h1>
+<p>Login to remote system.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpLogin(const char *user, const char *pass, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>user</b>
+<dd>Specifies the username.
+
+<dt><b>pass</b>
+<dd>Specifies the password.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>FtpLogin() attempts to login to the remote system with the supplied
+username and password.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
32 html/FtpMkdir.html
@@ -0,0 +1,32 @@
+<html>
+<head><title>FtpMkdir</title></head>
+<body>
+
+<h1>FtpMkdir</h1>
+<p>Create a directory on the remote system.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpMkdir(const char *path, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>path</b>
+<dd>Specifies the argument to mkdir on the remote system.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>FtpMkdir() sends a make directory request to the remote system.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
43 html/FtpModDate.html
@@ -0,0 +1,43 @@
+<html>
+<head><title>FtpModDate</title></head>
+<body>
+
+<h1>FtpModDate</h1>
+<p>Determine last modification time of a remote file.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpModDate(char *path, char *buf, int max, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>path</b>
+<dd>Name of remote file to be checked.
+
+<dt><b>buf</b>
+<dd>A pointer to a buffer where the result should be returned.
+
+<dt><b>max</b>
+<dd>Specifies the size of the user's buffer.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href=FtpConnect>FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>FtpModDate() attempts to determine the last access time of a remote
+file and return it to the user's buffer. The date and time are returned
+as a string in the format 'YYYYMMDDHHMMSS'.
+
+<h2>RETURN VALUE</h2>
+<p>If a good response is received and the date and time are successfully
+parsed out of the result, 1 is returned. Otherwise, 0 is returned.
+
+<p>Some servers may not support the MDTM command.
+
+</body>
+</html>
36 html/FtpNlst.html
@@ -0,0 +1,36 @@
+<html>
+<head><title>FtpNlst</title></head>
+<body>
+
+<h1>FtpNlst</h1>
+<p>Performs a terse directory.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpNlst(const char *output, const char *path, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>output</b>
+<dd>Specifies the name of a file to receive the directory listing.
+
+<dt><b>path</b>
+<dd>Specifies an argument to 'ls' on the remote system.
+
+<dt><b>nControl</b>
+<dd>A handle returned by <a href="FtpConnect.html">FtpConnect()</a>.
+
+</dl>
+
+<h2>DESCRIPTION</h2>
+<p>Performs a short form directory listing of the specified path on the
+remote system. The results are written to the specified file.
+
+<h2>RETURN VALUE</h2>
+<p>Returns 1 if successful or 0 on error.
+
+</body>
+</html>
87 html/FtpOptions.html
@@ -0,0 +1,87 @@
+<html>
+<head><title>FtpOptions</title></head>
+<body>
+
+<h1>FtpOptions</h1>
+<p>Set connection options.
+
+<h2>SYNOPSIS</h2>
+<pre>
+#include &lt;ftplib.h&gt;
+int FtpOptions(int opt, long val, netbuf *nControl);
+</pre>
+
+<h2>PARAMETERS</h2>
+<dl>
+
+<dt><b>opt</b>
+<dd>Specifies the option to change. Valid options are FTPLIB_CONNMODE,
+FTPLIB_CALLBACK, FTPLIB_IDLETIME, FTPLIB_CALLBACKARG, and
+FTPLIB_CALLBACKBYTES.
+
+<dt><b>val</b>
+<dd>Specifies the new value for the option. The value may need to by
+cast to a long.
+