FTP Library Package 1.2 for Tcl/Tk

<<< BACK TO HOMEPAGE   |   Introduction | Overview | Download | Installation | Examples

 Introduction 

The FTP Library Package ftp_lib provides client side of the File Transfer Protocol (FTP). The package extends tcl/tk with commands to support the file transfer protocol like OPEN, CLOSE, LIST, PUT, GET, REGET etc.. It's used either to add FTP ability to existing tcl/tk applications or to create small FTP scripts that perform tasks without user interaction. It allows automatic up/download processes even up to the mirroring of complete FTP sites.

The library package consists of 100% pure tcl code, no extensions, no C stuff.


note NOTE: The ftp_lib was frozen with release 1.2 and is no longer maintained at this site.
It is now part of the Standard Tcl Library (tcllib) and grows with this library of standard routines.
The source code for tcllib is available through CVS repository at the SourceForge's Tcl Foundry.

What's new!!!:

What's new in release 1.2 (May 12, 1999) :


NOTE: At the present there are two releases of ftp_lib. First, ftp_lib 0.4, is an older version to support tcl7.6/tk4.2 which still works using the undocumented command "unsupported0" for binary data transfer. I strongly recommend to use the second, the current version ftp_lib 1.2. Only this new release uses the much more stable and faster "fcopy" command to transfer binary data between two channels. For the latest release tcl/tk8.0 must be installed.

 Command Overview 

There are dozens of possible FTP commands described in several RFCs. Ftp_lib contains essentially requests specified in RFC 959 and some additionally features. The ftp library package currently supports the following commands:
FTP::Open <server> <user> <passwd> ?options?
FTP::Close
FTP::Cd <directory>
FTP::Pwd
FTP::Type <?ascii|binary?>	
FTP::List <?directory?>
FTP::NList <?directory?>
FTP::FileSize <file>
FTP::ModTime <file>
FTP::Delete <file>
FTP::Rename <from> <to>
FTP::Put <local> <?remote?>
FTP::Append <local> <?remote?>
FTP::Get <remote> <?local?>
FTP::Reget <remote> <?local?>
FTP::Newer <remote> <?local?>
FTP::MkDir <directory>
FTP::RmDir <directory>
FTP::Quote <arg1> <arg2> ...
For a complete description of each command please refer to the new HTML Online Manual Pages.
For further informations see README and CHANGES.
Jean-Yves Terrien sends a nice patch to allow multiple FTP session.

 Download 

The FTP library package is free software; you can redistribute it and/or modify it under the terms of the BSD License as published by the Free Software Foundation. The latest release ftp_lib 1.2 was created under Linux und runs on UN*X, Windows and maybe (*not tested*) on Macintosh Computers. Alternatively download location at ftp.neosoft.com

 Installation Instructions 

  1. If you do not have already installed tcl/tk 8.0, at first you must install it. Get it from the known locations and follow the installation instructions.

  2. Download ftp_lib from these location.

  3. Copy the compressed library package into a temporary directory. Unpack it dependent on operating system. Use Winzip for windows platforms and gunzip for UNIX.

  4. Type ./install.tcl in the current directory or double click it in explorer or file manager window. A simple installation program is seen now. The installation program allows you to change the destination directory for the FTP library. The default directory is "/usr/local/lib" for UN*X and the Tcl/Tk distribution directory for Win*.

  5. Some scripts are placed in the current directory that demonstrates the using of ftp_lib. One of them is called ftpdemo.tcl. It is a graphical user interface to test interactively the command set of ftp_lib in each environment. Check it out because not all FTP servers provides a complete set of FTP requests! I have used ftpdemo.tcl permanent during the development of ftp_lib.

    Configure ftpdemo.tcl with your access data and your customized options! I also suggest to have a look at the script's source code to understand how ftp_lib works!

    Some other example scripts are described below.

 Examples 

The FTP library package can easily include into programs. Invoke

package require FTP 1.2
in your tcl code to load a suitable version of the FTP library package. I have written some example utilities to show the easily use of ftp_lib's commands.

Example #1 - Directory Mirror

The script mirror.tcl is used to mirror a complete remote directory structure. It creates an exact copy of this structure on the locale machine. Three parameters needs to be modified to work properly, the hostname of the remote server, the username and the password for login.
package require FTP 1.2

# user configuration
set server noname
set username anonymous
set passwd xxxxxx 

# simple progress display
proc ProgressBar {bytes} {
    puts -nonewline stdout "."; flush stdout
}

# recursive file transfer 
proc GetTree {{dir ""}} {
    catch {file mkdir $dir}
    foreach line [FTP::List $dir] {
    	set rc [scan $line "%s %s %s %s %s %s %s %s %s %s %s" perm l u g size d1 d2 d3 name link linksource]
	if { ($name == ".") || ($name == "..") } {continue}
        set type [string range $perm 0 0]
        set name [file join $dir $name]
        switch -- $type {
            d {GetTree $name}
            l {catch {exec ln -s $linksource $name} msg}
            - {FTP::Get $name}
        }
    }
}

# main	
if {![FTP::Open $server $username $passwd -progress ProgressBar]} {
	puts "Connection refused!"
	exit 1
}
GetTree
FTP::Close 

Example #2 - Software Update

The next few lines in newer.tcl are used to detect whether a new release of Brent Welch's phantastic tcl-httpd is present at scriptics ftp server. If FTP::Newer detects a newer file then it causes the upload process and sends me (as root) an email to inform about.
package require FTP 1.2

if {![FTP::Open ftp.scriptics.com anonymous xxxx]} {
	puts "Connection refused!"
	exit 1
}
if {[FTP::Newer /pub/tcl/httpd/tclhttpd.tar.gz /usr/local/src/tclhttpd.tgz]} {
	exec echo "New httpd arrived!" | mailx -s ANNOUNCE root
}
FTP::Close 

Example #3 - Homepage Update

Quite a few people must have to keep permanent updating their homepages on a ISP server. My hpupdate.tcl is a tk-program for the interactive comparsion of the homepage directory on the local computer with the same directories on the remote homepage server. It is based on File Transfer Protocol. This process can be automated easily by hpupdate. It makes it quick and easy to keep the track of new/old or changed files.

Brief overview:

Example #4 - TkCon command line ftp client

Loading the FTP Library Package into Jeffrey Hobbs' TkCon provides a simple ftp command line utility with command history. TkCon is a replacement for the standard console that comes with Tk. It must be started with the "package" option:

tkcon -package FTP
to load ftp_lib automatically. Here is a screenshot of a simple ftp session using TkCon.

All examples can be found in the package distribution.


©Steffen Traeger
changed: 05/16/99

[Steffen Traeger's Homepage]