[tyndur-devel] [PATCH 2/2] ftp: nur nach einem passwort fragen wenn eins gefordert wird
Andreas Freimuth ·
+ ftp.c: response/request geben jetzt den status code zurück + ftp.c: nur wenn der Server danach verlangt wird ein Passwort abgefragt Signed-off-by: Andreas Freimuth <m.nemo at gmx.net> --- src/modules/c/ftp/ftp.c | 27 ++++++++++++++++----------- src/modules/c/ftp/ftp.h | 4 ++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/modules/c/ftp/ftp.c b/src/modules/c/ftp/ftp.c index 824b389..da5dc23 100644 --- a/src/modules/c/ftp/ftp.c +++ b/src/modules/c/ftp/ftp.c @@ -72,21 +72,24 @@ char* parser(char* string) * sendet einen Befehl an den FTP-Server und gibt den Request aus * * @param command enthaelt den Befehl für den FTP-Server + * @return Statuscode */ -void request(const char* command) +int request(const char* command) { fprintf(handle, "%s\r\n", command); fflush(handle); - response(); + return response(); } /** * gibt den Requeststring auf dem Bildschirm aus + * + * @return Statuscode */ -void response(void) +int response(void) { char code[5]; @@ -120,6 +123,7 @@ void response(void) break; } + return atoi(code); } @@ -162,17 +166,18 @@ void ftp_connect(char* hostname) fprintf(handle, "USER %s\r\n", input); fflush(handle); - response(); + if (response() == 331) { - input = readline("\033[1;37mPasswort: \033[0m"); + input = readline("\033[1;37mPasswort: \033[0m"); - for (; isspace(*input); input++); - for (c = input; !isspace(*c) && *c; c++); - *c = '\0'; + for (; isspace(*input); input++); + for (c = input; !isspace(*c) && *c; c++); + *c = '\0'; - fprintf(handle, "PASS %s\r\n", input); - fflush(handle); - response(); + fprintf(handle, "PASS %s\r\n", input); + fflush(handle); + response(); + } request("TYPE A"); } diff --git a/src/modules/c/ftp/ftp.h b/src/modules/c/ftp/ftp.h index 3725768..bfed48e 100644 --- a/src/modules/c/ftp/ftp.h +++ b/src/modules/c/ftp/ftp.h @@ -40,8 +40,8 @@ extern FILE* ftp_data_connect(void); extern char* parser(char*); extern void ftp_connect(char*); extern void ftp_disconnect(void); -extern void request(const char*); -extern void response(void); +extern int request(const char*); +extern int response(void); extern FILE* handle; extern char* host; -- 1.7.4.2