diff --git a/ChangeLog b/ChangeLog index 574fb449d..f328f1df1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,6 @@ [ssh.c] show debug output during option processing, report from pekkas@netcore.fi - - OpenBSD CVS Sync - markus@cvs.openbsd.org 2001/04/12 19:15:26 [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 @@ -19,6 +18,12 @@ - stevesk@cvs.openbsd.org 2001/04/12 20:09:38 [misc.c misc.h readconf.c servconf.c ssh.c sshd.c] 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) lack it. @@ -5041,4 +5046,4 @@ - Wrote replacements for strlcpy and mkdtemp - 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 $ diff --git a/sftp-int.c b/sftp-int.c index bbc97a1a5..8ec504dbf 100644 --- a/sftp-int.c +++ b/sftp-int.c @@ -26,7 +26,7 @@ /* XXX: recursive operations */ #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 "xmalloc.h" @@ -856,9 +856,10 @@ parse_dispatch_command(int in, int out, const char *cmd, char **pwd) } void -interactive_loop(int fd_in, int fd_out) +interactive_loop(int fd_in, int fd_out, char *file1, char *file2) { char *pwd; + char *dir = NULL; char cmd[2048]; version = do_init(fd_in, fd_out); @@ -869,6 +870,25 @@ interactive_loop(int fd_in, int fd_out) if (pwd == NULL) 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(infile, NULL, _IOLBF, 0); diff --git a/sftp-int.h b/sftp-int.h index 234d8003b..b47f862f8 100644 --- a/sftp-int.h +++ b/sftp-int.h @@ -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. @@ -24,4 +24,4 @@ * 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); diff --git a/sftp.1 b/sftp.1 index 34ff9346a..093ebb91c 100644 --- a/sftp.1 +++ b/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. .\" @@ -33,7 +33,11 @@ .Op Fl vC .Op Fl b Ar batchfile .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 .Nm is an interactive file transfer program, similar to @@ -48,6 +52,12 @@ connects and logs into the specified .Ar hostname , then enters an interactive command mode. .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: .Bl -tag -width Ds .It Fl b Ar batchfile diff --git a/sftp.c b/sftp.c index 7849d9491..911a04f24 100644 --- a/sftp.c +++ b/sftp.c @@ -24,7 +24,7 @@ #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: copy between two remote hosts (commandline) */ @@ -147,7 +147,7 @@ make_ssh_args(char *add_arg) 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); } @@ -156,7 +156,8 @@ main(int argc, char **argv) { int in, out, ch, debug_level, compress_flag; pid_t sshpid; - char *host, *userhost; + char *file1 = NULL; + char *host, *userhost, *cp, *file2; LogLevel ll; extern int optind; 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(); userhost = xstrdup(argv[optind]); + file2 = argv[optind+1]; + + if ((cp = strchr(userhost, ':')) != NULL) { + *cp++ = '\0'; + file1 = cp; + } if ((host = strchr(userhost, '@')) == NULL) host = userhost; else { - *host = '\0'; + *host++ = '\0'; if (!userhost[0]) { fprintf(stderr, "Missing username\n"); usage(); } make_ssh_args("-l"); make_ssh_args(userhost); - host++; } if (!*host) { @@ -256,7 +262,7 @@ main(int argc, char **argv) connect_to_server(make_ssh_args(NULL), &in, &out, &sshpid); - interactive_loop(in, out); + interactive_loop(in, out, file1, file2); #if !defined(USE_PIPES) shutdown(in, SHUT_RDWR);