- mouring@cvs.openbsd.org 2001/04/12 23:17:54
[sftp-int.c sftp-int.h sftp.1 sftp.c] Add support for: sftp [user@]host[:file [file]] - Fetch remote file(s) sftp [user@]host[:dir[/]] - Start in remote dir/ OK deraadt@
This commit is contained in:
parent
19066a112b
commit
63667f6568
|
@ -4,7 +4,6 @@
|
||||||
[ssh.c]
|
[ssh.c]
|
||||||
show debug output during option processing, report from
|
show debug output during option processing, report from
|
||||||
pekkas@netcore.fi
|
pekkas@netcore.fi
|
||||||
- OpenBSD CVS Sync
|
|
||||||
- markus@cvs.openbsd.org 2001/04/12 19:15:26
|
- markus@cvs.openbsd.org 2001/04/12 19:15:26
|
||||||
[auth-rhosts.c auth.h auth2.c buffer.c canohost.c canohost.h
|
[auth-rhosts.c auth.h auth2.c buffer.c canohost.c canohost.h
|
||||||
compat.c compat.h hostfile.c pathnames.h readconf.c readconf.h
|
compat.c compat.h hostfile.c pathnames.h readconf.c readconf.h
|
||||||
|
@ -19,6 +18,12 @@
|
||||||
- stevesk@cvs.openbsd.org 2001/04/12 20:09:38
|
- stevesk@cvs.openbsd.org 2001/04/12 20:09:38
|
||||||
[misc.c misc.h readconf.c servconf.c ssh.c sshd.c]
|
[misc.c misc.h readconf.c servconf.c ssh.c sshd.c]
|
||||||
robust port validation; ok markus@ jakob@
|
robust port validation; ok markus@ jakob@
|
||||||
|
- mouring@cvs.openbsd.org 2001/04/12 23:17:54
|
||||||
|
[sftp-int.c sftp-int.h sftp.1 sftp.c]
|
||||||
|
Add support for:
|
||||||
|
sftp [user@]host[:file [file]] - Fetch remote file(s)
|
||||||
|
sftp [user@]host[:dir[/]] - Start in remote dir/
|
||||||
|
OK deraadt@
|
||||||
- (bal) Added openbsd-compat/inet_ntop.[ch] since HP/UX (and others)
|
- (bal) Added openbsd-compat/inet_ntop.[ch] since HP/UX (and others)
|
||||||
lack it.
|
lack it.
|
||||||
|
|
||||||
|
@ -5041,4 +5046,4 @@
|
||||||
- Wrote replacements for strlcpy and mkdtemp
|
- Wrote replacements for strlcpy and mkdtemp
|
||||||
- Released 1.0pre1
|
- Released 1.0pre1
|
||||||
|
|
||||||
$Id: ChangeLog,v 1.1105 2001/04/12 23:39:26 mouring Exp $
|
$Id: ChangeLog,v 1.1106 2001/04/13 00:00:14 mouring Exp $
|
||||||
|
|
24
sftp-int.c
24
sftp-int.c
|
@ -26,7 +26,7 @@
|
||||||
/* XXX: recursive operations */
|
/* XXX: recursive operations */
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
RCSID("$OpenBSD: sftp-int.c,v 1.34 2001/04/11 07:06:22 djm Exp $");
|
RCSID("$OpenBSD: sftp-int.c,v 1.35 2001/04/12 23:17:54 mouring Exp $");
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
@ -856,9 +856,10 @@ parse_dispatch_command(int in, int out, const char *cmd, char **pwd)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
interactive_loop(int fd_in, int fd_out)
|
interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
|
||||||
{
|
{
|
||||||
char *pwd;
|
char *pwd;
|
||||||
|
char *dir = NULL;
|
||||||
char cmd[2048];
|
char cmd[2048];
|
||||||
|
|
||||||
version = do_init(fd_in, fd_out);
|
version = do_init(fd_in, fd_out);
|
||||||
|
@ -869,6 +870,25 @@ interactive_loop(int fd_in, int fd_out)
|
||||||
if (pwd == NULL)
|
if (pwd == NULL)
|
||||||
fatal("Need cwd");
|
fatal("Need cwd");
|
||||||
|
|
||||||
|
if (file1 != NULL) {
|
||||||
|
dir = xstrdup(file1);
|
||||||
|
dir = make_absolute(dir, pwd);
|
||||||
|
|
||||||
|
if (remote_is_dir(fd_in, fd_out, dir) && file2 == NULL) {
|
||||||
|
printf("Changing to: %s\n", dir);
|
||||||
|
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir);
|
||||||
|
parse_dispatch_command(fd_in, fd_out, cmd, &pwd);
|
||||||
|
} else {
|
||||||
|
if (file2 == NULL)
|
||||||
|
snprintf(cmd, sizeof cmd, "get %s", dir);
|
||||||
|
else
|
||||||
|
snprintf(cmd, sizeof cmd, "get %s %s", dir,
|
||||||
|
file2);
|
||||||
|
|
||||||
|
parse_dispatch_command(fd_in, fd_out, cmd, &pwd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
setvbuf(infile, NULL, _IOLBF, 0);
|
setvbuf(infile, NULL, _IOLBF, 0);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: sftp-int.h,v 1.1 2001/02/04 11:11:54 djm Exp $ */
|
/* $OpenBSD: sftp-int.h,v 1.2 2001/04/12 23:17:54 mouring Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001 Damien Miller. All rights reserved.
|
* Copyright (c) 2001 Damien Miller. All rights reserved.
|
||||||
|
@ -24,4 +24,4 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void interactive_loop(int fd_in, int fd_out);
|
void interactive_loop(int fd_in, int fd_out, char *file1, char *file2);
|
||||||
|
|
14
sftp.1
14
sftp.1
|
@ -1,4 +1,4 @@
|
||||||
.\" $OpenBSD: sftp.1,v 1.14 2001/04/09 00:42:05 stevesk Exp $
|
.\" $OpenBSD: sftp.1,v 1.15 2001/04/12 23:17:54 mouring Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2001 Damien Miller. All rights reserved.
|
.\" Copyright (c) 2001 Damien Miller. All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
|
@ -33,7 +33,11 @@
|
||||||
.Op Fl vC
|
.Op Fl vC
|
||||||
.Op Fl b Ar batchfile
|
.Op Fl b Ar batchfile
|
||||||
.Op Fl o Ar ssh_option
|
.Op Fl o Ar ssh_option
|
||||||
.Op Ar hostname | user@hostname
|
.Op Ar host
|
||||||
|
.Nm sftp
|
||||||
|
.Op [\fIuser\fR@]\fIhost\fR[:\fIfile\fR [\fIfile\fR]]
|
||||||
|
.Nm sftp
|
||||||
|
.Op [\fIuser\fR@]\fIhost\fR[:\fIdir\fR[\fI/\fR]]
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
is an interactive file transfer program, similar to
|
is an interactive file transfer program, similar to
|
||||||
|
@ -48,6 +52,12 @@ connects and logs into the specified
|
||||||
.Ar hostname ,
|
.Ar hostname ,
|
||||||
then enters an interactive command mode.
|
then enters an interactive command mode.
|
||||||
.Pp
|
.Pp
|
||||||
|
The second usage format will fetch files automaticly if a non-interactive
|
||||||
|
authentication is used, else it do so after an interactive authenication
|
||||||
|
is used.
|
||||||
|
.Pp
|
||||||
|
The last usage format allows the sftp client to start in a remote directory.
|
||||||
|
.Pp
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl b Ar batchfile
|
.It Fl b Ar batchfile
|
||||||
|
|
20
sftp.c
20
sftp.c
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
|
|
||||||
RCSID("$OpenBSD: sftp.c,v 1.13 2001/04/08 20:52:55 deraadt Exp $");
|
RCSID("$OpenBSD: sftp.c,v 1.14 2001/04/12 23:17:54 mouring Exp $");
|
||||||
|
|
||||||
/* XXX: commandline mode */
|
/* XXX: commandline mode */
|
||||||
/* XXX: copy between two remote hosts (commandline) */
|
/* XXX: copy between two remote hosts (commandline) */
|
||||||
|
@ -147,7 +147,7 @@ make_ssh_args(char *add_arg)
|
||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: sftp [-1vC] [-b batchfile] [-osshopt=value] [user@]host\n");
|
fprintf(stderr, "usage: sftp [-1vC] [-b batchfile] [-osshopt=value] [user@]host[:file [file]]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,8 @@ main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int in, out, ch, debug_level, compress_flag;
|
int in, out, ch, debug_level, compress_flag;
|
||||||
pid_t sshpid;
|
pid_t sshpid;
|
||||||
char *host, *userhost;
|
char *file1 = NULL;
|
||||||
|
char *host, *userhost, *cp, *file2;
|
||||||
LogLevel ll;
|
LogLevel ll;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
|
@ -202,22 +203,27 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind == argc || argc > (optind + 1))
|
if (optind == argc || argc > (optind + 2))
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
userhost = xstrdup(argv[optind]);
|
userhost = xstrdup(argv[optind]);
|
||||||
|
file2 = argv[optind+1];
|
||||||
|
|
||||||
|
if ((cp = strchr(userhost, ':')) != NULL) {
|
||||||
|
*cp++ = '\0';
|
||||||
|
file1 = cp;
|
||||||
|
}
|
||||||
|
|
||||||
if ((host = strchr(userhost, '@')) == NULL)
|
if ((host = strchr(userhost, '@')) == NULL)
|
||||||
host = userhost;
|
host = userhost;
|
||||||
else {
|
else {
|
||||||
*host = '\0';
|
*host++ = '\0';
|
||||||
if (!userhost[0]) {
|
if (!userhost[0]) {
|
||||||
fprintf(stderr, "Missing username\n");
|
fprintf(stderr, "Missing username\n");
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
make_ssh_args("-l");
|
make_ssh_args("-l");
|
||||||
make_ssh_args(userhost);
|
make_ssh_args(userhost);
|
||||||
host++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*host) {
|
if (!*host) {
|
||||||
|
@ -256,7 +262,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
connect_to_server(make_ssh_args(NULL), &in, &out, &sshpid);
|
connect_to_server(make_ssh_args(NULL), &in, &out, &sshpid);
|
||||||
|
|
||||||
interactive_loop(in, out);
|
interactive_loop(in, out, file1, file2);
|
||||||
|
|
||||||
#if !defined(USE_PIPES)
|
#if !defined(USE_PIPES)
|
||||||
shutdown(in, SHUT_RDWR);
|
shutdown(in, SHUT_RDWR);
|
||||||
|
|
Loading…
Reference in New Issue