about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTFTP.c
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>1998-04-23 12:35:00 -0400
committerThomas E. Dickey <dickey@invisible-island.net>1998-04-23 12:35:00 -0400
commit2a94396ccd9cf5ade728c53e02cba28e06af4378 (patch)
tree0ee1558f3e81f97725d83250f944aafa4eb43d54 /WWW/Library/Implementation/HTFTP.c
parent84271e583d80f546251ea914a33f8c537fddbac7 (diff)
downloadlynx-snapshots-2a94396ccd9cf5ade728c53e02cba28e06af4378.tar.gz
snapshot of project "lynx", label v2-8-1dev_7
Diffstat (limited to 'WWW/Library/Implementation/HTFTP.c')
-rw-r--r--WWW/Library/Implementation/HTFTP.c319
1 files changed, 116 insertions, 203 deletions
diff --git a/WWW/Library/Implementation/HTFTP.c b/WWW/Library/Implementation/HTFTP.c
index 48d0aa36..38ceddd4 100644
--- a/WWW/Library/Implementation/HTFTP.c
+++ b/WWW/Library/Implementation/HTFTP.c
@@ -338,7 +338,7 @@ PRIVATE int close_connection ARGS1(
     connection * scan;
     int status = NETCLOSE(con->socket);
     if (TRACE) {
-	fprintf(stderr, "HTFTP: Closing control socket %d\n", con->socket);
+	CTRACE(tfp, "HTFTP: Closing control socket %d\n", con->socket);
 #ifdef UNIX
 	if (status != 0)
 	    perror("HTFTP:close_connection");
@@ -375,8 +375,7 @@ PRIVATE void help_message_cache_add ARGS1(
     else
 	StrAllocCopy(help_message_buffer, string);
 
-    if (TRACE)
-	fprintf(stderr,"Adding message to help cache: %s\n",string);
+    CTRACE(tfp,"Adding message to help cache: %s\n",string);
 }
 
 PRIVATE char *help_message_cache_non_empty NOARGS
@@ -417,14 +416,12 @@ PRIVATE int response ARGS1(
     int status;
 
     if (!control) {
-	  if (TRACE)
-	      fprintf(stderr, "HTFTP: No control connection set up!!\n");
-	  return -99;
+	CTRACE(tfp, "HTFTP: No control connection set up!!\n");
+	return -99;
     }
 
     if (cmd) {
-	if (TRACE)
-	    fprintf(stderr, "  Tx: %s", cmd);
+	CTRACE(tfp, "  Tx: %s", cmd);
 #ifdef NOT_ASCII
 	{
 	    char * p;
@@ -435,9 +432,7 @@ PRIVATE int response ARGS1(
 #endif /* NOT_ASCII */
 	status = NETWRITE(control->socket, cmd, (int)strlen(cmd));
 	if (status < 0) {
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Error %d sending command: closing socket %d\n",
+	    CTRACE(tfp, "HTFTP: Error %d sending command: closing socket %d\n",
 			status, control->socket);
 	    close_connection(control);
 	    return status;
@@ -452,19 +447,15 @@ PRIVATE int response ARGS1(
 
 		char continuation;
 
-		if (interrupted_in_htgetcharacter)
-		  {
-		    if (TRACE)
-		      fprintf (stderr,
-			"HTFTP: Interrupted in HTGetCharacter, apparently.\n");
+		if (interrupted_in_htgetcharacter) {
+		    CTRACE (tfp, "HTFTP: Interrupted in HTGetCharacter, apparently.\n");
 		    NETCLOSE (control->socket);
 		    control->socket = -1;
 		    return HT_INTERRUPTED;
-		  }
+		}
 
 		*p = '\0';			/* Terminate the string */
-		if (TRACE)
-		    fprintf(stderr, "    Rx: %s", response_text);
+		CTRACE(tfp, "    Rx: %s", response_text);
 
 		/* Check for login or help messages */
 		if (!strncmp(response_text,"230-",4) ||
@@ -484,19 +475,15 @@ PRIVATE int response ARGS1(
 		break;
 	    } /* if end of line */
 
-	    if (interrupted_in_htgetcharacter)
-	       {
-		    if (TRACE)
-		      fprintf (stderr,
-			"HTFTP: Interrupted in HTGetCharacter, apparently.\n");
-		    NETCLOSE (control->socket);
-		    control->socket = -1;
-		    return HT_INTERRUPTED;
-	       }
+	    if (interrupted_in_htgetcharacter) {
+		CTRACE (tfp, "HTFTP: Interrupted in HTGetCharacter, apparently.\n");
+		NETCLOSE (control->socket);
+		control->socket = -1;
+		return HT_INTERRUPTED;
+	    }
 
 	    if (*(p-1) == (char) EOF) {
-		if (TRACE)
-		    fprintf(stderr, "Error on rx: closing socket %d\n",
+		CTRACE(tfp, "Error on rx: closing socket %d\n",
 			    control->socket);
 		strcpy(response_text, "000 *** TCP read error on response\n");
 		close_connection(control);
@@ -507,8 +494,7 @@ PRIVATE int response ARGS1(
     } while (continuation_response != -1);
 
     if (result == 421) {
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: They close so we close socket %d\n",
+	CTRACE(tfp, "HTFTP: They close so we close socket %d\n",
 		    control->socket);
 	close_connection(control);
 	return -1;
@@ -564,8 +550,7 @@ PRIVATE void get_ftp_pwd ARGS2(
 	if (*ServerType == TCPC_SERVER) {
 	    *ServerType = ((response_text[5] == '/') ?
 					  NCSA_SERVER : TCPC_SERVER);
-	     if (TRACE)
-		 fprintf(stderr, "HTFTP: Treating as %s server.\n",
+	    CTRACE(tfp, "HTFTP: Treating as %s server.\n",
 			 ((*ServerType == NCSA_SERVER) ?
 						 "NCSA" : "TCPC"));
 	} else if (response_text[5] == '/') {
@@ -574,25 +559,21 @@ PRIVATE void get_ftp_pwd ARGS2(
 	     */
 	    if (set_mac_binary(*ServerType)) {
 		*ServerType = NCSA_SERVER;
-		if (TRACE)
-		    fprintf(stderr, "HTFTP: Treating as NCSA server.\n");
+		CTRACE(tfp, "HTFTP: Treating as NCSA server.\n");
 	    } else {
 		 *ServerType = UNIX_SERVER;
 		 *UseList = TRUE;
-		 if (TRACE)
-		     fprintf(stderr, "HTFTP: Treating as Unix server.\n");
+		 CTRACE(tfp, "HTFTP: Treating as Unix server.\n");
 	    }
 	    return;
 	} else if (response_text[strlen(response_text)-1] == ']') {
 	    /* path names ending with ] imply VMS, right? */
 	    *ServerType = VMS_SERVER;
 	    *UseList = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as VMS server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as VMS server.\n");
 	} else {
 	    *ServerType = GENERIC_SERVER;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as Generic server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as Generic server.\n");
 	}
 
 	if ((*ServerType == NCSA_SERVER) ||
@@ -713,42 +694,35 @@ PRIVATE int get_connection ARGS2(
 	    FREE(p1);
     } /* scope of p1 */
 
-  status = HTDoConnect (arg, "FTP", IPPORT_FTP, (int *)&con->socket);
+    status = HTDoConnect (arg, "FTP", IPPORT_FTP, (int *)&con->socket);
 
-  if (status < 0)
-    {
-      if (TRACE)
-	{
-	  if (status == HT_INTERRUPTED)
-	    fprintf (stderr,
-		     "HTFTP: Interrupted on connect\n");
-	  else
-	    fprintf(stderr,
-		    "HTFTP: Unable to connect to remote host for `%s'.\n",
-		    arg);
+    if (status < 0) {
+	if (status == HT_INTERRUPTED) {
+	    CTRACE (tfp, "HTFTP: Interrupted on connect\n");
+	} else {
+	    CTRACE(tfp, "HTFTP: Unable to connect to remote host for `%s'.\n",
+		        arg);
 	}
-      if (status == HT_INTERRUPTED) {
-	_HTProgress ("Connection interrupted.");
-	status = HT_NOT_LOADED;
-      } else {
-	HTAlert("Unable to connect to FTP host.");
-      }
-      if (con->socket != -1)
+	if (status == HT_INTERRUPTED) {
+	    _HTProgress ("Connection interrupted.");
+	    status = HT_NOT_LOADED;
+	} else {
+	    HTAlert("Unable to connect to FTP host.");
+	}
+	if (con->socket != -1)
 	{
 	  NETCLOSE(con->socket);
 	}
 
-      FREE(username);
-      if (control == con)
-	  control = NULL;
-      FREE(con);
-      return status;			/* Bad return */
+	FREE(username);
+	if (control == con)
+	    control = NULL;
+	FREE(con);
+	return status;			/* Bad return */
     }
 
-    if (TRACE) {
-	fprintf(stderr, "FTP connected, socket %d  control %ld\n",
-			con->socket, (long)con);
-    }
+    CTRACE(tfp, "FTP connected, socket %d  control %ld\n",
+		con->socket, (long)con);
     control = con;		/* Current control connection */
 
     /* Initialise buffering for control connection */
@@ -760,16 +734,13 @@ PRIVATE int get_connection ARGS2(
 */
     status = response((char *)0);	/* Get greeting */
 
-    if (status == HT_INTERRUPTED)
-      {
-	if (TRACE)
-	  fprintf (stderr,
-		   "HTFTP: Interrupted at beginning of login.\n");
+    if (status == HT_INTERRUPTED) {
+	CTRACE (tfp, "HTFTP: Interrupted at beginning of login.\n");
 	_HTProgress ("Connection interrupted.");
 	NETCLOSE(control->socket);
 	control->socket = -1;
 	return HT_INTERRUPTED;
-      }
+    }
     server_type = GENERIC_SERVER;	/* reset */
     if (status == 2) {		/* Send username */
 	char *cp;		/* look at greeting text */
@@ -800,16 +771,13 @@ PRIVATE int get_connection ARGS2(
 	}
 	status = response(command);
 	FREE(command);
-	if (status == HT_INTERRUPTED)
-	  {
-	    if (TRACE)
-	      fprintf (stderr,
-		       "HTFTP: Interrupted while sending username.\n");
+	if (status == HT_INTERRUPTED) {
+	    CTRACE (tfp, "HTFTP: Interrupted while sending username.\n");
 	    _HTProgress ("Connection interrupted.");
 	    NETCLOSE(control->socket);
 	    control->socket = -1;
 	    return HT_INTERRUPTED;
-	  }
+	}
     }
     if (status == 3) {		/* Send password */
 	if (password) {
@@ -866,16 +834,14 @@ PRIVATE int get_connection ARGS2(
 	}
 	status = response(command);
 	FREE(command);
-	if (status == HT_INTERRUPTED)
-	  {
-	    if (TRACE)
-	      fprintf (stderr,
+	if (status == HT_INTERRUPTED) {
+	    CTRACE (tfp,
 		       "HTFTP: Interrupted while sending password.\n");
 	    _HTProgress ("Connection interrupted.");
 	    NETCLOSE(control->socket);
 	    control->socket = -1;
 	    return HT_INTERRUPTED;
-	  }
+	}
     }
     FREE(username);
 
@@ -883,25 +849,21 @@ PRIVATE int get_connection ARGS2(
 	char temp[80];
 	sprintf(temp, "ACCT noaccount%c%c", CR, LF);
 	status = response(temp);
-	if (status == HT_INTERRUPTED)
-	  {
-	    if (TRACE)
-	      fprintf (stderr,
-		       "HTFTP: Interrupted while sending password.\n");
+	if (status == HT_INTERRUPTED) {
+	    CTRACE (tfp, "HTFTP: Interrupted while sending password.\n");
 	    _HTProgress ("Connection interrupted.");
 	    NETCLOSE(control->socket);
 	    control->socket = -1;
 	    return HT_INTERRUPTED;
-	  }
+	}
 
     }
     if (status != 2) {
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: Login fail: %s", response_text);
+	CTRACE(tfp, "HTFTP: Login fail: %s", response_text);
 	/* if (control->socket > 0) close_connection(control->socket); */
 	return -1;		/* Bad return */
     }
-    if (TRACE) fprintf(stderr, "HTFTP: Logged in.\n");
+    CTRACE(tfp, "HTFTP: Logged in.\n");
 
     /** Check for host type **/
     if (server_type != NETPRESENZ_SERVER)
@@ -913,88 +875,71 @@ PRIVATE int get_connection ARGS2(
 		    "UNIX Type: L8 MAC-OS MachTen", 28) == 0) {
 	    server_type = MACHTEN_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as MachTen server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as MachTen server.\n");
 
 	} else if (strstr(response_text+4, "UNIX") != NULL ||
 		   strstr(response_text+4, "Unix") != NULL) {
 	    server_type = UNIX_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as Unix server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as Unix server.\n");
 
 	} else if (strstr(response_text+4, "MSDOS") != NULL) {
 	    server_type = MSDOS_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Treating as MSDOS (Unix emulation) server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as MSDOS (Unix emulation) server.\n");
 
 	} else if (strncmp(response_text+4, "VMS", 3) == 0) {
 	    server_type = VMS_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as VMS server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as VMS server.\n");
 
 	} else if ((strncmp(response_text+4, "VM/CMS", 6) == 0) ||
 		   (strncmp(response_text+4, "VM ", 3) == 0)) {
 	    server_type = CMS_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as CMS server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as CMS server.\n");
 
 	} else if (strncmp(response_text+4, "DCTS", 4) == 0) {
 	    server_type = DCTS_SERVER;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as DCTS server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as DCTS server.\n");
 
 	} else if (strstr(response_text+4, "MAC-OS TCP/Connect II") != NULL) {
 	    server_type = TCPC_SERVER;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Looks like a TCPC server.\n");
+	    CTRACE(tfp, "HTFTP: Looks like a TCPC server.\n");
 	    get_ftp_pwd(&server_type, &use_list);
 	    unsure_type = TRUE;
 
 	} else if (server_type == NETPRESENZ_SERVER) { /* already set above */
 	    use_list = TRUE;
 	    set_mac_binary(server_type);
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Treating as NetPresenz (MACOS) server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as NetPresenz (MACOS) server.\n");
 
 	} else if (strncmp(response_text+4, "MACOS Peter's Server", 20) == 0) {
 	    server_type = PETER_LEWIS_SERVER;
 	    use_list = TRUE;
 	    set_mac_binary(server_type);
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Treating as Peter Lewis (MACOS) server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as Peter Lewis (MACOS) server.\n");
 
 	} else if (strncmp(response_text+4, "Windows_NT", 10) == 0) {
 	    server_type = WINDOWS_NT_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as Window_NT server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as Window_NT server.\n");
 
 	} else if (strncmp(response_text+4, "MS Windows", 10) == 0) {
 	    server_type = MS_WINDOWS_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as MS Windows server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as MS Windows server.\n");
 
 	} else if (strncmp(response_text+4,
 			   "MACOS AppleShare IP FTP Server", 30) == 0) {
 	    server_type = APPLESHARE_SERVER;
 	    use_list = TRUE;
 	    set_mac_binary(server_type);
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Treating as AppleShare server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as AppleShare server.\n");
 
 	} else	{
 	    server_type = GENERIC_SERVER;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Ugh!  A Generic server.\n");
+	    CTRACE(tfp, "HTFTP: Ugh!  A Generic server.\n");
 	    get_ftp_pwd(&server_type, &use_list);
 	    unsure_type = TRUE;
 	 }
@@ -1013,8 +958,7 @@ PRIVATE int get_connection ARGS2(
 		close_connection(control->socket);
 	    return -status;		/* Bad return */
 	}
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: Port defined.\n");
+	CTRACE(tfp, "HTFTP: Port defined.\n");
     }
 #endif /* NOTREPEAT_PORT */
     return con->socket; 		/* Good return */
@@ -1033,8 +977,7 @@ PRIVATE int close_master_socket NOARGS
     int status;
     FD_CLR(master_socket, &open_sockets);
     status = NETCLOSE(master_socket);
-    if (TRACE)
-	fprintf(stderr, "HTFTP: Closed master socket %d\n", master_socket);
+    CTRACE(tfp, "HTFTP: Closed master socket %d\n", master_socket);
     master_socket = -1;
     if (status < 0)
 	return HTInetStatus("close master socket");
@@ -1079,8 +1022,7 @@ PRIVATE int get_listen_socket NOARGS
     if (new_socket < 0)
 	return HTInetStatus("socket for master socket");
 
-    if (TRACE)
-	fprintf(stderr, "HTFTP: Opened master socket number %d\n", new_socket);
+    CTRACE(tfp, "HTFTP: Opened master socket number %d\n", new_socket);
 
 /*  Search for a free port.
 */
@@ -1115,9 +1057,7 @@ PRIVATE int get_listen_socket NOARGS
 			    /* Cast to generic sockaddr */
 		    sizeof(soc_address))) == 0)
 		break;
-	    if (TRACE)
-		fprintf(stderr,
-			"TCP bind attempt to port %d yields %d, errno=%d\n",
+	    CTRACE(tfp, "TCP bind attempt to port %d yields %d, errno=%d\n",
 		port_number, status, SOCKET_ERRNO);
 	} /* for */
     }
@@ -1592,11 +1532,10 @@ PRIVATE void parse_vms_dir_entry ARGS2(
     }
 
     /** Wrap it up **/
-    if (TRACE)
-	fprintf(stderr, "HTFTP: VMS filename: %s  date: %s  size: %d\n",
-			entry_info->filename,
-			entry_info->date ? entry_info->date : "",
-			entry_info->size);
+    CTRACE(tfp, "HTFTP: VMS filename: %s  date: %s  size: %d\n",
+		entry_info->filename,
+		entry_info->date ? entry_info->date : "",
+		entry_info->size);
     return;
 } /* parse_vms_dir_entry() */
 
@@ -1673,11 +1612,10 @@ PRIVATE void parse_ms_windows_dir_entry ARGS2(
     }
 
     /** Wrap it up **/
-    if (TRACE)
-	fprintf(stderr, "HTFTP: MS Windows filename: %s  date: %s  size: %d\n",
-			entry_info->filename,
-			entry_info->date ? entry_info->date : "",
-			entry_info->size);
+    CTRACE(tfp, "HTFTP: MS Windows filename: %s  date: %s  size: %d\n",
+		entry_info->filename,
+		entry_info->date ? entry_info->date : "",
+		entry_info->size);
     return;
 } /* parse_ms_windows_dir_entry */
 
@@ -1795,11 +1733,10 @@ PRIVATE void parse_windows_nt_dir_entry ARGS2(
     }
 
     /** Wrap it up **/
-    if (TRACE)
-	fprintf(stderr, "HTFTP: Windows NT filename: %s  date: %s  size: %d\n",
-			entry_info->filename,
-			entry_info->date ? entry_info->date : "",
-			entry_info->size);
+    CTRACE(tfp, "HTFTP: Windows NT filename: %s  date: %s  size: %d\n",
+		entry_info->filename,
+		entry_info->date ? entry_info->date : "",
+		entry_info->size);
     return;
 } /* parse_windows_nt_dir_entry */
 #endif /* NOTDEFINED */
@@ -1954,11 +1891,10 @@ PRIVATE void parse_cms_dir_entry ARGS2(
     }
 
     /** Wrap it up. **/
-    if (TRACE)
-	fprintf(stderr, "HTFTP: VM/CMS filename: %s  date: %s  size: %d\n",
-			entry_info->filename,
-			entry_info->date ? entry_info->date : "",
-			entry_info->size);
+    CTRACE(tfp, "HTFTP: VM/CMS filename: %s  date: %s  size: %d\n",
+		entry_info->filename,
+		entry_info->date ? entry_info->date : "",
+		entry_info->size);
     return;
 } /* parse_cms_dir_entry */
 
@@ -2531,15 +2467,13 @@ AgainForMultiNet:
 	    if (c == (char) EOF && chunk->size == 1)
 	    /* 1 means empty: includes terminating 0 */
 		break;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Line in %s is %s\n",
-				lastpath, chunk->data);
+	    CTRACE(tfp, "HTFTP: Line in %s is %s\n",
+			lastpath, chunk->data);
 
 	    entry_info = parse_dir_entry(chunk->data, &first);
 	    if (entry_info->display) {
-		if (TRACE)
-		    fprintf(stderr, "Adding file to BTree: %s\n",
-				    entry_info->filename);
+		CTRACE(tfp, "Adding file to BTree: %s\n",
+			    entry_info->filename);
 		HTBTree_add(bt, (EntryInfo *)entry_info);
 	    } else {
 		FREE(entry_info);
@@ -2695,22 +2629,19 @@ PUBLIC int HTFTPLoad ARGS4(
 	{
 	    status = response(port_command);
 	    if (status == HT_INTERRUPTED) {
-	      if (TRACE)
-		fprintf (stderr,
-			 "HTFTP: Interrupted in response (port_command)\n");
-	      _HTProgress ("Connection interrupted.");
-	      NETCLOSE (control->socket);
-	      control->socket = -1;
-	      close_master_socket ();
-	      return HT_INTERRUPTED;
+		CTRACE (tfp, "HTFTP: Interrupted in response (port_command)\n");
+		_HTProgress ("Connection interrupted.");
+		NETCLOSE (control->socket);
+		control->socket = -1;
+		close_master_socket ();
+		return HT_INTERRUPTED;
 	    }
 	    if (status != 2) {		/* Could have timed out */
 		if (status < 0)
 		    continue;		/* try again - net error*/
 		return -status; 	/* bad reply */
 	    }
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Port defined.\n");
+	    CTRACE(tfp, "HTFTP: Port defined.\n");
 	}
 #endif /* REPEAT_PORT */
 #else	/* Use PASV */
@@ -2738,13 +2669,12 @@ PUBLIC int HTFTPLoad ARGS4(
 	   status = sscanf(p+1, "%d,%d,%d,%d,%d,%d",
 		   &h0, &h1, &h2, &h3, &p0, &p1);
 	   if (status < 4) {
-	       fprintf(stderr, "HTFTP: PASV reply has no inet address!\n");
+	       fprintf(tfp, "HTFTP: PASV reply has no inet address!\n");
 	       return -99;
 	   }
 	   passive_port = (p0<<8) + p1;
-	   if (TRACE)
-	       fprintf(stderr, "HTFTP: Server is listening on port %d\n",
-				passive_port);
+	   CTRACE(tfp, "HTFTP: Server is listening on port %d\n",
+			passive_port);
 
 
 /*	Open connection for data:
@@ -2759,8 +2689,7 @@ PUBLIC int HTFTPLoad ARGS4(
 		return status;			/* Bad return */
 	    }
 
-	    if (TRACE)
-		fprintf(stderr, "FTP data connected, socket %d\n", data_soc);
+	    CTRACE(tfp, "FTP data connected, socket %d\n", data_soc);
 	}
 #endif /* use PASV */
 	status = 0;
@@ -2787,10 +2716,7 @@ PUBLIC int HTFTPLoad ARGS4(
 		init_help_message_cache();  /* to free memory */
 		NETCLOSE(control->socket);
 		control->socket = -1;
-		if (TRACE) {
-		    fprintf(stderr,
-		     "HTFTP: Rejecting path due to illegal escaped slash.\n");
-		}
+		CTRACE(tfp, "HTFTP: Rejecting path due to illegal escaped slash.\n");
 		return -1;
 	    }
 	}
@@ -2825,13 +2751,12 @@ PUBLIC int HTFTPLoad ARGS4(
 		    *(filename+1) = '\0';
 		}
 	    }
-	    if (TRACE && *type != '\0') {
-		fprintf(stderr, "HTFTP: type=%s\n", type);
+	    if (*type != '\0') {
+		CTRACE(tfp, "HTFTP: type=%s\n", type);
 	    }
 	}
 	HTUnEscape(filename);
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: UnEscaped %s\n", filename);
+	CTRACE(tfp, "HTFTP: UnEscaped %s\n", filename);
 	if (filename[1] == '~') {
 	    /*
 	    ** Check if translation of HOME as tilde is supported,
@@ -2949,10 +2874,7 @@ PUBLIC int HTFTPLoad ARGS4(
 		init_help_message_cache();  /* to free memory */
 		NETCLOSE(control->socket);
 		control->socket = -1;
-		if (TRACE) {
-		    fprintf(stderr,
-		     "HTFTP: Rejecting path due to non-Unix-style syntax.\n");
-		}
+		CTRACE(tfp, "HTFTP: Rejecting path due to non-Unix-style syntax.\n");
 		return -1;
 	    }
 	    /** Handle any unescaped "/%2F" path **/
@@ -2962,21 +2884,15 @@ PUBLIC int HTFTPLoad ARGS4(
 		for (i = 0; filename[(i+1)]; i++)
 		    filename[i] = filename[(i+1)];
 		filename[i] = '\0';
-		if (TRACE) {
-		    fprintf(stderr, "HTFTP: Trimmed '%s'\n", filename);
-		}
+		CTRACE(tfp, "HTFTP: Trimmed '%s'\n", filename);
 		cp = HTMake_VMS_name("", filename);
-		if (TRACE) {
-		    fprintf(stderr, "HTFTP: VMSized '%s'\n", cp);
-		}
+		CTRACE(tfp, "HTFTP: VMSized '%s'\n", cp);
 		if ((cp1=strrchr(cp, ']')) != NULL) {
 		    cp1++;
 		    for (i = 0; cp1[i]; i++)
 			filename[i] = cp1[i];
 		    filename[i] = '\0';
-		    if (TRACE) {
-			fprintf(stderr, "HTFTP: Filename '%s'\n", filename);
-		    }
+		    CTRACE(tfp, "HTFTP: Filename '%s'\n", filename);
 		    *cp1 = '\0';
 		    sprintf(command, "CWD %s%c%c", cp, CR, LF);
 		    status = response (command);
@@ -3017,9 +2933,7 @@ PUBLIC int HTFTPLoad ARGS4(
 			for (i = 0; cp1[i]; i++)
 			    filename[i] = cp1[i];
 			filename[i] = '\0';
-			if (TRACE) {
-			    fprintf(stderr, "HTFTP: Filename '%s'\n", filename);
-			}
+			CTRACE(tfp, "HTFTP: Filename '%s'\n", filename);
 			*cp1 = '\0';
 			strcat(cp, "[");
 			strcat(cp, filename);
@@ -3359,8 +3273,7 @@ listen:
 	/* Reset buffering to control connection DD 921208 */
 
 	status = NETCLOSE(data_soc);
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: Closing data socket %d\n", data_soc);
+	CTRACE(tfp, "HTFTP: Closing data socket %d\n", data_soc);
 	if (status < 0 && rv != HT_INTERRUPTED && rv != -1) {
 	    (void) HTInetStatus("close");	/* Comment only */
 	    data_soc = -1;			/* invalidate it */