Click here to Skip to main content
Click here to Skip to main content

C# WebCam Service with FTP and Installer

, 31 Mar 2003
Rate this:
Please Sign up or sign in to vote.
C# WebCam Windows Service with FTP upload, Windows Service Installer, and file rotation.

Introduction

I got tired looking for an app to write a snap shot from my camera to disk; that was free, no ad ware and with no advertising on the image. I found a guy who wrapped the DirectX Library in C# - WHAT A CHAMP! Here's a link to his article. Anyway, he has a full library called DShowNET and I called into that, made a Windows service that always runs when my PC is on. I added a full FTP library that is extended from the work by Jaimon Mathew.

Overview

This package comes as a project and a DLL (DShowNET). It has the following files:

  • WebCamService.cs
  • FtpClient.cs
  • Capture.cs
  • WebCamInstaller.cs

Now, using the DShowNET library is a little tricky, and just to get a photo out of the web cam tool some 400 lines of code are required. I extended the Sample Grabber supplied with DShowNET and added the reset event so that the photo could be taken synchronously.

The worst problem was making it stable, but this has been running on my workstation now for 20+ days without a restart. The most important code for stability is in the CloseInterfaces method - note the extensive try/catches - everything must be cleaned up, otherwise strange errors (including blue screens) will be observed.

The FTP library I extended, so I could use it as a full featured FTP client. I have added it to this project so I can upload files to the server.

Requirements

  • DirectX 8.1
  • .NET Framework
  • Visual Studio .NET (if you plan to edit it of course)
  • A Windows OS that supports Windows Services (2K,XP)
  • Any DirectX supported Video in device (Tuner, Capture, Camera etc...)
  • 5 Minutes of your time

Setup

The Installer component is used to install the service with the command:

C:\>installutil.exe D:\projects\webcam\webcamservice\bin\debug\webcamservice.exe

You will also need to edit the config file to reflect your needs:

<add key="path" value="D:\Projects\WebCamService\out\WebCam.jpg"/>
<add key="CaptureCycleSeconds" value="10"/>
<add key="KeepOldImageCount" value="20"/>
<add key="FtpServer" value="???"/>
<add key="FtpUserName" value="???"/>
<add key="FtpPassword" value="???"/>
  • path is where you wish to upload the picture to.
  • CaptureCycleSeconds is how long to wait before taking another photo (add in capture time to 11+ seconds)
  • KeepOldImageCount is to hold the last n photos taken

The rest are pretty explanatory.

Now you cans start and stop the service with the following commands:

net start WebCamService
net stop WebCamService

The service will run in the background, and be started when your machine boots, NOT when you login.

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

Share

About the Author

Dan Glass
Architect support.com
Australia Australia

Comments and Discussions

 
GeneralThank you Dan! PinmemberMember 105806974-Aug-14 21:01 
Questionplease help me quickly to send image to my web site quickly Pinmemberhansalsal23-Feb-11 22:36 
GeneralLicense PinmemberRocky11388-Jun-10 18:29 
GeneralRe: License PinmemberApple Lam29-Aug-10 17:11 
GeneralCapture video Pinmemberdzango23-Mar-10 4:40 
GeneralJust works with the first shoot, (looking deeper than other comments) [modified] Pinmemberjoputaidilico31-Mar-08 4:29 
Questionmemory leak? Pinmemberjgerdes19-Oct-07 12:04 
GeneralWebcam captures exactly one image, BOMBS on second PinmemberPeter {faa780ce-0f0a-4c28-81d2-3667b71287fd}14-Apr-07 13:49 
GeneralFtpClient class Runs once then fails Pinmemberalanmcq13-Mar-07 1:02 
Question.NET 2.0 work PinmemberWarrenHuisman1-Sep-06 14:43 
GeneralAnother slight modification to the FTPClient PinmemberSteveDT12323-Jun-06 7:10 
GeneralIntegrate with the Motion Dectection [modified] Pinmembersyd kahn7-Jun-06 3:43 
Generalonly run once ? when i restart the service it will run again but once PinmemberMastarezma25-May-06 5:23 
GeneralRe: only run once ? when i restart the service it will run again but once Pinmemberdakdog32025-May-06 10:10 
GeneralRe: only run once ? when i restart the service it will run again but once PinmemberMastarezma25-May-06 14:13 
GeneralRe: only run once ? when i restart the service it will run again but once Pinmemberkarande2330-May-06 21:23 
GeneralRe: only run once ? when i restart the service it will run again but once Pinmemberp3kurwud13-Aug-06 9:16 
GeneralSet Resolution Pinmemberdoomsday32911-May-06 8:34 
Generalnot able to run the application Pinmemberketulvinayshah12-Apr-06 21:38 
GeneralImage Size Pinmembermnlux12-Mar-06 16:27 
GeneralRe: Image Size Pinmemberdoomsday32911-May-06 8:03 
QuestionHowto change FrameSize? Pinmemberclemens8120-Jan-06 10:10 
QuestionDamn this so nearly works... PinmemberFelixWatts21-Dec-05 8:31 
AnswerRe: Damn this so nearly works... PinmemberMartijn Stegeman13-Mar-06 5:49 
Jokeerror in errorlog .... Pinmembercodemanloyd2-Dec-05 6:20 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 1 Apr 2003
Article Copyright 2003 by Dan Glass
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid