On Fri, Nov 12, 2004 at 12:33:17PM +0100, S?bastien DAUBIES wrote:
> I have a last problem :
> I don't understand if it's possible to connect at proxy http with
> authentification required (user:password) with option "ftp:use-hftp no" and
> "ftp:proxy http://name:port"
>
> And if it's possible, what command to set ?
Please try this patch. Set ftp:proxy to http://proxy_user:[EMAIL PROTECTED]:port
--
Alexander.
Index: Http.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/Http.cc,v
retrieving revision 1.177
diff -u -p -r1.177 Http.cc
--- Http.cc 11 Nov 2004 07:03:43 -0000 1.177
+++ Http.cc 13 Nov 2004 12:53:29 -0000
@@ -55,8 +55,6 @@ CDECL char *strptime(const char *buf, co
#define HTTPS_DEFAULT_PORT "443"
static time_t http_atotm (const char *time_string);
-static int base64_length (int len);
-static void base64_encode (const char *s, char *store, int length);
/* Some status code validation macros: */
#define H_20X(x) (((x) >= 200) && ((x) < 300))
@@ -2222,51 +2220,6 @@ http_atotm (const char *time_string)
return mktime_from_utc (&t);
/* Failure. */
return -1;
-}
-
-/* How many bytes it will take to store LEN bytes in base64. */
-static int
-base64_length(int len)
-{
- return (4 * (((len) + 2) / 3));
-}
-
-/* Encode the string S of length LENGTH to base64 format and place it
- to STORE. STORE will be 0-terminated, and must point to a writable
- buffer of at least 1+BASE64_LENGTH(length) bytes. */
-static void
-base64_encode (const char *s, char *store, int length)
-{
- /* Conversion table. */
- static const char tbl[64] = {
- 'A','B','C','D','E','F','G','H',
- 'I','J','K','L','M','N','O','P',
- 'Q','R','S','T','U','V','W','X',
- 'Y','Z','a','b','c','d','e','f',
- 'g','h','i','j','k','l','m','n',
- 'o','p','q','r','s','t','u','v',
- 'w','x','y','z','0','1','2','3',
- '4','5','6','7','8','9','+','/'
- };
- int i;
- unsigned char *p = (unsigned char *)store;
-
- /* Transform the 3x8 bits to 4x6 bits, as required by base64. */
- for (i = 0; i < length; i += 3)
- {
- *p++ = tbl[s[0] >> 2];
- *p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];
- *p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];
- *p++ = tbl[s[2] & 0x3f];
- s += 3;
- }
- /* Pad the result if necessary... */
- if (i == length + 1)
- *(p - 1) = '=';
- else if (i == length + 2)
- *(p - 1) = *(p - 2) = '=';
- /* ...and zero-terminate it. */
- *p = '\0';
}
Index: ftpclass.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/ftpclass.cc,v
retrieving revision 1.340
diff -u -p -r1.340 ftpclass.cc
--- ftpclass.cc 13 Nov 2004 12:28:02 -0000 1.340
+++ ftpclass.cc 13 Nov 2004 21:16:41 -0000
@@ -2644,19 +2644,35 @@ int Ftp::ReceiveResp()
return m;
}
+void Ftp::HttpProxySendAuth(IOBuffer *buf)
+{
+ if(!proxy_user || !proxy_pass)
+ return;
+ char *auth=string_alloca(strlen(proxy_user)+1+strlen(proxy_pass)+1);
+ sprintf(auth,"%s:%s",proxy_user,proxy_pass);
+ int auth_len=strlen(auth);
+ char *buf64=string_alloca(base64_length(auth_len)+1);
+ base64_encode(auth,buf64,auth_len);
+ buf->Format("Proxy-Authorization: Basic %s\r\n",buf64);
+ Log::global->Format(4,"+--> Proxy-Authorization: Basic %s\r\n",buf64);
+}
void Ftp::HttpProxySendConnect()
{
const char
*the_port=portname?portname:ftps?FTPS_DEFAULT_PORT:FTP_DEFAULT_PORT;
- conn->control_send->Format("CONNECT %s:%s
HTTP/1.0\r\n\r\n",hostname,the_port);
+ conn->control_send->Format("CONNECT %s:%s HTTP/1.0\r\n",hostname,the_port);
Log::global->Format(4,"+--> CONNECT %s:%s HTTP/1.0\n",hostname,the_port);
+ HttpProxySendAuth(conn->control_send);
+ conn->control_send->Put("\r\n");
http_proxy_status_code=0;
}
void Ftp::HttpProxySendConnectData()
{
const char *the_host=SocketNumericAddress(&conn->data_sa);
int the_port=SocketPort(&conn->data_sa);
- conn->data_iobuf->Format("CONNECT %s:%d
HTTP/1.0\r\n\r\n",the_host,the_port);
+ conn->data_iobuf->Format("CONNECT %s:%d HTTP/1.0\r\n",the_host,the_port);
Log::global->Format(4,"+--> CONNECT %s:%d HTTP/1.0\n",the_host,the_port);
+ HttpProxySendAuth(conn->data_iobuf);
+ conn->data_iobuf->Put("\r\n");
http_proxy_status_code=0;
}
// Check reply and return true when the reply is received and is ok.
@@ -2702,7 +2718,7 @@ bool Ftp::HttpProxyReplyCheck(IOBuffer *
DisconnectNow();
return false;
}
- SetError(FATAL,all_lines);
+ SetError(FATAL,line);
return false;
}
}
@@ -2861,7 +2877,7 @@ void Ftp::Disconnect()
expect->Close();
DataAbort();
DataClose();
- if(conn && state!=CONNECTING_STATE
+ if(conn && state!=CONNECTING_STATE && state!=HTTP_PROXY_CONNECTED
&& expect->Count()<2 && QueryBool("use-quit",hostname))
{
conn->SendCmd("QUIT");
Index: ftpclass.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/ftpclass.h,v
retrieving revision 1.122
diff -u -p -r1.122 ftpclass.h
--- ftpclass.h 13 Sep 2004 19:43:05 -0000 1.122
+++ ftpclass.h 13 Nov 2004 13:02:47 -0000
@@ -324,6 +324,8 @@ private:
// Send CONNECT method to http proxy.
void HttpProxySendConnect();
void HttpProxySendConnectData();
+ // Send http proxy auth.
+ void HttpProxySendAuth(IOBuffer *);
// Check if proxy returned a reply, returns true if reply is ok.
// May disconnect.
bool HttpProxyReplyCheck(IOBuffer *buf);
Index: misc.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.cc,v
retrieving revision 1.67
diff -u -p -r1.67 misc.cc
--- misc.cc 7 Jun 2004 14:22:41 -0000 1.67
+++ misc.cc 13 Nov 2004 12:52:24 -0000
@@ -827,3 +827,48 @@ char last_char(const char *str)
int len=strlen(str);
return str[len-(len>0)];
}
+
+/* How many bytes it will take to store LEN bytes in base64. */
+int
+base64_length(int len)
+{
+ return (4 * (((len) + 2) / 3));
+}
+
+/* Encode the string S of length LENGTH to base64 format and place it
+ to STORE. STORE will be 0-terminated, and must point to a writable
+ buffer of at least 1+BASE64_LENGTH(length) bytes. */
+void
+base64_encode (const char *s, char *store, int length)
+{
+ /* Conversion table. */
+ static const char tbl[64] = {
+ 'A','B','C','D','E','F','G','H',
+ 'I','J','K','L','M','N','O','P',
+ 'Q','R','S','T','U','V','W','X',
+ 'Y','Z','a','b','c','d','e','f',
+ 'g','h','i','j','k','l','m','n',
+ 'o','p','q','r','s','t','u','v',
+ 'w','x','y','z','0','1','2','3',
+ '4','5','6','7','8','9','+','/'
+ };
+ int i;
+ unsigned char *p = (unsigned char *)store;
+
+ /* Transform the 3x8 bits to 4x6 bits, as required by base64. */
+ for (i = 0; i < length; i += 3)
+ {
+ *p++ = tbl[s[0] >> 2];
+ *p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];
+ *p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];
+ *p++ = tbl[s[2] & 0x3f];
+ s += 3;
+ }
+ /* Pad the result if necessary... */
+ if (i == length + 1)
+ *(p - 1) = '=';
+ else if (i == length + 2)
+ *(p - 1) = *(p - 2) = '=';
+ /* ...and zero-terminate it. */
+ *p = '\0';
+}
Index: misc.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.h,v
retrieving revision 1.34
diff -u -p -r1.34 misc.h
--- misc.h 16 Apr 2004 14:27:36 -0000 1.34
+++ misc.h 13 Nov 2004 12:53:09 -0000
@@ -115,4 +115,7 @@ char *dirname_modify(char *fn);
/* returns last character of string or \0 if string is empty */
char last_char(const char *str);
+int base64_length (int len);
+void base64_encode (const char *s, char *store, int length);
+
#endif // MISC_H