Click here to Skip to main content
15,886,799 members
Articles / Desktop Programming / Windows Forms

Windows Vista Sidebar Gadget and Standalone :: FTP-BOX

Rate me:
Please Sign up or sign in to vote.
2.50/5 (3 votes)
30 Mar 20072 min read 48.7K   901   24  
Simple FTP Client
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.IO;

namespace DSn.FtpBox.Objects
{
  public class Ftp
  {
    public event EventHandler<DoDownloadEventArgs> DoDownload;
    public event EventHandler<DoUploadEventArgs> DoUpload;
    public event EventHandler<DoListEventArgs> DoList;
    public event EventHandler DoConnect;
    public event EventHandler DoDisconnect;

    public event EventHandler SettingsChanged;
    private void OnSettingsChanged(EventArgs e)
    {
      if (SettingsChanged != null) SettingsChanged(this, e);
    }

    private FtpSettingsData ftpData;
    public FtpSettingsData FtpData
    {
      get { return ftpData; }
      set
      {
        ftpData = value;
        OnSettingsChanged(new EventArgs());
      }
    }

    public void Upload(FtpFile ftpFile, string source)
    {
      if (DoUpload != null) DoUpload(this, new DoUploadEventArgs(ftpFile, source));
    }

    public void Download(FtpFile ftpFile, string target)
    {
      if (DoDownload != null) DoDownload(this, new DoDownloadEventArgs(ftpFile, target));
    }

    public List<FtpFile> List()
    {
      DoListEventArgs e = new DoListEventArgs();
      if (DoList != null) DoList(this, e);
      return e.Result;
    }

    public void Connect()
    {
      if (DoConnect != null) DoConnect(this, new EventArgs());
    }

    public void Disconnect()
    {
      if (DoDisconnect != null) DoDisconnect(this, new EventArgs());
    }

    public event EventHandler<DoDeleteEventArgs> DoDelete;
    public void Delete(FtpFile ftpFile)
    {
      if (DoDelete != null) DoDelete(this, new DoDeleteEventArgs(ftpFile));
    }

    public class ProgressEventArgs : CancelEventArgs
    {
      private readonly FtpFile ftpFile;
      public FtpFile FtpFile
      {
        get { return ftpFile; }
      }

      private readonly int progress;
      public int Progress
      {
        get { return progress; }
      }

      public ProgressEventArgs(FtpFile ftpFile, int progress)
      {
        this.ftpFile = ftpFile;
        this.progress = progress;
      }
    }
    public event EventHandler<ProgressEventArgs> Progress;
    public bool OnProgress(FtpFile ftpFile, int progress)
    {
      ProgressEventArgs e = new ProgressEventArgs(ftpFile, progress);
      if (Progress != null) Progress(this, e);
      return e.Cancel;
    }
  }
}

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 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
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions