[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
wput and multiline response
- To: itooktheredpill@gmx.de
- Subject: wput and multiline response
- From: Mitry Matyushkov <mitry@todes.by>
- Date: Thu, 1 Jul 2004 21:01:26 +0300
- Delivered-to: GMX delivery to itooktheredpill@gmx.de
- Envelope-to: hagen@itooktheredpill.dyndns.org
- Organization: SIS Todes Ltd.
- Reply-to: Mitry Matyushkov <mitry@todes.by>
Hi,
I made a little hack of ftp.c based on wget code to support multiline
response from ftp server because I've encountered a site which I couldn't
upload file to. Here it is:
====
diff -ur wput.orig/src/ftp.c wput/src/ftp.c
--- wput.orig/src/ftp.c Wed Jun 16 14:08:28 2004
+++ wput/src/ftp.c Thu Jul 1 20:52:09 2004
@@ -18,6 +18,8 @@
/* This file contains procedures for acting with the FTP-Server */
+#define ISDIGIT(x) ((x) >= '0' && (x) <= '9')
+
#include "ftp.h"
#include "utils.h"
#include "progress.h"
@@ -798,15 +800,31 @@
int get_msg(int csock, char * msg, int buflen){
int res = 0;
-
- do {
- memset(msg, 0, buflen);
- res = recv(csock, msg, buflen-1, 0);
- printout(vDEBUG, "%s", msg);
+ int mlen = 0;
+ const char *p;
+
+ memset(msg, 0, buflen);
+ res = recv(csock, msg, buflen-1, 0);
+ printout(vDEBUG, "<--- %s", msg);
+
+ mlen = strlen( msg );
+
+ while (1) {
/* multiline messages are required by rfc to have a hiphen
* after the command-code (e.g. 250-).
* this counts for all but the last one, so look out for it. */
- } while(msg[3] == '-');
+ if ( ISDIGIT(msg[0]) && ISDIGIT(msg[1]) && ISDIGIT(msg[2]) && msg[3] == ' ' )
+ break;
+
+ p = memchr( msg, '\n', mlen );
+ if ( p ) {
+ mlen -= p - msg + 1;
+ memcpy( msg, p + 1, mlen );
+ msg[mlen] = '\0';
+ }
+ else
+ break;
+ }
return res;
}
====
Regards,
Mitry Matyushkov.
System engineer, SIS Todes Ltd.