diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | sftp-int.c | 24 | ||||
-rw-r--r-- | sftp-int.h | 4 | ||||
-rw-r--r-- | sftp.1 | 14 | ||||
-rw-r--r-- | sftp.c | 20 |
5 files changed, 56 insertions, 15 deletions
@@ -4,7 +4,6 @@ | |||
4 | [ssh.c] | 4 | [ssh.c] |
5 | show debug output during option processing, report from | 5 | show debug output during option processing, report from |
6 | pekkas@netcore.fi | 6 | pekkas@netcore.fi |
7 | - OpenBSD CVS Sync | ||
8 | - markus@cvs.openbsd.org 2001/04/12 19:15:26 | 7 | - markus@cvs.openbsd.org 2001/04/12 19:15:26 |
9 | [auth-rhosts.c auth.h auth2.c buffer.c canohost.c canohost.h | 8 | [auth-rhosts.c auth.h auth2.c buffer.c canohost.c canohost.h |
10 | compat.c compat.h hostfile.c pathnames.h readconf.c readconf.h | 9 | compat.c compat.h hostfile.c pathnames.h readconf.c readconf.h |
@@ -19,6 +18,12 @@ | |||
19 | - stevesk@cvs.openbsd.org 2001/04/12 20:09:38 | 18 | - stevesk@cvs.openbsd.org 2001/04/12 20:09:38 |
20 | [misc.c misc.h readconf.c servconf.c ssh.c sshd.c] | 19 | [misc.c misc.h readconf.c servconf.c ssh.c sshd.c] |
21 | robust port validation; ok markus@ jakob@ | 20 | robust port validation; ok markus@ jakob@ |
21 | - mouring@cvs.openbsd.org 2001/04/12 23:17:54 | ||
22 | [sftp-int.c sftp-int.h sftp.1 sftp.c] | ||
23 | Add support for: | ||
24 | sftp [user@]host[:file [file]] - Fetch remote file(s) | ||
25 | sftp [user@]host[:dir[/]] - Start in remote dir/ | ||
26 | OK deraadt@ | ||
22 | - (bal) Added openbsd-compat/inet_ntop.[ch] since HP/UX (and others) | 27 | - (bal) Added openbsd-compat/inet_ntop.[ch] since HP/UX (and others) |
23 | lack it. | 28 | lack it. |
24 | 29 | ||
@@ -5041,4 +5046,4 @@ | |||
5041 | - Wrote replacements for strlcpy and mkdtemp | 5046 | - Wrote replacements for strlcpy and mkdtemp |
5042 | - Released 1.0pre1 | 5047 | - Released 1.0pre1 |
5043 | 5048 | ||
5044 | $Id: ChangeLog,v 1.1105 2001/04/12 23:39:26 mouring Exp $ | 5049 | $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 @@ | |||
26 | /* XXX: recursive operations */ | 26 | /* XXX: recursive operations */ |
27 | 27 | ||
28 | #include "includes.h" | 28 | #include "includes.h" |
29 | RCSID("$OpenBSD: sftp-int.c,v 1.34 2001/04/11 07:06:22 djm Exp $"); | 29 | RCSID("$OpenBSD: sftp-int.c,v 1.35 2001/04/12 23:17:54 mouring Exp $"); |
30 | 30 | ||
31 | #include "buffer.h" | 31 | #include "buffer.h" |
32 | #include "xmalloc.h" | 32 | #include "xmalloc.h" |
@@ -856,9 +856,10 @@ parse_dispatch_command(int in, int out, const char *cmd, char **pwd) | |||
856 | } | 856 | } |
857 | 857 | ||
858 | void | 858 | void |
859 | interactive_loop(int fd_in, int fd_out) | 859 | interactive_loop(int fd_in, int fd_out, char *file1, char *file2) |
860 | { | 860 | { |
861 | char *pwd; | 861 | char *pwd; |
862 | char *dir = NULL; | ||
862 | char cmd[2048]; | 863 | char cmd[2048]; |
863 | 864 | ||
864 | version = do_init(fd_in, fd_out); | 865 | version = do_init(fd_in, fd_out); |
@@ -869,6 +870,25 @@ interactive_loop(int fd_in, int fd_out) | |||
869 | if (pwd == NULL) | 870 | if (pwd == NULL) |
870 | fatal("Need cwd"); | 871 | fatal("Need cwd"); |
871 | 872 | ||
873 | if (file1 != NULL) { | ||
874 | dir = xstrdup(file1); | ||
875 | dir = make_absolute(dir, pwd); | ||
876 | |||
877 | if (remote_is_dir(fd_in, fd_out, dir) && file2 == NULL) { | ||
878 | printf("Changing to: %s\n", dir); | ||
879 | snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); | ||
880 | parse_dispatch_command(fd_in, fd_out, cmd, &pwd); | ||
881 | } else { | ||
882 | if (file2 == NULL) | ||
883 | snprintf(cmd, sizeof cmd, "get %s", dir); | ||
884 | else | ||
885 | snprintf(cmd, sizeof cmd, "get %s %s", dir, | ||
886 | file2); | ||
887 | |||
888 | parse_dispatch_command(fd_in, fd_out, cmd, &pwd); | ||
889 | return; | ||
890 | } | ||
891 | } | ||
872 | setvbuf(stdout, NULL, _IOLBF, 0); | 892 | setvbuf(stdout, NULL, _IOLBF, 0); |
873 | setvbuf(infile, NULL, _IOLBF, 0); | 893 | setvbuf(infile, NULL, _IOLBF, 0); |
874 | 894 | ||
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 @@ | |||
1 | /* $OpenBSD: sftp-int.h,v 1.1 2001/02/04 11:11:54 djm Exp $ */ | 1 | /* $OpenBSD: sftp-int.h,v 1.2 2001/04/12 23:17:54 mouring Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2001 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2001 Damien Miller. All rights reserved. |
@@ -24,4 +24,4 @@ | |||
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | void interactive_loop(int fd_in, int fd_out); | 27 | void interactive_loop(int fd_in, int fd_out, char *file1, char *file2); |
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: sftp.1,v 1.14 2001/04/09 00:42:05 stevesk Exp $ | 1 | .\" $OpenBSD: sftp.1,v 1.15 2001/04/12 23:17:54 mouring Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 2001 Damien Miller. All rights reserved. | 3 | .\" Copyright (c) 2001 Damien Miller. All rights reserved. |
4 | .\" | 4 | .\" |
@@ -33,7 +33,11 @@ | |||
33 | .Op Fl vC | 33 | .Op Fl vC |
34 | .Op Fl b Ar batchfile | 34 | .Op Fl b Ar batchfile |
35 | .Op Fl o Ar ssh_option | 35 | .Op Fl o Ar ssh_option |
36 | .Op Ar hostname | user@hostname | 36 | .Op Ar host |
37 | .Nm sftp | ||
38 | .Op [\fIuser\fR@]\fIhost\fR[:\fIfile\fR [\fIfile\fR]] | ||
39 | .Nm sftp | ||
40 | .Op [\fIuser\fR@]\fIhost\fR[:\fIdir\fR[\fI/\fR]] | ||
37 | .Sh DESCRIPTION | 41 | .Sh DESCRIPTION |
38 | .Nm | 42 | .Nm |
39 | is an interactive file transfer program, similar to | 43 | is an interactive file transfer program, similar to |
@@ -48,6 +52,12 @@ connects and logs into the specified | |||
48 | .Ar hostname , | 52 | .Ar hostname , |
49 | then enters an interactive command mode. | 53 | then enters an interactive command mode. |
50 | .Pp | 54 | .Pp |
55 | The second usage format will fetch files automaticly if a non-interactive | ||
56 | authentication is used, else it do so after an interactive authenication | ||
57 | is used. | ||
58 | .Pp | ||
59 | The last usage format allows the sftp client to start in a remote directory. | ||
60 | .Pp | ||
51 | The options are as follows: | 61 | The options are as follows: |
52 | .Bl -tag -width Ds | 62 | .Bl -tag -width Ds |
53 | .It Fl b Ar batchfile | 63 | .It Fl b Ar batchfile |
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | 26 | ||
27 | RCSID("$OpenBSD: sftp.c,v 1.13 2001/04/08 20:52:55 deraadt Exp $"); | 27 | RCSID("$OpenBSD: sftp.c,v 1.14 2001/04/12 23:17:54 mouring Exp $"); |
28 | 28 | ||
29 | /* XXX: commandline mode */ | 29 | /* XXX: commandline mode */ |
30 | /* XXX: copy between two remote hosts (commandline) */ | 30 | /* XXX: copy between two remote hosts (commandline) */ |
@@ -147,7 +147,7 @@ make_ssh_args(char *add_arg) | |||
147 | void | 147 | void |
148 | usage(void) | 148 | usage(void) |
149 | { | 149 | { |
150 | fprintf(stderr, "usage: sftp [-1vC] [-b batchfile] [-osshopt=value] [user@]host\n"); | 150 | fprintf(stderr, "usage: sftp [-1vC] [-b batchfile] [-osshopt=value] [user@]host[:file [file]]\n"); |
151 | exit(1); | 151 | exit(1); |
152 | } | 152 | } |
153 | 153 | ||
@@ -156,7 +156,8 @@ main(int argc, char **argv) | |||
156 | { | 156 | { |
157 | int in, out, ch, debug_level, compress_flag; | 157 | int in, out, ch, debug_level, compress_flag; |
158 | pid_t sshpid; | 158 | pid_t sshpid; |
159 | char *host, *userhost; | 159 | char *file1 = NULL; |
160 | char *host, *userhost, *cp, *file2; | ||
160 | LogLevel ll; | 161 | LogLevel ll; |
161 | extern int optind; | 162 | extern int optind; |
162 | extern char *optarg; | 163 | extern char *optarg; |
@@ -202,22 +203,27 @@ main(int argc, char **argv) | |||
202 | } | 203 | } |
203 | } | 204 | } |
204 | 205 | ||
205 | if (optind == argc || argc > (optind + 1)) | 206 | if (optind == argc || argc > (optind + 2)) |
206 | usage(); | 207 | usage(); |
207 | 208 | ||
208 | userhost = xstrdup(argv[optind]); | 209 | userhost = xstrdup(argv[optind]); |
210 | file2 = argv[optind+1]; | ||
211 | |||
212 | if ((cp = strchr(userhost, ':')) != NULL) { | ||
213 | *cp++ = '\0'; | ||
214 | file1 = cp; | ||
215 | } | ||
209 | 216 | ||
210 | if ((host = strchr(userhost, '@')) == NULL) | 217 | if ((host = strchr(userhost, '@')) == NULL) |
211 | host = userhost; | 218 | host = userhost; |
212 | else { | 219 | else { |
213 | *host = '\0'; | 220 | *host++ = '\0'; |
214 | if (!userhost[0]) { | 221 | if (!userhost[0]) { |
215 | fprintf(stderr, "Missing username\n"); | 222 | fprintf(stderr, "Missing username\n"); |
216 | usage(); | 223 | usage(); |
217 | } | 224 | } |
218 | make_ssh_args("-l"); | 225 | make_ssh_args("-l"); |
219 | make_ssh_args(userhost); | 226 | make_ssh_args(userhost); |
220 | host++; | ||
221 | } | 227 | } |
222 | 228 | ||
223 | if (!*host) { | 229 | if (!*host) { |
@@ -256,7 +262,7 @@ main(int argc, char **argv) | |||
256 | 262 | ||
257 | connect_to_server(make_ssh_args(NULL), &in, &out, &sshpid); | 263 | connect_to_server(make_ssh_args(NULL), &in, &out, &sshpid); |
258 | 264 | ||
259 | interactive_loop(in, out); | 265 | interactive_loop(in, out, file1, file2); |
260 | 266 | ||
261 | #if !defined(USE_PIPES) | 267 | #if !defined(USE_PIPES) |
262 | shutdown(in, SHUT_RDWR); | 268 | shutdown(in, SHUT_RDWR); |