[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tyndur-devel] [PATCH] FTP-Client



Weitergeleitet, ursprünglich Von: Paul Lange <matheeguru@xxxxxx> 

-------------------

+ftp: bearbeitete Version wurde hinzugefügt
---
src/modules/c/ftp/Makefile.all |    7 +
src/modules/c/ftp/command.c    |  184 +++++++++++++++++++++++++++++
src/modules/c/ftp/command.h    |  63 ++++++++++
src/modules/c/ftp/ftp.c        |  248 ++++++++++++++++++++++++++++++++++++++++
src/modules/c/ftp/ftp.h        |  40 +++++++
src/modules/c/ftp/main.c      |  152 ++++++++++++++++++++++++
6 files changed, 694 insertions(+), 0 deletions(-)
create mode 100644 src/modules/c/ftp/Makefile.all
create mode 100644 src/modules/c/ftp/command.c
create mode 100644 src/modules/c/ftp/command.h
create mode 100644 src/modules/c/ftp/ftp.c
create mode 100644 src/modules/c/ftp/ftp.h
create mode 100644 src/modules/c/ftp/main.c

diff --git a/src/modules/c/ftp/Makefile.all b/src/modules/c/ftp/Makefile.all
new file mode 100644
index 0000000..fb31509
--- /dev/null
+++ b/src/modules/c/ftp/Makefile.all
@@ -0,0 +1,7 @@
+shopt -s extglob
+source $LOST_BUILDMK_ROOT/config.sh
+
+echo "LD  $1/apps/ftp"
+$LOST_TOOLS_LD -oftp -Ttext=0x40000000 *.o --start-group $2 --end-group
+
+mv ftp $1/apps/
diff --git a/src/modules/c/ftp/command.c b/src/modules/c/ftp/command.c
new file mode 100644
index 0000000..ac20e30
--- /dev/null
+++ b/src/modules/c/ftp/command.c
@@ -0,0 +1,184 @@
+/**
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Paul Lange.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by the tyndur Project
+ *    and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <types.h>
+#include <ctype.h>
+#include <libgen.h>
+#include <sys/stat.h>
+#include <readline/readline.h>
+#include "ftp.h"
+
+#define LINE_LENGTH 80
+#define BLOCK_128K 131072
+
+extern char* host;
+extern FILE* handle;
+
+void ftp_account(void)
+{
+    char* input, *prompt, *c;
+
+    asprintf(&prompt, "\033[1;37mBenutzer (%s): \033[0m", host);
+    input = readline(prompt);
+    free(prompt);
+
+    // sorgt dafür, dass die Leerzeichen entfernt werden
+    for (; isspace(*input); input++);
+    for (c = input; !isspace(*c) && *c; c++);
+    *c = '\0';
+
+    fprintf(handle, "USER %s\r\n", input);
+    fflush(handle);
+    response();
+
+    input = readline("\033[1;37mPasswort: \033[0m");
+
+    for (; isspace(*input); input++);
+    for (c = input; !isspace(*c) && *c; c++);
+    *c = '\0';
+
+    fprintf(handle, "PASS %s\r\n", input);
+    fflush(handle);
+    response();
+}
+
+void ftp_ls(void)
+{
+    FILE* data_handle;
+    char c;
+    char buffer[LINE_LENGTH];
+    long  i;
+
+    data_handle = ftp_data_connect();
+    request("LIST");
+
+    while (!feof(data_handle)) {
+        i = 0;
+        while (((c = fgetc(data_handle)) != '\n') &&
+              i < (LINE_LENGTH - 1) && !feof(data_handle)) {
+            if (c != EOF) {
+                buffer[i++] = c;
+            }
+        }
+        buffer[i] = '\0';
+        printf("%s\n", buffer);
+    }
+
+    fclose(data_handle);
+    data_handle = NULL;
+    response();
+    puts("\033[1;37mDatenverbindung beendet\033[0m");
+}
+
+void ftp_get(char* pathname)
+{
+    FILE* data_handle;
+    FILE* file_handle;
+    char* filename;
+    char buffer[BLOCK_128K];
+
+    filename = basename(pathname);
+    file_handle = fopen(filename, "w+");
+    data_handle = ftp_data_connect();
+
+    fprintf(handle, "RETR %s\r\n", pathname);
+    fflush(handle);
+    response();
+
+    while (!feof(data_handle)) {
+        fwrite(buffer, 1, fread(buffer, 1, BLOCK_128K, data_handle), file_handle);
+    }
+
+    fclose(file_handle);
+    response();
+    puts("\033[1;37mDatenverbindung beendet\033[0m");
+}
+
+void ftp_put(char* pathname)
+{
+    FILE* data_handle;
+    FILE* file_handle;
+    char* filename;
+    char buffer[BLOCK_128K];
+    size_t count;
+
+    filename = basename(pathname);
+    file_handle = fopen(pathname, "r");
+    data_handle = ftp_data_connect();
+
+    fprintf(handle, "STOR %s\r\n", filename);
+    fflush(handle);
+    response();
+
+    while (!feof(file_handle)) {
+        count = fread(buffer, 1, BLOCK_128K, file_handle);
+        fwrite(buffer, 1, count, data_handle);
+    }
+
+    fclose(file_handle);
+    fclose(data_handle);
+    response();
+    puts("\033[1;37mDatenverbindung beendet\033[0m");
+}
+
+void ftp_mkdir(const char* pathname)
+{
+    fprintf(handle, "MKD %s\r\n", pathname);
+    fflush(handle);
+    response();
+}
+
+void ftp_rmdir(const char* pathname)
+{
+    fprintf(handle, "RMD %s\r\n", pathname);
+    fflush(handle);
+    response();
+}
+
+void ftp_cd(const char* pathname)
+{
+    fprintf(handle, "CWD %s\r\n", pathname);
+    fflush(handle);
+    response();
+}
+
+void ftp_cdup(void)
+{
+    fprintf(handle, "%s\r\n", "CDUP");
+    fflush(handle);
+    response();
+}
diff --git a/src/modules/c/ftp/command.h b/src/modules/c/ftp/command.h
new file mode 100644
index 0000000..d813232
--- /dev/null
+++ b/src/modules/c/ftp/command.h
@@ -0,0 +1,63 @@
+/**
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Paul Lange.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by the tyndur Project
+ *    and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// listet die Dateien aus dem aktuellen Verzeichniss des FTP-Servers auf
+void ftp_ls(void);
+
+// auf dem FTP-Server einloggen
+void ftp_account(void);
+
+// erzeugt ein Verzeichniss auf dem FTP-Server
+// @param Pfadname+Dateiname
+void ftp_mkdir(const char*);
+
+// loescht ein Verzeichniss auf dem FTP-Server
+// @param Pfadname+Dateiname
+void ftp_rmdir(const char*);
+
+// wechselt das Verzeichniss auf dem FTP-Server
+// @param Pfadname
+void ftp_cd(const char*);
+
+// zeigt das Hauptverzeichniss auf dem FTP-Server an
+void ftp_cdup(void);
+
+// uebertraegt eine Datei auf den FTP-Server
+// @param Pfadname+Dateiname
+void ftp_get(const char*);
+
+// speichert eine Datei vom FTP-Server
+// @param Pfadname+Dateiname
+void ftp_put(const char*);
diff --git a/src/modules/c/ftp/ftp.c b/src/modules/c/ftp/ftp.c
new file mode 100644
index 0000000..88857b8
--- /dev/null
+++ b/src/modules/c/ftp/ftp.c
@@ -0,0 +1,248 @@
+/**
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Paul Lange.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by the tyndur Project
+ *    and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCZLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <types.h>
+#include <ctype.h>
+#include <string.h>
+#include <readline/readline.h>
+
+#define COMMAND_PORT 21
+#define LINE_LENGTH 80
+
+extern char* host;
+extern FILE* handle;
+
+/**
+ * sendet einen Befehl an den Server und gibt den Request aus
+ *
+ * @param *command enthaelt den Befehl für den Server
+ */
+void request(const char* command)
+{
+    char buffer;
+    char response[LINE_LENGTH];
+    bool line_end = TRUE;
+    int i = 0;
+
+    fprintf(handle, "%s\r\n", command);
+    fflush(handle);
+
+    while (line_end) {
+        while (((buffer = fgetc(handle)) != '\n') && i < (LINE_LENGTH - 1)) {
+            if (buffer != EOF) {
+              response[i++] = buffer;
+            }
+        }
+        response[i] = '\0';
+        printf("%s\n", response);
+        line_end = FALSE;
+
+        if ((i > 3) && (response[3] == '-')) {
+            line_end = TRUE;
+            i = 0;
+        }
+    }
+}
+
+
+/**
+ * gibt den Request string auf dem Bildschirm aus
+ */
+void response(void)
+{
+    char buffer;
+    char response[LINE_LENGTH];
+    bool line_end = TRUE;
+    int i = 0;
+
+    while (line_end) {
+        while (((buffer = fgetc(handle)) != '\n') && i < (LINE_LENGTH - 1)) {
+            if (buffer != EOF) {
+              response[i++] = buffer;
+            }
+        }
+        response[i] = '\0';
+        printf("%s\n", response);
+        line_end = FALSE;
+
+        if ((i > 3) && (response[3] == '-')) {
+            line_end = TRUE;
+            i = 0;
+        }
+    }
+}
+
+
+/**
+ * Stellt eine Verbindung zum Server her
+ */
+void ftp_connect(void)
+{
+    char* host_path;
+    char* prompt;
+    char* input;
+    char* c;
+
+    if (handle) return;
+    puts("\033[1;37mVerbinde...\033[0m");
+    asprintf(&host_path, "tcpip:/%s:%d", host, COMMAND_PORT);
+    handle = fopen(host_path, "r+");
+    free(host_path);
+
+    if (!handle) {
+        puts("\033[1;37mFehler: Host nicht erreichbar!\033[0m");
+        handle = NULL;
+        return;
+    }
+    printf("\033[1;37mVerbunden mit %s, warte auf Antwort...\033[0m\n", host);
+    response();
+
+    asprintf(&prompt, "\033[1;37mBenutzer (%s): \033[0m", host);
+    input = readline(prompt);
+    free(prompt);
+
+    // sorgt dafür, dass die Leerzeichen entfernt werden
+    for (; isspace(*input); input++);
+    for (c = input; !isspace(*c) && *c; c++);
+    *c = '\0';
+
+    fprintf(handle, "USER %s\r\n", input);
+    fflush(handle);
+    response();
+
+    input = readline("\033[1;37mPasswort: \033[0m");
+
+    for (; isspace(*input); input++);
+    for (c = input; !isspace(*c) && *c; c++);
+    *c = '\0';
+
+    fprintf(handle, "PASS %s\r\n", input);
+    fflush(handle);
+    response();
+
+    request("TYPE A");
+}
+
+
+/**
+ * Schliest die Verbindung zum Server
+ */
+void ftp_disconnect(void)
+{
+    if (!handle) return;
+    request("QUIT");
+    fclose(handle);
+    handle = NULL;
+    puts("\033[1;37mVerbindung getrennt...\033[0m");
+}
+
+
+/**
+ * Öffnet eine passive Datenverbindung zum Server
+ *
+ * @return Handle zum Datenfluss
+ */
+FILE* ftp_data_connect(void)
+{
+    char buffer;
+    char* c, *host_path;
+    char response[LINE_LENGTH], portI[4], portII[4];
+    bool line_end = TRUE;
+    unsigned int port, port_low;
+    int i = 0;
+    FILE* data_handle = NULL;
+
+    puts("\033[1;37mDatenverbindung wird geöffnet...\033[0m");
+    fprintf(handle, "%s\r\n", "PASV");
+    fflush(handle);
+
+    // hier wird statt response() aufzurufen, der Inhalt dieser Funktion
+    // wiedergegeben, da der Inhalt des response noch gebraucht wird
+    while (line_end) {
+        while (((buffer = fgetc(handle)) != '\n') && i < (LINE_LENGTH - 1)) {
+            if (buffer != EOF) {
+              response[i++] = buffer;
+            }
+        }
+        response[i] = '\0';
+        printf("%s\n", response);
+        line_end = FALSE;
+
+        if ((i > 3) && (response[3] == '-')) {
+            line_end = TRUE;
+            i = 0;
+        }
+    }
+    // bis zum ersten Leerzeichen Parsen
+    for (c = response; *c != '(' || *c == '\n'; c++);
+
+    // hier wird der Port rausgeparst, der dann noch in Zahlenwerte umgewandelt
+    // werden sowie noch zusammengerechnet werden muss, da der Port so vom
+    // Server verschickt wird '(127, 0, 0, 1, p1,p2)'. Vorne die IP dahinter
+    // der Port, der so zusammengerechnet werden muss p1*256 + p2!
+    i = 0;
+    while (i < 4) {
+        for (; *(c++) != ',' || *c == '\n';);
+        i++;
+    }
+
+    i = 0;
+    while (*c != ',' || *c == '\n') {
+        portI[i] = *c;
+        i++;
+        c++;
+    }
+    portI[i++] = '\0';
+    c++;
+    i = 0;
+    while (*c != ')' || *c == '\n') {
+        portII[i] = *c;
+        i++;
+        c++;
+    }
+    portII[i++] = '\0';
+    port = atoi(portI);
+    port *= 256;
+    port_low = atoi(portII);
+    port += port_low;
+
+    asprintf(&host_path, "tcpip:/%s:%d", host, port);
+    data_handle = fopen(host_path, "r+");
+    free(host_path);
+
+    return data_handle;
+}
diff --git a/src/modules/c/ftp/ftp.h b/src/modules/c/ftp/ftp.h
new file mode 100644
index 0000000..bb7189e
--- /dev/null
+++ b/src/modules/c/ftp/ftp.h
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Paul Lange.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by the tyndur Project
+ *    and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+extern void ftp_connect(void);
+extern FILE* ftp_data_connect(void);
+extern void ftp_disconnect(void);
+extern void request(const char*);
+extern void response(void);
diff --git a/src/modules/c/ftp/main.c b/src/modules/c/ftp/main.c
new file mode 100644
index 0000000..4e00ced
--- /dev/null
+++ b/src/modules/c/ftp/main.c
@@ -0,0 +1,152 @@
+/**
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Paul Lange.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by the tyndur Project
+ *    and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <readline/readline.h>
+#include <types.h>
+#include "command.h"
+#include "ftp.h"
+
+char* host;
+FILE* handle;
+
+int main(int argc, char* argv[])
+{
+    bool prgm_end = FALSE;
+    char* input, *buffer;
+
+    if (argc == 2) {
+        host = argv[1];
+        ftp_connect();
+    }
+
+    // Bildet den Ablauf des kompletten Programmes
+    do {
+        input = readline("\033[1;37mFTP>\033[0m");
+        // durchlaeuft den String bis zum ersten Zeichen
+        for (; isspace(*input); input++);
+
+            if (!strncmp(input, "exit", 4)) {
+                prgm_end = TRUE;
+            } else if (!strncmp(input, "close", 5)) {
+                ftp_disconnect();
+            } else if (!strncmp(input, "quit", 4)) {
+                ftp_disconnect();
+                prgm_end = TRUE;
+            } else if (!strncmp(input, "help", 4)) {
+            } else if (!strncmp(input, "open", 4)) {
+                // parst den host aus dem string
+                input += 4;
+                for (; isspace(*input); input++);
+                if (*input != '\0') {
+                    for (buffer = input; !isspace(*buffer) && *buffer;
+                        buffer++);
+                    *buffer = '\0';
+
+                    host = input;
+                    ftp_connect();
+                }
+            } else if (!strncmp(input, "account", 7)) {
+                ftp_account();
+            } else if (!strncmp(input, "mkdir", 5)) {
+                input += 5;
+                for (; isspace(*input); input++);
+                if (*input != '\0') {
+                    for (buffer = input; !isspace(*buffer) && *buffer;
+                        buffer++);
+                    *buffer = '\0';
+
+                    ftp_mkdir(input);
+                }
+            } else if (!strncmp(input, "rmdir", 5)) {
+                input += 5;
+                for (; isspace(*input); input++);
+                if (*input != '\0') {
+                    for (buffer = input; !isspace(*buffer) && *buffer;
+                        buffer++);
+                        *buffer = '\0';
+
+                        ftp_rmdir(input);
+                }
+            } else if (!strncmp(input, "cdup", 4)) {
+                ftp_cdup();
+            } else if (!strncmp(input, "ascii", 5)) {
+                request("TYPE A");
+            } else if (!strncmp(input, "binary", 6)) {
+                request("TYPE I");
+            } else if (!strncmp(input, "clear", 5)) {
+                puts("\33[2J\33[H");
+            } else if (!strncmp(input, "get", 3)) {
+                input += 3;
+                for (; isspace(*input); input++);
+                if (*input != '\0') {
+                    for (buffer = input; !isspace(*buffer) && *buffer;
+                        buffer++);
+                        *buffer = '\0';
+
+                        ftp_get(input);
+                }
+            } else if (!strncmp(input, "put", 3)) {
+                input += 3;
+                for (; isspace(*input); input++);
+                if (*input != '\0') {
+                    for (buffer = input; !isspace(*buffer) && *buffer;
+                        buffer++);
+                        *buffer = '\0';
+
+                        ftp_put(input);
+                }
+            } else if (!strncmp(input, "cd", 2)) {
+                input += 2;
+                for (; isspace(*input); input++);
+                if (*input != '\0') {
+                    for (buffer = input; !isspace(*buffer) && *buffer;
+                        buffer++);
+                    *buffer = '\0';
+
+                    ftp_cd(input);
+                }
+            } else if (!strncmp(input, "ls", 2)) {
+                ftp_ls();
+            } else {
+                puts("\033[1;37mFehler: Falschen Befehl eingegeben! Geben sie "
+                  "help ein um eine Liste aller\nBefehle zu erhalten\033[0m");
+            }
+        } while (!prgm_end);
+    return 0;
+}
-- 
1.6.0.4 

Attachment: signature.asc
Description: Digital signature