Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Files uploaded via FTP vs CMS


Go to End


5 Posts   2210 Views

Avatar
Rod

Community Member, 12 Posts

29 August 2011 at 12:12pm

HI there,

I have noticed that Silverstripe will not 'know about' files that are uploaded via the FTP until I 'look for new files' in the Files & Images tab of the CMS.

Is there a way to change this behavior?

The reason is that we have a process that automatically/periodically creates some files (exe's and tar.gs's) and uploads them to a folder under 'assets'. I'd like these to instantly be available on the web front end. i.e. I want to eliminate this step of having to log into the CMS and 'looking for new files' every time I add or remove a file through the FTP via the automated process.

Any ideas?

Thanks
Liam

PS, here is a sample of my code in case it is useful...

Page.php file has a nuber of functions within the Page class that looks for these files, e.g.:

function GetTheFiles() {
	   return DataObject::get(
	      $name = 'File',
	      $filter = "ClassName = 'File' and Filename like 'assets/subfolder/subfolder2/%-nz-win-%'",
	      $sort = "Name ASC",
	      $join = "",
	      $limit = "4"
	   );
	}

And the Page.ss template then displays them, e.g.:

<% control GetTheFiles %>
  <li class="win"><a href="$URL">$Title</a></li>
<% end_control %>

Avatar
MarcusDalgren

Community Member, 288 Posts

29 August 2011 at 1:24pm

Setup a custom controller action that runs the check for new files function and then call that periodically with a cron script. Since all files ss recognizes have to be either the file class or a subclass thereof a script needs to run to check.

Avatar
Rod

Community Member, 12 Posts

29 August 2011 at 1:29pm

Thanks Smurkas. That sounds like it would work..... I don't suppose you could post some sample code?? :-)

Thanks
Liam

Avatar
Rod

Community Member, 12 Posts

1 September 2011 at 2:31pm

Edited: 01/09/2011 2:32pm

I solved this problem.

Within Page.php's controller:

public function FileSync() {
	return FileSystem::sync();
} 

Then within the template (actually, within an include used on just one page):

<% control FileSync %><% end_control %>

It unfortunately has a noticeable impact on page speed (a couple of extra seconds), but otherwise works really well. As the speed issue only affects this page, it's probably worth it, as it ensures the list of files is always up to date.

If anyone has any suggestions for improvement, please let me know! :-)

Cheers
Liam

Avatar
martimiz

Forum Moderator, 1391 Posts

1 September 2011 at 11:27pm

You could take a look at partial caching - limit execution of the sync operation to once every xx minutes...

Or even write away a timestamp, to only perform the operation once a certain amount of time has passed

I think cron would be the better option though