Tcl
Tcl
Get a Raw Text Directory Listing (LIST)
See more FTP Examples
Demonstrates the Chilkat Ftp2.GetTextDirListing method, which sends a legacy LIST request and returns the server's raw textual listing. The only argument is appended literally as a server-side listing argument; an empty string lists the current remote directory.
Background: This returns exactly what the server's
LIST command produces — usually a Unix ls -l-style block, but the format is server-defined and not standardized. That makes it handy for display or debugging, but fragile to parse; prefer GetXmlDirListing or the index-based accessors when you need structured data. Since the argument is appended literally to LIST, it can carry server-specific options as well as a wildcard.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the Ftp2.GetTextDirListing method, which sends a legacy LIST request and returns
# the server's raw textual listing. The only argument is appended literally as a server-side
# listing argument; an empty string lists the current remote directory.
set ftp [new_CkFtp2]
CkFtp2_put_Hostname $ftp "ftp.example.com"
CkFtp2_put_Username $ftp "myFtpLogin"
# Normally you would not hard-code the password in source. You should instead obtain it
# from an interactive prompt, environment variable, or a secrets vault.
CkFtp2_put_Password $ftp "myPassword"
set success [CkFtp2_Connect $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
set success [CkFtp2_ChangeRemoteDir $ftp "public_html"]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
# Get the raw listing text. The format is server-defined (often Unix "ls -l" style).
set listing [CkFtp2_getTextDirListing $ftp ""]
if {[CkFtp2_get_LastMethodSuccess $ftp] == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
puts "$listing"
set success [CkFtp2_Disconnect $ftp]
if {$success == 0} then {
puts [CkFtp2_lastErrorText $ftp]
delete_CkFtp2 $ftp
exit
}
delete_CkFtp2 $ftp