Object | +---DFTPClient
The DFTPClient class implements a number of methods for building a FTP (File Transfer Protocol) client.
#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; }