If EPSV or EPRT fails, disable epsv4 for the rest of the current connection.

the disabled state can be overridden by toggling epsv4.

(I got sick of the errors about EPSV not being supported on almost
every server I connect to. This way we retain support for epsv4, but
it's not so whiny after the first failure...)
This commit is contained in:
lukem 1999-10-01 08:01:12 +00:00
parent 4c9f05c61f
commit fcb1a22a1c
5 changed files with 50 additions and 31 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.67 1999/10/01 06:18:32 lukem Exp $ */
/* $NetBSD: cmds.c,v 1.68 1999/10/01 08:01:12 lukem Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@ -107,7 +107,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
__RCSID("$NetBSD: cmds.c,v 1.67 1999/10/01 06:18:32 lukem Exp $");
__RCSID("$NetBSD: cmds.c,v 1.68 1999/10/01 08:01:12 lukem Exp $");
#endif
#endif /* not lint */
@ -717,7 +717,8 @@ status(argc, argv)
"Socket buffer sizes: send %d, receive %d.\n",
sndbuf_size, rcvbuf_size);
fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s.\n", onoff(epsv4));
fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
epsv4bad ? " (disabled for this connection)" : "");
#ifndef NO_EDITCOMPLETE
fprintf(ttyout, "Command line editing: %s.\n", onoff(editing));
#endif /* !NO_EDITCOMPLETE */
@ -1619,6 +1620,7 @@ disconnect(argc, argv)
cout = NULL;
connected = 0;
data = -1;
epsv4bad = 0;
if (!proxy) {
macnum = 0;
}
@ -2035,6 +2037,17 @@ setpassive(argc, argv)
verbose ? "Passive mode" : NULL);
}
void
setepsv4(argc, argv)
int argc;
char *argv[];
{
code = togglevar(argc, argv, &epsv4,
verbose ? "EPSV/EPRT on IPv4" : NULL);
epsv4bad = 0;
}
void
setsunique(argc, argv)
int argc;
@ -2454,14 +2467,3 @@ setxferbuf(argc, argv)
fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
sndbuf_size, rcvbuf_size);
}
void
setepsv4(argc, argv)
int argc;
char *argv[];
{
code = togglevar(argc, argv, &epsv4,
verbose ? "EPSV/EPRT on IPv4" : NULL);
}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ftp.1,v 1.49 1999/10/01 05:08:32 lukem Exp $
.\" $NetBSD: ftp.1,v 1.50 1999/10/01 08:01:12 lukem Exp $
.\"
.\" Copyright (c) 1985, 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -409,20 +409,21 @@ completion.
This is automatically enabled if input is from a terminal, and
disabled otherwise.
.It Ic epsv4
Toggle the use of
Toggle the use of the extended
.Dv EPSV
and
.Dv EPRT
commands on IPv4 connections.
This is enabled by default
.Po
first try
commands on IPv4 connections; first try
.Dv EPSV /
.Dv EPRT ,
and then
.Dv PASV /
.Dv PORT
.Pc .
.Dv PORT .
This is enabled by default.
If an extended command fails then this option will be temporarily
disabled for the duration of the current connection, or until
.Ic epsv4
is executed again.
.It Ic exit
A synonym for
.Ic bye .

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp.c,v 1.73 1999/10/01 06:55:44 lukem Exp $ */
/* $NetBSD: ftp.c,v 1.74 1999/10/01 08:01:12 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -67,7 +67,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
__RCSID("$NetBSD: ftp.c,v 1.73 1999/10/01 06:55:44 lukem Exp $");
__RCSID("$NetBSD: ftp.c,v 1.74 1999/10/01 08:01:12 lukem Exp $");
#endif
#endif /* not lint */
@ -1375,7 +1375,7 @@ reinit:
result = COMPLETE + 1;
switch (data_addr.su_family) {
case AF_INET:
if (epsv4) {
if (epsv4 && !epsv4bad) {
result = command(pasvcmd = "EPSV");
/*
* this code is to be friendly with broken
@ -1387,6 +1387,13 @@ reinit:
ttyout);
result = COMPLETE + 1;
}
if (result != COMPLETE) {
epsv4bad = 1;
if (debug)
fputs(
"disabling epsv4 for this connection\n",
ttyout);
}
}
if (result != COMPLETE)
result = command(pasvcmd = "PASV");
@ -1635,7 +1642,7 @@ noport:
switch (data_addr.su_family) {
case AF_INET:
if (!epsv4) {
if (!epsv4 || epsv4bad) {
result = COMPLETE + 1;
break;
}
@ -1648,8 +1655,15 @@ noport:
NULL, 0, NI_NUMERICHOST)) {
result = ERROR;
} else {
result = command("EPRT |%d|%s|%d|",
af, hname, ntohs(data_addr.su_port));
result = command("EPRT |%d|%s|%d|", af, hname,
ntohs(data_addr.su_port));
if (result != COMPLETE) {
epsv4bad = 1;
if (debug)
fputs(
"disabling epsv4 for this connection\n",
ttyout);
}
}
break;
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp_var.h,v 1.39 1999/10/01 06:55:45 lukem Exp $ */
/* $NetBSD: ftp_var.h,v 1.40 1999/10/01 08:01:13 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -204,6 +204,7 @@ GLOBAL int ttywidth; /* width of tty */
GLOBAL char *tmpdir; /* temporary directory */
GLOBAL FILE *ttyout; /* stdout, or stderr if retrieving to stdout */
GLOBAL int epsv4; /* use EPSV/EPRT on IPv4 connections */
GLOBAL int epsv4bad; /* EPSV doesn't work on the current server */
#ifndef NO_EDITCOMPLETE
GLOBAL int editing; /* command line editing enabled */

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.57 1999/10/01 06:55:45 lukem Exp $ */
/* $NetBSD: main.c,v 1.58 1999/10/01 08:01:13 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -72,7 +72,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
__RCSID("$NetBSD: main.c,v 1.57 1999/10/01 06:55:45 lukem Exp $");
__RCSID("$NetBSD: main.c,v 1.58 1999/10/01 08:01:13 lukem Exp $");
#endif
#endif /* not lint */
@ -149,6 +149,7 @@ main(argc, argv)
#else
epsv4 = 0;
#endif
epsv4bad = 0;
/*
* Get the default socket buffer sizes if we don't already have them.