Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loFtp
LOCAL n
lnSuccess = 0
loFtp = CreateObject('Chilkat.Ftp2')
loFtp.Hostname = "ftp.example.com"
loFtp.Username = "myFtpLogin"
* AllowMlsd (default 1) requests machine-readable MLSD listings when the server advertises
* support. MLSD is preferred because its format is standardized.
loFtp.AllowMlsd = 1
* PreferNlst (default 0) chooses NLST over LIST when a legacy listing is needed and MLSD is
* unavailable. NLST returns only names.
loFtp.PreferNlst = 0
* ListOption is appended literally to a legacy LIST command; "-a" sends "LIST -a" to include
* hidden files on Unix servers.
loFtp.ListOption = "-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.
loFtp.Password = "myPassword"
lnSuccess = loFtp.Connect()
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
CANCEL
ENDIF
n = loFtp.GetDirCount()
? "Entries: " + STR(n)
lnSuccess = loFtp.Disconnect()
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
CANCEL
ENDIF
RELEASE loFtp