Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Database

Synchronize Now!


Eric has developed everything from data-reduction software for particle bombardment experiments to software for travel agencies. He can be contacted at [email protected].


There are several files I need to access and update from practically any computer I use—my web browser favorites, contact lists, web-site passwords, and my .NET programming tips. Although I keep these files on a flash drive, it's not always convenient to take the drive everywhere I go. I'd rather store the files on a server and access them over the Internet, as long as it's reliable, secure, and inexpensive. Xdrive.com offers 5 GB of Internet-accessible storage, but the $10.00 monthly fee is more than I pay for hosting my entire web site. Fortunately, Amazon's S3 web service offers secure Internet file access at modest prices. Additionally, .NET 2.0's FtpWebRequest class offers access by programs to FTP sites. In this article, I show how to use S3 and FtpWebRequest to securely synchronize files on multiple machines.

To illustrate, I use Visual Studio 2005 to develop a sample application named "Synchronize Files" (available at http://www.ddj.com/code/). You can build it with Visual Studio 2005 or Visual C# 2005 Express Edition (http://msdn.microsoft.com/vstudio/express/visualcsharp). This program encrypts files for security, and compresses them to conserve bandwidth and storage space. It takes advantage of the Microsoft Enterprise Library for cryptography, logging, and exception management.

Building and Running The Sample App

The sample app uses the Cryptography, Exception Handling, and Logging "Application Blocks" from the January 2006 Microsoft Enterprise Library for .NET Framework 2.0. Before building the app, download the Enterprise Library (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/entlib2.asp) and run the install. After installing the library, specify an encryption key to encrypt/decrypt your files. To specify your key, first ensure the sample app's app.config file is writable. Run the Enterprise Library Configuration program. Select File/Open Application and open the sample app's app.config file. Right-click the Symmetric Provider on the left and select Remove. Then right-click Symmetric Providers and select New/Symmetric Algorithm Provider. Select RijndaelManaged and press OK. Make sure the Create a New Key radio button is selected, then click Next. Click the Generate button, then Next. Specify the key file path and press Next. Specify the data-protection mode and press Finish. On the right, change the Name from "RijndaelManaged" to "Symmetric Provider," which is the name the sample app expects. Finally, select File/Save Application.

Now it's time to build the app. Open SynchronizeFiles.sln in Visual Studio 2005, build the app, and run it. Select Options/Settings and select the S3 or FTP radio button to specify where your files will be stored. If you're using S3, enter the Access Key ID and Secret Access Key you received when signing up. Then press Get Canonical User ID and your Canonical User ID and Display Name is filled in. For an FTP site, first use an FTP program to create a folder on the FTP site for your home directory. Then go back to Synchronize Files and enter the FTP site (ftp://upload.comcast.net, for instance), the home directory you created, and your User ID and Password.

After entering your configuration information, press OK. Click the New button to create a bucket (folder) to hold your files. Then click Upload to upload your files. When files are selected by checking the checkbox in the DataGridView's leftmost column (Figure 1), they can be downloaded or deleted. When you press the Synchronize button, all files with a check in the Synchronize column are uploaded to the server if they've changed on the local machine.

[Click image to view at full size]

Figure 1: Synchronize files.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.