FTP Download Into String Variable
Demonstrates how to download a file on a remote FTP server directly into a string variable.
<HTML>
<HEAD>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=utf-8">
<TITLE>FTP Download Into String</TITLE>
</HEAD>
<BODY>
<%
' Create an FTP object
set ftp = Server.CreateObject("Chilkat_9_5_0.Ftp2")
' Any unlock code begins the 30-day trial
ftp.UnlockComponent "anything"
ftp.Username = "***"
ftp.Password = "***"
ftp.Hostname = "ftp.chilkatsoft.com"
ftp.KeepSessionLog = 1
ok = ftp.Connect()
if (ok <> 1) then
Response.Write ftp.LastErrorHtml
else
ok = ftp.ChangeRemoteDir("xml-samples")
' Normally you would check to make sure ok = 1
' Download a file from the FTP server.
remoteFilename = "pigs.xml"
xmlStr = ftp.GetRemoteFileTextData(remoteFilename)
if Len(xmlStr) = 0 then
Response.Write "<pre>"
Response.Write ftp.LastErrorText
Response.Write Server.HtmlEncode(ftp.SessionLog)
Response.Write "</pre>"
else
' xmlStr is a string containing the contents of the remote file.
' Load it into the Chilkat XML object and list the pigs by name:
set xml = Server.CreateObject("ChilkatXml.ChilkatXml")
xml.LoadXml(xmlStr)
' Loop over the <animal> nodes in the XML document, displaying the <name> of each.
xml.FirstChild2()
do
if xml.Tag = "animal" then
Response.Write xml.GetChildContent("name") & "<br>"
end if
loop while xml.NextSibling2()
xml.GetParent2()
end if
end if
Set ftp = Nothing
%>
</BODY>
</HTML>
|