comparison packages/net/ftpclient/current/src/ftpclient.c @ 269:7fffb214536c

* src/ftpclient.c: Send "quit" not "quit " to keep some servers happy. Also deal with multi line replies correctly.
author asl
date Wed, 07 Aug 2002 08:00:33 +0000
parents d2c90368aeef
children c1abcb7d0cf8
comparison
equal deleted inserted replaced
268:2fd40a752de4 269:7fffb214536c
7 //========================================================================== 7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN#### 8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // ------------------------------------------- 9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System. 10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2002 Andrew Lunn.
12 // 13 //
13 // eCos is free software; you can redistribute it and/or modify it under 14 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free 15 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version. 16 // Software Foundation; either version 2 or (at your option) any later version.
16 // 17 //
52 53
53 #include <pkgconf/system.h> 54 #include <pkgconf/system.h>
54 55
55 #include <network.h> 56 #include <network.h>
56 #include <stdio.h> 57 #include <stdio.h>
58 #include <stdlib.h>
57 #include <sys/socket.h> 59 #include <sys/socket.h>
58 #include <netinet/in.h> 60 #include <netinet/in.h>
59 #include <arpa/inet.h> 61 #include <arpa/inet.h>
60 #include <ctype.h> 62 #include <ctype.h>
61 #include "ftpclient.h" 63 #include "ftpclient.h"
126 get_reply(int s,ftp_printf_t ftp_printf) { 128 get_reply(int s,ftp_printf_t ftp_printf) {
127 129
128 char buf[BUFSIZ]; 130 char buf[BUFSIZ];
129 int more = 0; 131 int more = 0;
130 int ret; 132 int ret;
131 133 int first_line=1;
134 int code=0;
135
132 do { 136 do {
133 137
134 if ((ret=get_line(s,buf,sizeof(buf),ftp_printf)) < 0) { 138 if ((ret=get_line(s,buf,sizeof(buf),ftp_printf)) < 0) {
135 return(ret); 139 return(ret);
136 } 140 }
137 141
138 ftp_printf(0,"FTP: %s\n",buf); 142 ftp_printf(0,"FTP: %s\n",buf);
139 143
140 more = (buf[3] == '-'); 144 if (first_line) {
145 code = strtoul(buf,NULL,0);
146 first_line=0;
147 more = (buf[3] == '-');
148 } else {
149 if (isdigit(buf[0]) && isdigit(buf[1]) && isdigit(buf[2]) &&
150 (code == strtoul(buf,NULL,0)) &&
151 buf[3]==' ') {
152 more=0;
153 } else {
154 more =1;
155 }
156 }
141 } while (more); 157 } while (more);
142 158
143 return (buf[0] - '0'); 159 return (buf[0] - '0');
144 } 160 }
145 161
459 unsigned msgbuflen, 475 unsigned msgbuflen,
460 ftp_printf_t ftp_printf) { 476 ftp_printf_t ftp_printf) {
461 477
462 int ret; 478 int ret;
463 479
464 ret = command("QUIT","",s,msgbuf,msgbuflen,ftp_printf); 480 ret = command("QUIT",NULL,s,msgbuf,msgbuflen,ftp_printf);
465 if (ret < 0) { 481 if (ret < 0) {
466 return (ret); 482 return (ret);
467 } 483 }
468 if (ret != 2) { 484 if (ret != 2) {
469 ftp_printf(1,"FTP: Quit failed!\n"); 485 ftp_printf(1,"FTP: Quit failed!\n");