Solved

Cold fusion code to download files (eg Word/Excel) from an FTP/WWW Site, and offer it for download.

Posted on 2004-08-31
10
350 Views
Last Modified: 2013-12-24
First of all, is it possible for cold fusion to retrieve a file from an ftp/www site and then prompt the user to save/view that file from the brower? If so, can you provide brief code as an example. I have tried using the cfttp, cfftp and cfcontent tags to a limited degree of success. I can retrieve the file from the site, and also prompt the user to save the file, but it is usually garbled (looks like it has been converted into a string).

The reason behind this is to hide the original source of the files, as the source is protected and I do not wish the credentials to be hard coded into the link.

Thanks,
Shane.
0
Comment
Question by:Shane_Capper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 21

Expert Comment

by:pinaldave
ID: 11949486
hello,
You have two Questions
1) FTP... it works and I have done it many times... the code is simple and the best one is on the web site of macromedia.
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-p39.htm#wp1800554
There are two cat for ftp
i) you need to open connection.
ii) you need to use hte file operation of ftp..
regarding the code, if i will give you any code there will be no different then the code on web site....
2) second content is of file content...
let me show you small code for excel and you can do the same for word....
<cfquery datasource="MyDataSourceHere" name="qryAccessData">
     SELECT Field1, Field2, FieldN
          FROM AccessTable
</cfquery>
<cfheader name="content-disposition" value="inline;filename=AccessToExcelDump.xls">
<cfcontent type="application/msexcel">
<table border="1">
     <tr>
          <th>Field1</th>
          <th>Field2</th>
          <th>FieldN</th>
     </tr><cfoutput query="qryAccessData">
     <tr>
          <td>#qryAccessData.Field1#</td>
          <td>#qryAccessData.Field2#</td>
          <td>#qryAccessData.FieldN#</td>
     </tr></cfoutput>
</table>

you may not need the query and you can do it without that... also....
some things to read more about in the same line of ideas....
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20701038.html
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20918372.html

If you have any problem regarding ftp or any code problem let us know.
Regards,
---Pinal
0
 

Author Comment

by:Shane_Capper
ID: 11949541
Thanks for your quick response, but I dont think you really answered my question. I have successfully used code like yours above, but not when dealing with binary data (like a word doc). The code I was playing around with is below. It obviously doesnt work, but I'm not sure what I am doing wrong.

------------------------------------------------------------------------------------
<cfheader name="content-disposition" value="inline;file=word.doc">
<cfcontent type="application/msword">
 
<cfhttp url="http://www.webserver.com/myworddocument.doc" username="xxxxxx" password="xxxxx" port="80" method="GET" getasbinary="yes">
<cfoutput>#cfhttp.FileContent#</cfoutput>
------------------------------------------------------------------------------------
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11949564
Hello,
May be I have not answered your question...
I have not much used http...
though, I was wondering what is the error...or what is the output which you are not loooking for ...
Regards,
---Pinal.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:Shane_Capper
ID: 11949575
There is no real error message. What happens is IE prompts me to download the test.cfm page, but then complains it cant find it. Stange hey.
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11949734
just try this... for kicks... i am looking into this ... before I go to sleep ... it is pretty late here...
<meta http-equiv="Refresh" content="1;URL=download.cfm">

Just put it in the HEAD tags of your HTML document.  This will wait one second then try running download.cfm which has your CFHEADER and CFCONTENT tags.
0
 

Author Comment

by:Shane_Capper
ID: 11949751
Same thing happens. Thanks for your help, I appreciate this!
0
 
LVL 21

Accepted Solution

by:
pinaldave earned 250 total points
ID: 11949753
1)
try to use attachment instead of lnline... may be that is the error...

<CFHEADER name="content-disposition" value="attachment;filename=#filename#">
<CFCONTENT file="#filepath#" type="text/csv" deletefile="no" reset="yes">

2) have a look at this.... may be you can find something useful... Expert Anandkp has great explaination....
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20563598.html

3)
Just try to play with order...

<cfcontent type="application/vnd.ms-excel" reset="no">
<cfheader name="Content-Disposition" value="attachment;filename=export.xls">

Well this is for now... if none of this work... I think, you have bug in IE. IE 6 has bug when you write value="inline;
and IE 5.5 has bug when you write value="attachments

do not knwo what is the real reason...
Regards,
---Pinal
0
 

Author Comment

by:Shane_Capper
ID: 11949823
Thanks Pinal, I think I should be able to manage from here. You've given me a few options that I think will do the trick. You have the points.

Shane.
0
 

Author Comment

by:Shane_Capper
ID: 11949918
Ahh, I managed to get an error out of coldfusion which should point me in the right diredction.

Error: ByteArray objects cannot be converted to strings.  
0
 

Author Comment

by:Shane_Capper
ID: 11959673
For those interested, final working code below.

--------------------------------------------------
<cfsetting enableCFoutputOnly = "Yes">
<cfsilent>
<cfhttp url="http://www.webserver.com" username="myusername" password="mypassword" throwOnError="yes" port="80" method="GET" getasbinary="yes">
<cfheader name="content-disposition" value="attachment;filename=word.doc">
<cfcontent type="#cfhttp.mimetype#">
</cfsilent>
<cfscript>writeOutput(toString(cfhttp.filecontent));</cfscript>
--------------------------------------------------

Thanks Pinal! All credit to you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question