Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / XML
Article

.NET WebScheduler for scheduled downloading of web sites and files through HTTP and FTP

Rate me:
Please Sign up or sign in to vote.
3.36/5 (8 votes)
28 Oct 20052 min read 70.9K   1.7K   41   12
An article describing a ScheduledTask class for writing a WebScheduler application, for example a Windows Service.

Introduction

Ever wanted to create a web application that sends reminder e-mails every week? Or that cleans up a remote images or articles folder? Or to backup a certain FTP folder every night or week? This document describes a ScheduledTask class written by David van Leerdam for use in (for example) a Windows Service that you can run to accomplish these tasks for you.

Background

When you're hosting your own applications, scheduling events for your web server is not a real challenge. But it is an issue when your (for example, ASP.NET or PHP) application is hosted by a third party which does not allow running of home grown timers, schedulers, Windows Services etc. A possible solution is to run the (web) scheduler on a remote machine, for example, a machine at home or at the office, which is always online. This is also great for remotely creating backups of websites through FTP.

Using the code

The solution consists of two parts:

  1. An application, a Windows Service (or whatever) that references the WebScheduler assembly (see downloads).
  2. The WebScheduler assembly containing the ScheduledTask class.

For part 1, I assume you will be creating a Windows Service (see downloads for sample code). All the code my Windows Service contains is:

VB
Protected Overrides Sub OnStart(ByVal args() As String)
    Try
        sites = ScheduledTask.GetAll()
        For i As Integer = 0 To sites.Count - 1
            Dim st As ScheduledTask = sites(i)
            st.Start()
        Next
    Catch ex As Exception
        EventLog.WriteEntry("WebScheduler", _
          "An exception occurred. " & ex.ToString())
        Return
    End Try
End Sub

Protected Overrides Sub OnStop()
    Try
        For i As Integer = 0 To sites.Count - 1
            Dim st As ScheduledTask = sites(i)
            st.Cancel()
        Next
    Catch ex As Exception
        EventLog.WriteEntry("WebScheduler", _
          "An exception occurred. " & ex.ToString())
        Return
    End Try
End Sub

The result of the GetAll() method is an ArrayList containing all the tasks defined in the config file.

Tasks are defined using a config file (currently hard coded to reference c:\WebScheduler.config). This example contains a task definition for creating a backup of mydomain.nl every night at 0:45 A.M.:

XML
<?xml version="1.0" encoding="utf-8" ?>
<config>
    <tasks>
     <task id="ftp.mydomain.nl"
        url="ftp://ftp.mydomain.nl/"
        scheduledFor="everyDay"
        startTime="00:45:00"
        saveTo="c:\backup\websites\mydomain.nl\"
        recursive="true">
            <credentials
            username="davidl"
            password="p4ssw0rd" />
     </task>
    </tasks>
</config>

Note that any configured path to a folder (i.e. not a file) needs to end with '\'. This is applicable to both local and remote paths.

Points of Interest

A few changes are required to make this component more reliable:

  • What happens when the config file is updated while a task is being executed is to be researched.
  • Further attempts should be made when a request or a complete task fails.

All suggestions, bug reports, code updates, refactorings etc. are welcome. Please leave me a message at the bottom of this page so that I can update the article.

Consuming application

I will keep a list of applications that consume this component or parts of it. Please leave me a message so that I can list your application!

  • My own SchedulingService application, see downloads.

History

  • 19 October 2005: Updated the article with version 0.2 of the code. Some major changes include a better FTP component (version 1.2.2 of edtFTP.NET), config format adjustments, and bug fixes. Minor adjustments where made in terms of performance and refactoring.
  • 1 February 2005: Posted the article with version 0.1 of the code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Netherlands Netherlands
I am a .NET developer for a large European IT consultancy company.

Comments and Discussions

 
Questionhow do i set this up on my local machine? Pin
FlipsideDevelopments14-Sep-08 23:25
FlipsideDevelopments14-Sep-08 23:25 
QuestionHow to implement in my application. Pin
Umesh87383-Mar-08 19:45
Umesh87383-Mar-08 19:45 
Generalcopy of new version Pin
ninja_scroll22-Aug-07 23:56
ninja_scroll22-Aug-07 23:56 
Generalcould u pls send me the latest update Pin
ravi kanthi24-Jun-07 18:35
ravi kanthi24-Jun-07 18:35 
GeneralAn update on the article/project's progress [modified] Pin
David van Leerdam8-Sep-06 3:38
David van Leerdam8-Sep-06 3:38 
General[Message Removed] Pin
Mojtaba Vali26-Oct-05 10:10
Mojtaba Vali26-Oct-05 10:10 
GeneralRe: opensource Pin
David van Leerdam26-Oct-05 20:08
David van Leerdam26-Oct-05 20:08 
GeneralUnable to Download source code Pin
PSK_1-Jun-05 22:24
PSK_1-Jun-05 22:24 
GeneralRequest Pin
Phaniraz14-Feb-05 19:46
Phaniraz14-Feb-05 19:46 
GeneralRe: Request Pin
Anonymous14-Feb-05 21:49
Anonymous14-Feb-05 21:49 
GeneralRe: Request Pin
Anonymous15-Feb-05 0:42
Anonymous15-Feb-05 0:42 
GeneralRe: Request Pin
Anonymous15-Feb-05 4:40
Anonymous15-Feb-05 4:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.