PowerBuilder
PowerBuilder
Get FTP Filenames as XML (NLST)
See more FTP Examples
Demonstrates the Chilkat Ftp2.NlstXml method, which sends NLST and returns the matching names in XML form. The only argument is appended literally; an empty string sends a bare NLST and a value like *.txt sends NLST *.txt.
Tip: Code to parse the returned XML can be generated at Chilkat Tools.
Background:
NLST is the lightweight listing command: it returns only names, with none of the sizes, dates, or type information that LIST provides. That makes it fast and simple when a bare list of filenames is all you need — for example to drive a batch of downloads. Wrapping the result as XML gives you a clean, uniform structure to iterate regardless of how the server formats the raw NLST reply.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ftp
string ls_Xml
li_Success = 0
// Demonstrates the Ftp2.NlstXml method, which sends NLST and returns the matching names in XML
// form. The only argument is appended literally; an empty string sends a bare NLST.
loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
destroy loo_Ftp
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.Username = "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.
loo_Ftp.Password = "myPassword"
li_Success = loo_Ftp.Connect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
li_Success = loo_Ftp.ChangeRemoteDir("public_html")
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
// NLST returns names only (no sizes, dates, or types). "*.txt" sends NLST *.txt.
ls_Xml = loo_Ftp.NlstXml("*.txt")
if loo_Ftp.LastMethodSuccess = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
Write-Debug ls_Xml
li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
return
end if
destroy loo_Ftp