Class DFTPClient

Inherits from:
Object
Declared in:
DFTPClient.h

Class Hierarchy

    Object
      |
      +---DFTPClient

Class Description

The DFTPClient class implements a number of methods for building a FTP (File Transfer Protocol) client.

Example:
#include <stdio.h>
#include "ofc/DFTPClient.h"

int main(int argc, char *argv[])
{
  DFTPClient         *ftp   = [DFTPClient new];
  DInetSocketAddress *addr  = [DInetSocketAddress new];
  DList              *files = [DList new];
  DListIterator      *iter  = [DListIterator new];
  DText              *str;

  [addr host :"ftp.gnu.org" :DFPC_PORT]; // Set address to the host and default FTP port

  if ([ftp open :addr])                // Open the ftp client (passive)
  {
    if ([ftp waitForGreetings])        // Wait for server greetings
    {
      if ([ftp login :NULL :NULL :NULL]) // Login
      {
        if (![ftp getWorkingDirectory])
          printf("Could not do a get working directory:%d\n", [ftp responseCode]);

        if ([ftp list :NULL :files]) // Ask for a directory listing
        {
          printf("Directory with %ld files.\n", [files length]);

          [iter list :files];

          str = [iter first];
          while (str != nil)
          {
            printf("File: %s\n", [str cstring]); // Print the files in the listing

            str = [iter next];
          }
        }
        else
          printf("Could not do a directory listing:%d\n", [ftp responseCode]);

      }
      else
        printf("Could not login:%d\n", [ftp responseCode]);
    }
    else
      printf("Service not available:%d\n", [ftp responseCode]);

    [ftp quit];                       // Quit the connection
  }
  else
    printf("Could not connect to \"ftp.gnu.org\".\n");

  return 0;
}
Last modified:
17-Aug-2008 (DFTPClient.h)

Instance Variables

private DSocket *_client
the client socket
private DText *_request
the request for the server
private DText *_response
the response from the server
private DText *_directory
the directory info received from the server
private id <DSocketAddressable> _server
the address of the server
private id <DSocketAddressable> _address
the address received from the server
private int _bytes
the number of bytes received from the server
private BOOL _connected
is there a connection to the server ?
private int _port
the active port (or 0 for passive mode)
private int _code
the response code
private int _bufferSize
the buffer size during binary transfer (def. 8192)

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0