Version 18 of ftp

Updated 2005-11-27 19:53:46

Standard documentation appears at http://tcllib.sourceforge.net/doc/ftp.html .

Related pages:


Here's an example implementation of a "deep" listing, which recurses into subdirectories:

    proc deep_list {host user pass dir} {
        set handle [::ftp::Open $host $user $pass]
            # An alternative would be to "::ftp::Cd ... $dir",
            #     then "::ftp::DeepList $handle .", then strip
            #     off the leading "./" (or equivalent).  That
            #     gives a slightly different format.  I'm not
            #     sure which has superior aesthetics.
        set result [::ftp::DeepList $handle $dir]
        ::ftp::Close $handle
        return $result
    }


    proc ::ftp::DeepList {handle directory} {
        set result {}
        set original [::ftp::Pwd $handle]
        foreach item [::ftp::NList $handle $directory/*] {
                # Why two clauses in the predicate?  Because,
                #    depending on the (run-time) value of 
                #    $::ftp::VERBOSE, we might receive either
                #    an exception, or a return value.  We need
                #    to handle either case gracefully.
            if {[catch {::ftp::Cd $handle $item} ret_val] || !$ret_val} {
                lappend result $item
            } else {
                ::ftp::Cd $handle $original
                set result [concat $result [deep_list_i $handle $item]]
            }
        }
        return [lsort $result]
    }

Use this as

    set list_of_files [deep_list $host $user $pass $directory]

/* As a cut and paste code snippet it failed for me. The procedure deep_list_i is undefined. Art Morel [email protected] */


Commentary on the history of FTP specifications appear at http://www.wu-ftpd.org/rfc/ .


These days (21th century) system administrators have started shutting down FTP access for security reasons. A rather different protocol which could provide an alternative is fish.


Category Package (sub-package of Tcllib) Category Internet