2

I am working on an intranet enhancement that will allow the user to open the latest instance(most recently modified or created) of a file within a given directory.

Unfortunately, the cfdirectory tag (and a few others) are blocked by the hosting provider. I essentially need to mimic the functionality of this piece of code without using cfdirectory:

<cfdirectory action="list" directory="\\SERVERABC\FILEDIR"   name="myDirectory"> 
<cfloop query="mydirectory">
<cfoutput> 
     <cfif mydirectory.dateLastModified EQ DateFormat(Now(),'mm/dd/yy')>
        <!--- ..display link to file for user to download --->
     </cfif>
</cfoutput>
</cfloop>

The FileExists() function is available. But the default ColdFusion user would not have access to all the network locations that might be available to the actual user within the application itself.

Leigh
  • 28,765
  • 10
  • 55
  • 103
user1178394
  • 83
  • 1
  • 8
  • 2
    To be honest, if they don't have sandboxing implemented and have to disable CFDirectory, you should probably find another hosting provider. You might be able to "work around" it by using Java components, but they probably block CreateObject("java") too? Hard to give you an alternative without know the full scale of disabled tags. – BKK Mar 06 '13 at 15:22
  • unfortunately, I cannot use another hosting provider. I work for a very large company that uses an internal hosting group so we are at the mercy of their discretion with what tags are blocked or not. I'm trying to find a complete list of what tags those are. – user1178394 Mar 06 '13 at 15:42
  • Tried: createObject("java", "java.io.File") --- Result: access denied (java.io.FilePermission \\SERVERABC\FILEDIR read) – user1178394 Mar 06 '13 at 15:46
  • Its kind of out there, but do you have cfexecute? you can try dir C:\ > results.txt and try to read and parse the results.txt, or could you write a .net dll that you could call that would return the info you need to CF? – steve Mar 06 '13 at 16:09
  • Just tried. Cfexceute blocked as well :( Good thought though! :) – user1178394 Mar 06 '13 at 16:28
  • 1
    Is storing this information in a database and updating it each time a change is made to the file an option? – Kevin B Mar 06 '13 at 16:46
  • does your server support any other languages? php or asp/.net etc that may not be "locked down" and can pass you back the info you need via json, xml, or something. – steve Mar 06 '13 at 16:48
  • 5
    _"I work for a very large company that uses an internal hosting group..."_ - then tell whoever you report to that (1) you don't have the tools required to do your job and (2) the internal hosting group very likely don't know what they're doing. – Peter Boughton Mar 06 '13 at 18:23
  • In the meantime, nobody has mentioned DirectoryList - have they blocked that too? (You've also not said what version of CF this is.) – Peter Boughton Mar 06 '13 at 18:25
  • Oh, and this comparison: `mydirectory.dateLastModified EQ DateFormat(Now(),'mm/dd/yy')` should probably be `DateCompare(mydirectory.dateLastModified,Now(),'d')` ? – Peter Boughton Mar 06 '13 at 18:28
  • If everything is blocked, the only other way is to keep a list of the items in the directory in code or DB. – Sharondio Mar 06 '13 at 18:36
  • If your company will not setup the correct security for you, ask them to setup an FTP account for that folder, or an FTP account and a virtual directory to that folder. You can use CFFTP to pull a directory listing along with doing other light folder/file operations. It may take a little longer, but is an alternative that they should be open to doing. – steve Mar 07 '13 at 04:19
  • Coldfusion 10 is the version. DirectoryList is also on the blocked list of tags. – user1178394 Mar 07 '13 at 17:31
  • Ok so an UPDATE on this... I was able to get all the tags unblocked for my application! So I now have full access :) Now another hurdle. The user assigned to the app pool in IIS is a local built-in account.. and thus doesn't have access to any network shares (only the folders within the actual directories on the server where the code for the app lives). So I'm going to have to get them to create a service account created and those network share permissions granted to this account, and then have it assigned to run the app pool for the site. But hey hopefully it works :) – user1178394 Mar 08 '13 at 16:29

1 Answers1

1

You need to ask your host to give you a security sandbox so you can use those tags. The only reason they couldn't do this is if they are running the CF Standard Edition, and not Enterprise. If that is the case, case you are out of luck as all file i/o tags will be unavailable. No professional CF host runs the Standard Edition.

Community
  • 1
  • 1
snake
  • 732
  • 1
  • 6
  • 11