ftp: Allow remote user in command.

Implement the extended host argument form `user@host'
for quick selection of the remote user name.
This commit is contained in:
Mats Erik Andersson
2016-01-23 22:47:41 +01:00
parent 450b0a8ef4
commit 891d8ff98e
4 changed files with 41 additions and 2 deletions

View File

@@ -1,3 +1,15 @@
2016-01-23 Mats Erik Andersson <gnu@gisladisker.se>
ftp: Allow remote user in command.
* ftp/ftp.c (hookup): Check for an embedded at-sign in the input
variable `host', keeping the rightmost part. New variable P.
(login): Likewise, but also using the string part to the left of
the last at-sign as remote user name.
* doc/inetutils.texi (ftp invocation): Document this ability.
* NEWS: Likewise.
2016-01-22 Mats Erik Andersson <gnu@gisladisker.se>
* bootstrap: Updated from gnulib.

5
NEWS
View File

@@ -5,6 +5,11 @@ Free Software Foundation, Inc.
See the end of this file for license conditions.
Please send inetutils bug reports to <bug-inetutils@gnu.org>.
* ftp
Allow invocation, as well as command `open', to accept an explicit
remote user name as extended host argument: `user@host'.
June 9, 2015
Version 1.9.4:

View File

@@ -1527,6 +1527,9 @@ Synopsis:
@example
ftp [@var{option}@dots{}] [@var{host} [@var{port}]]
pftp [@var{option}@dots{}] [@var{host} [@var{port}]]
ftp [@var{option}@dots{}] @var{user@@host} [@var{port}]
pftp [@var{option}@dots{}] @var{user@@host} [@var{port}]
@end example
@noindent
@@ -1537,6 +1540,7 @@ The client host with which @command{ftp} is to communicate may be
specified on the command line.
If this is done, @command{ftp} will immediately attempt to establish
a connection to the FTP server running on that host.
Optionally, a remote user name can be specified at will.
Otherwise, the program will start a command interpreter and will await
further instructions from the user.
Commands can either be entered interactively,
@@ -2004,6 +2008,7 @@ character's position in @var{inchars} is longer than the length of
@var{outchars}, the character is deleted from the file name.
@item open @var{host} [@var{port}]
@itemx open @var{user@@host} [@var{port}]
Establish a connection to the specified FTP server
at @var{host}. An optional port number may be supplied,
in which case, @command{ftp} will attempt to contact the server
@@ -2011,6 +2016,10 @@ at that specific TCP port. If the @code{autologin} option
is on (is so by default), @command{ftp} will also attempt to
automatically log the user in to the FTP server.
The second form of invocation sets the remote user name to @var{user},
which otherwise is taken as identical to the user identity owning the
local session.
@item passive
Toggle passive mode. If passive mode is turned on (default is off),
the @command{ftp} client will send a @code{PASV} command for all data

View File

@@ -133,7 +133,11 @@ hookup (char *host, int port)
int s, tos;
socklen_t len;
static char hostnamebuf[80];
char *rhost;
char *rhost, *p;
p = strrchr (host, '@');
if (p && p != host && isprint (p[1]))
host = ++p;
#ifdef HAVE_IDN
status = idna_to_ascii_lz (host, &rhost, 0);
@@ -293,7 +297,7 @@ int
login (char *host)
{
char tmp[80];
char *user, *pass, *acct;
char *user, *pass, *acct, *p;
int n, aflag = 0;
user = pass = acct = 0;
@@ -302,6 +306,15 @@ login (char *host)
code = -1;
return (0);
}
p = strrchr (host, '@');
if (user == NULL && p && p != host && isprint (p[1]))
{
*p = 0;
user = host;
host = ++p;
}
while (user == NULL)
{
char *myname = getlogin ();