Free Programming E-Books
Free download ebooks on computer and programming

Free ebook "Real World .NET Applications" Sample Chapter

Real World .NET Applications
Free download chapter 5: Developing an FTP Client Application
Download chapter

Real World .NET Applications consists of six significant .NET applications, each representing one of the major application types: a custom Windows control, an XML document editor, a Pac-Man-style game, a drawing application, an FTP client application, and an ASP.NET online store. Each application or component is thoroughly documented, starting from coverage of the underlying principles through the architecture and design, and finally the actual implementation of the application.

< < prev next > >

Developing an FTP Client Application

FILE TRANSFER IS an important networking task, and File Transfer Protocol (FTP) client applications are still in wide use despite the ever-increasing popularity of the Web. The FTP client application built for this chapter complies with the current standard as specified in RFC959 by the World Wide Web Consortium (www.w3.org); you can use it to connect to and engage in file transfer with standard FTP servers. The main purpose of developing this application is to show how to work with sockets in the .NET Framework.

Overview of the Chapter

This chapter starts by presenting a general overview of sockets and continues with FTP and the project itself. In this chapter, you will find the following sections:

  • "Working with Sockets": This section introduces sockets and explains how to use the System.Net.Sockets.Socket class and other related classes for network programming.
  • "Understanding FTP": This section discusses the protocol for file transfer as specified in RFC959.
  • "Creating an FTP Application Step by Step": This section covers a simple console application that is similar to the ftp.exe program included in the UNIX/Linux or Windows operating systems. This serves as an introduction to the chapter's FTP project.
  • "Implementing the Project": This section contains a detailed discussion on the FTP client application with a Graphical User Interface (GUI).

Working with Sockets

A socket is an end point of a connection. It is a descriptor that lets an application read from and write to the network. Using sockets, client applications and server applications can communicate by sending and receiving streams of bytes over connections. To send a message to another socket used in a software application, you need to know not only the machine's Internet Protocol (IP) address that hosts the software application but also the software's process identifier in that machine. A unique number, called a port, identifies a software process in a machine. Therefore, to send a message from a socket in one application to another socket in another connection, you need to know the machine's IP address and the application's port number.

In the .NET Framework, the System.Net.Sockets.Socket class represents a socket. This class is an implementation of the Sockets Application Programming Interface (API), which is also known as the Berkeley sockets interface. The Sockets API was developed in the early 80s at the University of California at Berkeley for the 4.1c release of Berkeley Software Distribution (BSD) Unix. This distribution contained an early version of the Internet protocols.

You can use the System.Net.Sockets.Socket class as a socket in a server application as well as in a client application. It also allows both synchronous and asynchronous operations. This chapter only covers using the Socket class in a client application. For more details on using this class in a server application, you should consult the .NET Framework documentation.