Click here to Skip to main content
15,894,017 members
Articles / Programming Languages / C#

Console FTP in C#

Rate me:
Please Sign up or sign in to vote.
3.78/5 (17 votes)
7 Mar 20043 min read 224.7K   3K   46  
A basic FTP client in C#.
using System;

namespace HB.Web.Pop3
{
	/// <summary>
	/// Represents a message on a Pop3 server.
	/// </summary>
	public struct Message : IComparable
	{
		/// <summary>
		/// Creates a new Pop3 server message.
		/// </summary>
		/// <param name="id">The ID of the pop3 message.</param>
		/// <param name="length">The length of the pop3 message.</param>
		/// <exception cref="ArgumentNullException">When parameter id is null.</exception>
		public Message(string id, long length)
		{
			if(id == null)
				throw new ArgumentNullException("id");
			this.id = id;
			this.length = length;
		}

		/// <summary>
		/// Gets the length in bytes of the message.
		/// </summary>
		public long Length
		{
			get
			{
				return length;
			}
		}

		/// <summary>
		/// Gets the unique ID of the message.
		/// </summary>
		public string Id
		{
			get
			{
				return id;
			}
		}

		/// <summary>
		/// Compares the current instance with another <see cref="Message"/>.
		/// </summary>
		/// <param name="obj">An <see cref="Object"/> to compare.</param>
		/// <returns>A 32-bit signed integer that indicates the relative order of the comparands.</returns>
		/// <exception cref="ArgumentException">When parameter obj is not the same type as this instance.</exception>
		/// <remarks>The <see cref="ID"/> is compared.</remarks>
		public int CompareTo(object obj)
		{
			if(!(obj is Message))
				throw new ArgumentException("obj is not the same type as this instance.");
			return Id.CompareTo(((Message)obj).Id);
		}

		/// <summary>
		/// Returns the <see cref="ID"/> of the <see cref="Message"/>.
		/// </summary>
		/// <returns>The <see cref="ID"/> and <see cref="Length"/> of the <see cref="Message"/>.</returns>
		public override string ToString()
		{
			return Id + " " + Length;
		}

		/// <summary>
		/// Determines if this instance of <see cref="Message"/>
		/// is equal to another object.
		/// </summary>
		/// <param name="obj">The object to compare.</param>
		/// <returns>true if parameter obj is of type <see cref="Message"/>
		/// and equal to the this instance.</returns>
		public override bool Equals(object obj)
		{
			return ((obj is Message) && (this == (Message)obj));
		}

		/// <summary>
		/// Determines if two instances of type <see cref="Message"/>
		/// are equal to each other.
		/// </summary>
		/// <param name="lhs">A <see cref="Message"/> to compare.</param>
		/// <param name="rhs">A <see cref="Message"/> to compare.</param>
		/// <returns>true if both objects are of type <see cref="Message"/>
		/// with the same <see cref="Id"/>.</returns>
		public static bool operator ==(Message lhs, Message rhs)
		{
			if(((object)lhs == null) && ((object)rhs == null))
				return true;
			if(((object)lhs == null) || ((object)rhs == null))
				return false;
			return lhs.Id == rhs.Id;
		}

		/// <summary>
		/// Determines if two instances of type <see cref="Message"/>
		/// are not equal to each other.
		/// </summary>
		/// <param name="lhs">A <see cref="Message"/> to compare.</param>
		/// <param name="rhs">A <see cref="Message"/> to compare.</param>
		/// <returns>true if the objects are not equal.</returns>
		/// <remarks>Negates the result of the equals operator.</remarks>
		public static bool operator !=(Message lhs, Message rhs)
		{
			return !(lhs == rhs);
		}

		private string id;
		private long length;
	}
}

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

Comments and Discussions