Tcl
Tcl
Get FTP Directory Listing Information
See more FTP Examples
_LANGUAGE_ example showing how to get information about files and subdirectories in the current remote FTP directory.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set ftp [new_CkFtp2]
CkFtp2_put_Hostname $ftp "ftp.example.com"
CkFtp2_put_Username $ftp "login"
CkFtp2_put_Password $ftp "password"
# Connect and login to the FTP server.
set success [CkFtp2_Connect $ftp]
if {$success != 1} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# The ListPattern property is our directory listing filter.
# The default value is "*", which includes everything.
puts [CkFtp2_listPattern $ftp]
# To get file and sub-directory information, simply
# loop from 0 to ftp.GetDirCount() - 1
set n [CkFtp2_GetDirCount $ftp]
if {$n < 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
if {$n > 0} then {
for {set i 0} {$i <= [expr $n - 1]} {incr i} {
# Display the filename
puts [CkFtp2_getFilename $ftp $i]
# Display the file size (in bytes)
puts [CkFtp2_GetSize $ftp $i]
# Is this a sub-directory?
if {[CkFtp2_GetIsDirectory $ftp $i] == 1} then {
puts ".. this is a sub-directory"
}
puts "--"
}
}
puts "-----------------------------------"
# Only files and directories
# matching the ListPattern are returned.
CkFtp2_put_ListPattern $ftp "*.asp"
set n [CkFtp2_GetDirCount $ftp]
if {$n < 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
if {$n > 0} then {
for {set i 0} {$i <= [expr $n - 1]} {incr i} {
# Display the filename
puts [CkFtp2_getFilename $ftp $i]
# Display the file size (in bytes)
puts [CkFtp2_GetSize $ftp $i]
puts "--"
}
}
set success [CkFtp2_Disconnect $ftp]
delete_CkFtp2 $ftp