Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#

FtpPublisher, An FTP File Synchronization Tool

Rate me:
Please Sign up or sign in to vote.
4.24/5 (5 votes)
12 Oct 2006CPOL3 min read 84K   4.2K   55  
A small utility that will upload changed files to an FTP site
using System;
using System.Collections.Generic;
using System.Text;

namespace FilePublisher
{
    public class Configuration
    {
        string host;

        public string Host
        {
            get { return host; }
            set { host = value; }
        }

        string user;

        public string User
        {
            get { return user; }
            set { user = value; }
        }
        string pass;

        public string Pass
        {
            get { return pass; }
            set { pass = value; }
        }
        bool passive;

        public bool Passive
        {
            get { return passive; }
            set { passive = value; }
        }

        List<RemoteFolder> folders = new List<RemoteFolder>();

        public List<RemoteFolder> Folders
        {
            get { return folders; }
            set { folders = value; }
        }

        public void Save(string file)
        {
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Configuration));
            using( System.IO.FileStream fs = System.IO.File.Create(file))
                serializer.Serialize(fs, this);
        }

        public static Configuration Load(string file)
        {
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Configuration));
            using( System.IO.FileStream fs = System.IO.File.OpenRead(file))
                   return (Configuration)serializer.Deserialize(fs);
        }
    }

    public class RemoteFolder
    {
        string folder;

        public string Folder
        {
            get { return folder; }
            set { folder = value; }
        }

        List<Item> items = new List<Item>();

        public List<Item> Items
        {
            get { return items; }
            set { items = value; }
        }
    }

    public class Item
    {
        string path;

        public string Path
        {
            get { return path; }
            set { path = value; }
        }

        DateTime lastUpload;

        public DateTime LastUpload
        {
            get { return lastUpload; }
            set { lastUpload = value; }
        }

        public Item(){}
        public Item(string file, DateTime upload)
        {
            path = file;
            lastUpload = upload;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Canada Canada
Thomas is developer for a small service company based in the greater Vancouver area of canada. He has spent most of his time building custom c# business applications for clients.

Comments and Discussions