Index: lib/ftp.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/ftp.c,v
retrieving revision 1.397
diff -u -r1.397 ftp.c
--- lib/ftp.c	16 Feb 2007 18:19:35 -0000	1.397
+++ lib/ftp.c	17 Feb 2007 14:28:33 -0000
@@ -1737,6 +1737,23 @@
     /* this just dumps information about this second connection */
     ftp_pasv_verbose(conn, conninfo, newhost, connectport);
 
+  switch(data->set.proxytype) {
+  case CURLPROXY_SOCKS5:
+    result = Curl_SOCKS5(conn->proxyuser, conn->proxypasswd, newhost, newport,
+                         SECONDARYSOCKET, conn);
+    break;
+  case CURLPROXY_HTTP:
+    /* do nothing here. handled later. */
+    break;
+  case CURLPROXY_SOCKS4:
+    result = Curl_SOCKS4(conn->proxyuser, newhost, newport,
+                         SECONDARYSOCKET, conn);
+    break;
+  default:
+    failf(data, "unknown proxytype option given");
+    result = CURLE_COULDNT_CONNECT;
+    break;
+  }
 #ifndef CURL_DISABLE_HTTP
   if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
     /* FIX: this MUST wait for a proper connect first if 'connected' is
Index: lib/socks.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/socks.c,v
retrieving revision 1.6
diff -u -r1.6 socks.c
--- lib/socks.c	6 Feb 2007 18:08:11 -0000	1.6
+++ lib/socks.c	17 Feb 2007 14:28:33 -0000
@@ -108,12 +108,15 @@
 *   Nonsupport "Identification Protocol (RFC1413)"
 */
 CURLcode Curl_SOCKS4(const char *proxy_name,
+                     char *hostname,
+                     int remote_port,
+                     int sockindex,
                      struct connectdata *conn)
 {
   unsigned char socksreq[262]; /* room for SOCKS4 request incl. user id */
   int result;
   CURLcode code;
-  curl_socket_t sock = conn->sock[FIRSTSOCKET];
+  curl_socket_t sock = conn->sock[sockindex];
   long timeout;
   struct SessionHandle *data = conn->data;
 
@@ -146,7 +149,7 @@
 
   socksreq[0] = 4; /* version (SOCKS4) */
   socksreq[1] = 1; /* connect */
-  *((unsigned short*)&socksreq[2]) = htons(conn->remote_port);
+  *((unsigned short*)&socksreq[2]) = htons(remote_port);
 
   /* DNS resolve */
   {
@@ -154,7 +157,7 @@
     Curl_addrinfo *hp=NULL;
     int rc;
 
-    rc = Curl_resolv(conn, conn->host.name, (int)conn->remote_port, &dns);
+    rc = Curl_resolv(conn, hostname, remote_port, &dns);
 
     if(rc == CURLRESOLV_ERROR)
       return CURLE_COULDNT_RESOLVE_PROXY;
@@ -190,7 +193,7 @@
     }
     if(!hp) {
       failf(data, "Failed to resolve \"%s\" for SOCKS4 connect.",
-            conn->host.name);
+            hostname);
       return CURLE_COULDNT_RESOLVE_HOST;
     }
   }
@@ -312,6 +315,9 @@
  */
 CURLcode Curl_SOCKS5(const char *proxy_name,
                      const char *proxy_password,
+                     char *hostname,
+                     int remote_port,
+                     int sockindex,
                      struct connectdata *conn)
 {
   /*
@@ -336,7 +342,7 @@
   ssize_t written;
   int result;
   CURLcode code;
-  curl_socket_t sock = conn->sock[FIRSTSOCKET];
+  curl_socket_t sock = conn->sock[sockindex];
   struct SessionHandle *data = conn->data;
   long timeout;
 
@@ -507,7 +513,7 @@
   {
     struct Curl_dns_entry *dns;
     Curl_addrinfo *hp=NULL;
-    int rc = Curl_resolv(conn, conn->host.name, (int)conn->remote_port, &dns);
+    int rc = Curl_resolv(conn, hostname, remote_port, &dns);
 
     if(rc == CURLRESOLV_ERROR)
       return CURLE_COULDNT_RESOLVE_HOST;
@@ -541,12 +547,12 @@
     }
     if(!hp) {
       failf(data, "Failed to resolve \"%s\" for SOCKS5 connect.",
-            conn->host.name);
+            hostname);
       return CURLE_COULDNT_RESOLVE_HOST;
     }
   }
 
-  *((unsigned short*)&socksreq[8]) = htons(conn->remote_port);
+  *((unsigned short*)&socksreq[8]) = htons(remote_port);
 
   {
     const int packetsize = 10;
Index: lib/socks.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/socks.h,v
retrieving revision 1.2
diff -u -r1.2 socks.h
--- lib/socks.h	23 Sep 2006 19:09:39 -0000	1.2
+++ lib/socks.h	17 Feb 2007 14:28:33 -0000
@@ -28,6 +28,9 @@
  * final destination server.
  */
 CURLcode Curl_SOCKS4(const char *proxy_name,
+                     char *hostname,
+                     int remote_port,
+                     int sockindex,
                      struct connectdata *conn);
 
 /*
@@ -36,6 +39,9 @@
  */
 CURLcode Curl_SOCKS5(const char *proxy_name,
                      const char *proxy_password,
+                     char *hostname,
+                     int remote_port,
+                     int sockindex,
                      struct connectdata *conn);
 
 #endif
Index: lib/url.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/url.c,v
retrieving revision 1.584
diff -u -r1.584 url.c
--- lib/url.c	12 Feb 2007 21:13:51 -0000	1.584
+++ lib/url.c	17 Feb 2007 14:28:35 -0000
@@ -2286,13 +2286,15 @@
 
     switch(data->set.proxytype) {
     case CURLPROXY_SOCKS5:
-      result = Curl_SOCKS5(conn->proxyuser, conn->proxypasswd, conn);
+      result = Curl_SOCKS5(conn->proxyuser, conn->proxypasswd, conn->host.name,
+                           conn->remote_port, FIRSTSOCKET, conn);
       break;
     case CURLPROXY_HTTP:
       /* do nothing here. handled later. */
       break;
     case CURLPROXY_SOCKS4:
-      result = Curl_SOCKS4(conn->proxyuser, conn);
+      result = Curl_SOCKS4(conn->proxyuser, conn->host.name, conn->remote_port,
+                           FIRSTSOCKET, conn);
       break;
     default:
       failf(data, "unknown proxytype option given");
