[tyndur-devel] [PATCH] FTP-Client
Alexander Hartmut Kluth ·
Op maandag 21-09-2009 om 18:23 uur [tijdzone +0200], schreef Paul Lange: Das sieht mir alles irgendwie sehr "hardcoded" aus...wofür ist die libc schließlich da ;-) Zur Formatierung: In tyndur gehört der Stern für Pointer an den Typ, nicht an die Variable (ich mach's persönlich auch anders, aber ist halt so *g*) Weiter unten noch ein paar Sachen, die ich angemerkt hab. > From: Paul Lange <matheguru94 at googlemail.com> > > +ftp: ftp wurde hinzugefügt > > Paul Lange<matheeguru at gmx.de> > --- > src/modules/c/ftp/Makefile.all | 7 + > src/modules/c/ftp/command.c | 185 ++++++++++++++++++++++++++++++ > src/modules/c/ftp/command.h | 43 +++++++ > src/modules/c/ftp/ftp.c | 241 ++++++++++++++++++++++++++++++++++++++++ > src/modules/c/ftp/ftp.h | 40 +++++++ > src/modules/c/ftp/main.c | 152 +++++++++++++++++++++++++ > 6 files changed, 668 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..e951c92 > --- /dev/null > +++ b/src/modules/c/ftp/command.c > @@ -0,0 +1,185 @@ > +/** > + * 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 _128K 131072 > +#define _56K 57344 Die Unterstriche verwirren ein wenig (sieht man sie doch meist bei Bibliotheksfunktionen). > + > +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[_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, _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[_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, _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..565f2a3 > --- /dev/null > +++ b/src/modules/c/ftp/command.h > @@ -0,0 +1,43 @@ > +/** > + * 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. > + */ > + > +void ftp_ls(void); > +void ftp_account(void); > +void ftp_mkdir(const char*); > +void ftp_rmdir(const char*); > +void ftp_cd(const char*); > +void ftp_cdup(void); > +void ftp_get(const char*); > +void ftp_put(const char*); Sollte man hier nicht eventuell auch noch die Parameternamen zuschreiben? > diff --git a/src/modules/c/ftp/ftp.c b/src/modules/c/ftp/ftp.c > new file mode 100644 > index 0000000..c8f9298 > --- /dev/null > +++ b/src/modules/c/ftp/ftp.c > @@ -0,0 +1,241 @@ > +/** > + * 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++); Sollte es nicht evt. !isspace(*c) || *c; heißen? > + *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); > + > + 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; > + } > + } > + for (c = response; *c != '(' || *c == '\n'; c++); > + > + 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++; > + } Kommentieren wäre ganz nett ;-) > + 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..f6fe89e > --- /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", 3)) { > + 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)) { So viel Zeit muss doch sein, oder ;-) > + // 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; > +}