datasheets.com EBN.com EDN.com EETimes.com Embedded.com PlanetAnalog.com TechOnline.com  
Events
UBM Tech
UBM Tech

Design Article

Guide to Embedded Systems Architecture - Part 4: Application layer networking protocol examples

Tammy Noergaard

5/10/2010 2:00 PM EDT

Pseudocode example (FTP)
The following pseudocode demonstrates a possible initial FTP connection mechanism within an FTP client application in which access control commands are transmitted to an FTP site.

FTP Client Pseudocode for access control commands USER and PASS

FTPConnect (string host, string login, string password) {

  TCPSocket s= new TCPSocket(FTPServer,21); // establishing a TCP connection to port 21 of the destination device   Timeout = 3 seconds; // timeout for establishing connection 3 seconds
  FTP Successful = FALSE;
  Time = 0;
  While (time < timeout) {
    read in REPLY;

    If response from recipient then {
    //login to FTP
        transmit to server ("USER "+login+ "\r\n");
        transmit to server ("PASS " + password+ "\r\n");
        read in REPLY;

        // reply 230 means user logged in, to proceed
        if REPLY not 230 {
                close TCP connection
                time = timeout;
        } else {
                time = timeout;

                FTP Successful = TRUE; }

        }

    else {
    time = time + 1;
    } // end if-then-else response from recipient
  } // end while (time < timeout)
}

In fact, as shown in the pseudocode below, the FTP client needs to provide mechanisms that support the user being able to transmit the different types of commands (shown in Table 10-10) available via FTP, as well as process any response codes received (shown in Table 10-9).

FTP Client Pseudocode

// "QUIT" access command routine
FTPQuit () {

  transmit to server ("QUIT");
  read in REPLY;

  // reply 221 means server closing control connection
  if REPLY not 221 {
  // error closing connection with server
  } close TCP connection
}

// FTP Service Command Routines

  // "DELE"
  FTPDelete (string filename) {

    transmit to server ("DELE " + filename);
    read in REPLY;

    // reply 250 means requested file action Ok
    if REPLY not 250 {
    // error deleting file
    }
  }

  // "RNFR"
  FTPRenameFile (string oldfilename, string newfilename) {
  transmit to server ("RNFR " + oldfilename);
  read in REPLY;

  // reply 350 means requested file action pending further information
  if REPLY not 350 {
  // error renaming file
  }

  transmit to server ("RNTO " + newfilename);
  read in REPLY;

  // reply 250 means requested file action Ok
  if REPLY not 250 {
  // error renaming file
  }
}

........

The FTP Server initiates the data connection and any transfers according to the commands specified by the FTP client.





Please sign in to post comment

Navigate to related information

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)