The CFFTP tag includes extensive support for FTP operations. However, all remote file access requires interaction with the local drive. For example, if you want to retrieve and parse an XML file, you have to get the file and save to disk, then use cffile to load it into memory, and finally parse it. All this extra disk access takes unnecessary time.
Since CFMX is now Java based, we can take advantage of the Java network library to perform this same action without disk access.
The following code grabs a file from a local FTP site and displays it on screen.
s = "";
jUrl = createObject("java", "java.net.URL");
jUrl.init("ftp://127.0.0.1/temp/test.xml");
inStream = jUrl.openStream();
inRead = createObject(
"java",
"java.io.InputStreamReader");
inRead.init(inStream);
bufRead = createObject(
"java",
"java.io.BufferedReader");
bufRead.init(inRead);
#s#
I haven’t tried it but you should be able to specify the username and password within the url as in “ftp://username:password@hostname/path/filename”.
How about writing a UDF out of this and submitting it to cflib.org?
I’ll wrap it up and submit it to return the file as a string.
Know what would be even cooler? Make the UDF take any string. If you pass http or ftp whatever, it makes a http or ftp request. If you pass anything else, it considers it a local file path.
The code will accept http:// right now, but in that respect it doesn’t have any real advantage over CFHTTP. Similar situation with local files, the change would be simple, but it wouldn’t have any real benefit over CFHTTP. Since it’s a CFScript implementation it would probably be slower than CFHTTP/CFFILE.
What do you think?
Actually, I wouldn’t assume it would be much slower. At the same time, I’m probably making this way more complex then it needs to be.
Hello there,
Iwas browsing the web and found this blog. Some interesting quotes. Keep them coming!
Alice
fast weight loss with propylene
Welcome Home Everyone Home
Cya
Max
Hi Guys
Thanks for taking the time posting. MSN have finally launch blogs, what was with the delay?
Call Centres Solutions
Cya
Bruce