DataFlex
DataFlex
Control How FTP Directory Listings Are Requested
See more FTP Examples
Demonstrates the AllowMlsd, PreferNlst, and ListOption properties, which control which listing command Chilkat uses and what options it passes.
Background: FTP has three listing commands with different trade-offs.
MLSD is machine-readable and standardized, so AllowMlsd (on by default) prefers it when the server supports it. When it must fall back to the legacy commands, PreferNlst chooses names-only NLST over the fuller LIST, and ListOption appends flags such as -a (to include hidden files) literally to LIST. Together they adapt listing to a particular server's capabilities and conventions.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFtp
Integer n
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatFtp2)) To hoFtp
If (Not(IsComObjectCreated(hoFtp))) Begin
Send CreateComObject of hoFtp
End
Set ComHostname Of hoFtp To "ftp.example.com"
Set ComUsername Of hoFtp To "myFtpLogin"
// AllowMlsd (default True) requests machine-readable MLSD listings when the server advertises
// support. MLSD is preferred because its format is standardized.
Set ComAllowMlsd Of hoFtp To True
// PreferNlst (default False) chooses NLST over LIST when a legacy listing is needed and MLSD is
// unavailable. NLST returns only names.
Set ComPreferNlst Of hoFtp To False
// ListOption is appended literally to a legacy LIST command; "-a" sends "LIST -a" to include
// hidden files on Unix servers.
Set ComListOption Of hoFtp To "-a"
// 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.
Set ComPassword Of hoFtp To "myPassword"
Get ComConnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComGetDirCount Of hoFtp To n
Showln "Entries: " n
Get ComDisconnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure