Automatic Publication at Scheduled Times (Cron job)

The jDownloads automatic monitoring can be started at a time schedule with a 'Cron job'. 
The most likely situation is that you have allowed various users to upload files into the relvant directory (category) and these need to become Downloads.  But you do not want to grant access to the backend to allow those users to run the monitoring.  Another situation is that you need to publish a large number of download files.  These could have been setup on a test site and now you want to upload and publish them.

Transfering a large number of files (downloads) in a directory structure (category structure) from your PC to your website is readily achieved using your favourite ftp program such as FileZilla.  These downloads, and possibly new categories, will need creating into Downloads and publishing.

Before doing anything else if you want to enable monitoring and to allow automatic publication you need to look at the settings in the Monitoring section of the jD Options.  These include Download directory monitoring?Monitor all file types?Monitor only the following file types and Automatically publish Downloads?  So set those up first to suit your current needs.  For example if you as the administrator are initially copying over  large number of files you probably would set "Automatically publish Downloads?" to Yes.  But later if you open it up to some general users then you may wish to review each Download before publishing it by setting "Automatically publish Downloads?". to No.  That is set it to whichever way suits your current needs.

However you are strongly recommended to set Download directory monitoring? to No.  If you leave it at Yes then there may be a fight between the jD automatic monitoring and the cron initiated monitoring.  It is not a good idea to have two 'scan' processes runing at the same time, they could both be actioning the same file with unknown consequences. So set it to No to avoid that possibility.

jDownloads provides facilities to automate the publication process.  One of them is to activate the Automatic Monitoring in the Monitoring section of the Configuration.  This actually runs every time you access the jDownloads control panel in the backend.  If you have a large number of files the delay whilst monitoring is carried out can be frustrating, so this facility is often disabled. Another method is to click on the manual scan on the right hand side of the jDownloads control panel.  Both of these methods require that you are actually present and accessing the jDownloads control panel.

This is not always convenient. A solution is to have the scanning scheduled to run periodically or at some fixed time from your web site services.  Such a facility is often referred to as a 'Cron job'. This could be from your web site if you have a Cpanel web site.  Or  it could be from a web based cron service.  A third alternative is  to use a 'psuedo' cron service provided by the Joomla! extension XTCronjob, which is also known by its former name JPrc Cronjobs.

Whichever way you choose you will need the relevant url link. This may be found by copying the link from the 'Check Download area now' on the   jD Control Panel.  The  link will be something like the following.


where the key part is unique to your specific  site.  This secret key is the one created by Joomla! for your site.  It may be found in the Joomla! System - System Information - Configuration tab. Scroll down until you find the Secret key.  It is usually a 32 character sequence such as for example say 'stoAs118BoemlusWO1mlaxoesPl9wrlU' - the one shown is artificial and not real.  jDownloads compares the key you supply with the one in your Joomla! configuration file so that no one else can initiate a Cron on your site.

Using cPanel Cron job
Most cPanel implementations have an Advanced section with a Cron job icon. These notes apply to cPanel version 54.0 (build 22) but all recent versions are similar.
After clicking on the Cron Job icon a screen such as opposite appears. The cPanel has the ability to send an email every time the cron job runs.  You just  put in your email address into the appropriate field. If you leave it blank then no emails are sent.  If you have  multiple cron jobs there is a way of seclectively setting which  cron jobs will not send an email.
The email sent is a full html page that is the same text mixed with html tags as would have been generated if you had run the scan process  manually from the jD control panel.

As is obvious from the picture opposite setting up the schedule times for the cron to run is reasonably simple.  The easiest to use is the common settings which can be readily adjusted in the  individual time parts.  In the example shown opposite the schedule is twice a day at 00 and 12:00 on every day.   One could edit the hour part to say 1 and 5 to give an unequal spacing.
The Command part is simply
where your-key is the Joomla! Secret key specific to your site (see System - Site Information - Configuration tab Secret field), and the <your_site> is replaced by as appropriate.

After clicking on the 'Add New Cron Job' button a line appears something like opposite.
The resultant schedule and command are quite obvious.  Importantly one is able to edit the 'cron line' to change say the schedule.  For initial testing setting I set the cron job to run every five minutes with just a few files.  It was then edited to run just twice a day.
If the cron job does not run then you should initially check with yout host site provider as they may have imposed some restricions such as a minimum time interval.

Joomla! Extensions for Cronjobs
At the time of writing there are no 'self-contained' cron job  Joomla! extensions.  There are some that are incorporated in other applications, for example Komento.

Web based Cron Job
Another alternative is to use a web based cron service.  There are a whole host of services, many free.  To find some try searching with a phrase like 'cron services'. 

They just need to know the url of the jDownloads scan software and of couse the frequency at which a scan is to occur.

Some free ones require you need to renew every month.  But there are others such as  that allow you permanent access. Setup is simple as illustrated opposite.  There are some additional options about email notification should a cron job fail.
cron job02

Background Notes
Any Cron job consists of two parts: the scheduling time string, and the command which eventually get combined.

The time string is made up of 5 items specifying: minutes, hours, days, months and weekdays.  The syntax is five space separated 'values'; but the values not always obvious! Some examples are given below but if you want to determine other time strings then you could look at .   All times are usually UTC based so you may need to take that into account.

Time string  */30 4 * * * would cause execution every day at 4:00 and 4:30.
Time string     3 4    * * * is once a day at 4:03 am
Time string  */20 * * * * is every 20 minutes

The general structure of the command part for use with jDownloads is the unix command: "curl -s /dev/null https://websitename/script-name"
Specifically something like:
curl -s /dev/null  https://<your_site>/jda1/administrator/components/com_jdownloads/helpers/scan.php?key=qwertySS1zW0kIdQ1VZ7xxxyyy
which also includes the Secret key specific to your site as described above. The  key shown is  of course not a real one!

Colin Mercer July 2019

Print Email

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.