]> andersk Git - openssh.git/commitdiff
- mouring@cvs.openbsd.org 2001/04/12 23:17:54
authormouring <mouring>
Fri, 13 Apr 2001 00:00:14 +0000 (00:00 +0000)
committermouring <mouring>
Fri, 13 Apr 2001 00:00:14 +0000 (00:00 +0000)
     [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@

ChangeLog
sftp-int.c
sftp-int.h
sftp.1
sftp.c

index c00d1c91dd4f0b591cd258849b42a6cc072d3ce1..ce1319b45b722d7c2f6f189acc031e2db784434e 100644 (file)
--- 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 
    - 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.
 
index bbc97a1a5631f6d18678c774295b4c476ac23c28..8ec504dbf7732655c4e0e167d712aff0c03f4c49 100644 (file)
@@ -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);
 
index 234d8003bc57b3815e638176ff2aff94aeffe2bc..b47f862f8fedc794a457ca33a5c0f7482b52c8f7 100644 (file)
@@ -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 34ff9346aa705386f93d2dc51931f5175fd15484..093ebb91c852d2b1faede43add6c9bca012cd11a 100644 (file)
--- 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.
 .\"
 .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 7849d9491af5e8d5a8d08a3c4b46d72ee81f0930..911a04f243d683c7e20b9b42aa0f924a635943b5 100644 (file)
--- 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);
This page took 0.790675 seconds and 5 git commands to generate.